From be5482216c3e65a02061864d9e6d00b33561a3fd Mon Sep 17 00:00:00 2001 From: kean Date: Mon, 1 Apr 2024 17:39:50 -0400 Subject: [PATCH] Remove secondary actions from the editor --- .../ViewRelated/Post/PostEditor+Publish.swift | 19 +- .../Classes/ViewRelated/Post/PostEditor.swift | 6 +- .../ViewRelated/Post/PostEditorState.swift | 37 +++- WordPress/WordPress.xcodeproj/project.pbxproj | 4 - .../WordPressTest/PostEditorStateTests.swift | 188 ------------------ 5 files changed, 38 insertions(+), 216 deletions(-) delete mode 100644 WordPress/WordPressTest/PostEditorStateTests.swift diff --git a/WordPress/Classes/ViewRelated/Post/PostEditor+Publish.swift b/WordPress/Classes/ViewRelated/Post/PostEditor+Publish.swift index 1306639fa7f7..ef964d27461e 100644 --- a/WordPress/Classes/ViewRelated/Post/PostEditor+Publish.swift +++ b/WordPress/Classes/ViewRelated/Post/PostEditor+Publish.swift @@ -99,6 +99,7 @@ extension PublishingEditor { performEditorAction(action, analyticsStat: postEditorStateContext.publishActionAnalyticsStat) } + /// - note: deprecated (kahu-offline-mode) func handleSecondaryActionButtonTap() { guard let action = self.postEditorStateContext.secondaryPublishButtonAction else { // If the user tapped on the secondary publish action button, it means we should have a secondary publish action. @@ -110,11 +111,7 @@ extension PublishingEditor { let secondaryStat = self.postEditorStateContext.secondaryPublishActionAnalyticsStat let publishPostClosure = { [unowned self] in - guard RemoteFeatureFlag.syncPublishing.enabled() else { - publishPost(action: action, dismissWhenDone: action.dismissesEditor, analyticsStat: secondaryStat) - return - } - performEditorAction(action, analyticsStat: secondaryStat) + publishPost(action: action, dismissWhenDone: action.dismissesEditor, analyticsStat: secondaryStat) } if presentedViewController != nil { @@ -134,20 +131,14 @@ extension PublishingEditor { switch action { case .schedule, .publish: showPrepublishingSheet(for: action, analyticsStat: analyticsStat) - case .saveAsDraft: - performSaveDraftAction() case .update: - if post.original().status == .draft { - performSaveDraftAction() - } else { - performUpdatePostAction() - } + performUpdatePostAction() case .submitForReview: // TODO: Show Prepublishing VC fatalError("Not implemented (kahu-offline-mode)") - case .save, .continueFromHomepageEditing: - assertionFailure("No longer used and supported") + case .save, .saveAsDraft, .continueFromHomepageEditing: assertionFailure("No longer used and supported") + break } } diff --git a/WordPress/Classes/ViewRelated/Post/PostEditor.swift b/WordPress/Classes/ViewRelated/Post/PostEditor.swift index f8ace2c36e7d..1f16142e55cd 100644 --- a/WordPress/Classes/ViewRelated/Post/PostEditor.swift +++ b/WordPress/Classes/ViewRelated/Post/PostEditor.swift @@ -103,7 +103,11 @@ extension PostEditor { } var editorHasChanges: Bool { - return post.hasUnsavedChanges() + if RemoteFeatureFlag.syncPublishing.enabled() { + return !post.changes.isEmpty + } else { + return post.hasUnsavedChanges() + } } func editorContentWasUpdated() { diff --git a/WordPress/Classes/ViewRelated/Post/PostEditorState.swift b/WordPress/Classes/ViewRelated/Post/PostEditorState.swift index 79a41c4e34d5..dc0465816097 100644 --- a/WordPress/Classes/ViewRelated/Post/PostEditorState.swift +++ b/WordPress/Classes/ViewRelated/Post/PostEditorState.swift @@ -8,6 +8,7 @@ import WordPressShared public enum PostEditorAction { /// - note: Deprecated (kahu-offline-mode) case save + /// - note: Deprecated (kahu-offline-mode) case saveAsDraft case schedule case publish @@ -114,6 +115,7 @@ public enum PostEditorAction { } } + /// - note: deprecated (kahu-offline-mode) fileprivate var secondaryPublishAction: PostEditorAction? { switch self { case .publish: @@ -260,7 +262,11 @@ public class PostEditorStateContext { case .draft where originalPostStatus == nil: return publishAction(userCanPublish: userCanPublish) case .draft: - return .update + if RemoteFeatureFlag.syncPublishing.enabled() { + return publishAction(userCanPublish: userCanPublish) + } else { + return .update + } case .pending: return .save case .publish where isNewOrDraft(originalPostStatus): @@ -358,8 +364,7 @@ public class PostEditorStateContext { return action.publishActionAnalyticsStat } - /// Returns whether the secondary publish button should be displayed, or not - /// + /// - note: deprecated (kahu-offline-mode) var isSecondaryPublishButtonShown: Bool { guard hasContent else { return false @@ -376,11 +381,14 @@ public class PostEditorStateContext { return false } + guard !RemoteFeatureFlag.syncPublishing.enabled() else { + return false + } + return action.secondaryPublishAction != nil } - /// Returns the secondary publish action - /// + /// - note: deprecated (kahu-offline-mode) var secondaryPublishButtonAction: PostEditorAction? { guard isSecondaryPublishButtonShown else { return nil @@ -389,8 +397,7 @@ public class PostEditorStateContext { return action.secondaryPublishAction } - /// Returns the secondary publish button text - /// + /// - note: deprecated (kahu-offline-mode) var secondaryPublishButtonText: String? { guard isSecondaryPublishButtonShown else { return nil @@ -399,7 +406,7 @@ public class PostEditorStateContext { return action.secondaryPublishAction?.publishActionLabel } - /// Returns the WPAnalyticsStat enum to be tracked when this post is published with the secondary action + /// - note: deprecated (kahu-offline-mode) var secondaryPublishActionAnalyticsStat: WPAnalyticsStat? { guard isSecondaryPublishButtonShown else { return nil @@ -411,7 +418,19 @@ public class PostEditorStateContext { /// Indicates whether the Publish Action should be allowed, or not /// private func updatePublishActionAllowed() { - publishActionAllowed = hasContent && hasChanges && !isBeingPublished && (action.isAsync || !isUploadingMedia) + if RemoteFeatureFlag.syncPublishing.enabled() { + switch action { + case .schedule, .publish, .submitForReview: + publishActionAllowed = hasContent + case .update: + publishActionAllowed = hasContent && hasChanges && !isBeingPublished + case .save, .saveAsDraft, .continueFromHomepageEditing: + assertionFailure("No longer used") + break + } + } else { + publishActionAllowed = hasContent && hasChanges && !isBeingPublished && (action.isAsync || !isUploadingMedia) + } } } diff --git a/WordPress/WordPress.xcodeproj/project.pbxproj b/WordPress/WordPress.xcodeproj/project.pbxproj index 651cfe39939d..2cb3d07182d2 100644 --- a/WordPress/WordPress.xcodeproj/project.pbxproj +++ b/WordPress/WordPress.xcodeproj/project.pbxproj @@ -2445,7 +2445,6 @@ 937250EE267A492D0086075F /* StatsPeriodStoreTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 937250ED267A492D0086075F /* StatsPeriodStoreTests.swift */; }; 937D9A0F19F83812007B9D5F /* WordPress-22-23.xcmappingmodel in Sources */ = {isa = PBXBuildFile; fileRef = 937D9A0E19F83812007B9D5F /* WordPress-22-23.xcmappingmodel */; }; 937D9A1119F838C2007B9D5F /* AccountToAccount22to23.swift in Sources */ = {isa = PBXBuildFile; fileRef = 937D9A1019F838C2007B9D5F /* AccountToAccount22to23.swift */; }; - 937E3AB61E3EBE1600CDA01A /* PostEditorStateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 937E3AB51E3EBE1600CDA01A /* PostEditorStateTests.swift */; }; 937F3E321AD6FDA7006BA498 /* WPAnalyticsTrackerAutomatticTracks.m in Sources */ = {isa = PBXBuildFile; fileRef = 937F3E311AD6FDA7006BA498 /* WPAnalyticsTrackerAutomatticTracks.m */; }; 938466B92683CA0E00A538DC /* ReferrerDetailsViewModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 938466B82683CA0E00A538DC /* ReferrerDetailsViewModelTests.swift */; }; 938CF3DC1EF1BE6800AF838E /* CocoaLumberjack.swift in Sources */ = {isa = PBXBuildFile; fileRef = 938CF3DB1EF1BE6800AF838E /* CocoaLumberjack.swift */; }; @@ -7827,7 +7826,6 @@ 937D9A0C19F83744007B9D5F /* WordPress 22.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "WordPress 22.xcdatamodel"; sourceTree = ""; }; 937D9A0E19F83812007B9D5F /* WordPress-22-23.xcmappingmodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcmappingmodel; path = "WordPress-22-23.xcmappingmodel"; sourceTree = ""; }; 937D9A1019F838C2007B9D5F /* AccountToAccount22to23.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AccountToAccount22to23.swift; sourceTree = ""; }; - 937E3AB51E3EBE1600CDA01A /* PostEditorStateTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PostEditorStateTests.swift; sourceTree = ""; }; 937F3E301AD6FDA7006BA498 /* WPAnalyticsTrackerAutomatticTracks.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = WPAnalyticsTrackerAutomatticTracks.h; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; }; 937F3E311AD6FDA7006BA498 /* WPAnalyticsTrackerAutomatticTracks.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WPAnalyticsTrackerAutomatticTracks.m; sourceTree = ""; }; 938466B82683CA0E00A538DC /* ReferrerDetailsViewModelTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReferrerDetailsViewModelTests.swift; sourceTree = ""; }; @@ -14375,7 +14373,6 @@ 57E3C98223835A57004741DB /* Controllers */, 57DF04BF2314895E00CC93D6 /* Views */, 5749984522FA0EB900CE86ED /* Utils */, - 937E3AB51E3EBE1600CDA01A /* PostEditorStateTests.swift */, E10F3DA01E5C2CE0008FAADA /* PostListFilterTests.swift */, 57D6C83D22945A10003DDC7E /* PostCompactCellTests.swift */, 575E126222973EBB0041B3EB /* PostCompactCellGhostableTests.swift */, @@ -23898,7 +23895,6 @@ D821C817210036D9002ED995 /* ActivityContentFactoryTests.swift in Sources */, 931D26F719ED7F7500114F17 /* ReaderPostServiceTest.m in Sources */, B5772AC61C9C84900031F97E /* GravatarServiceTests.swift in Sources */, - 937E3AB61E3EBE1600CDA01A /* PostEditorStateTests.swift in Sources */, FF9A6E7121F9361700D36D14 /* MediaUploadHashTests.swift in Sources */, B532ACCF1DC3AB8E00FFFA57 /* NotificationSyncMediatorTests.swift in Sources */, 7E4A772F20F7FDF8001C706D /* ActivityLogTestData.swift in Sources */, diff --git a/WordPress/WordPressTest/PostEditorStateTests.swift b/WordPress/WordPressTest/PostEditorStateTests.swift deleted file mode 100644 index 44b6a8c74bd9..000000000000 --- a/WordPress/WordPressTest/PostEditorStateTests.swift +++ /dev/null @@ -1,188 +0,0 @@ -import XCTest -@testable import WordPress - -class PostEditorStateTests: XCTestCase { - var context: PostEditorStateContext! - - override func setUp() { - super.setUp() - } - - override func tearDown() { - super.tearDown() - - context = nil - } - - func testContextNoContentPublishButtonDisabled() { - context = PostEditorStateContext(originalPostStatus: .publish, userCanPublish: true, delegate: self) - - context.updated(hasContent: false) - - XCTAssertFalse(context.isPublishButtonEnabled) - } - - func testContextChangedNewPostToDraft() { - context = PostEditorStateContext(originalPostStatus: nil, userCanPublish: true, delegate: self) - - context.updated(postStatus: .draft) - - XCTAssertEqual(PostEditorAction.publish, context.action, "New posts, even if switched to draft, should show Publish button.") - } - - func testContextExistingDraft() { - context = PostEditorStateContext(originalPostStatus: .draft, userCanPublish: true, delegate: self) - - XCTAssertEqual(PostEditorAction.update, context.action, "Existing draft posts should show Update button.") - } - - func testContextScheduledPost() { - context = PostEditorStateContext(originalPostStatus: .scheduled, userCanPublish: true, delegate: self) - - XCTAssertEqual(PostEditorAction.update, context.action, "Scheduled posts should show Update") - } - - func testContextScheduledPostUpdated() { - context = PostEditorStateContext(originalPostStatus: .scheduled, userCanPublish: true, delegate: self) - - context.updated(postStatus: .scheduled) - - XCTAssertEqual(PostEditorAction.update, context.action, "Scheduled posts that get updated should still show Update") - } -} - -// These tests are all based off of Calypso unit tests -// https://github.com/Automattic/wp-calypso/blob/master/client/post-editor/editor-publish-button/test/index.jsx -extension PostEditorStateTests { - func testContextChangedPublishedPostStaysPublished() { - context = PostEditorStateContext(originalPostStatus: .publish, userCanPublish: true, delegate: self) - - XCTAssertEqual(PostEditorAction.update, context.action, "should return Update if the post was originally published and is still slated to be published") - } - - func testContextChangedPublishedPostToDraft() { - context = PostEditorStateContext(originalPostStatus: .publish, userCanPublish: true, delegate: self) - - context.updated(postStatus: .draft) - - XCTAssertEqual(PostEditorAction.update, context.action, "should return Update if the post was originally published and is currently reverted to non-published status") - } - - func testContextPostFutureDatedAlreadyScheduled() { - context = PostEditorStateContext(originalPostStatus: .scheduled, userCanPublish: true, delegate: self) - - context.updated(postStatus: .scheduled) - context.updated(publishDate: Date.distantFuture) - - XCTAssertEqual(PostEditorAction.update, context.action, "should return Update if the post is scheduled and dated in the future") - } - - func testContextUpdatingAlreadyScheduledToDraft() { - context = PostEditorStateContext(originalPostStatus: .scheduled, userCanPublish: true, delegate: self) - - context.updated(publishDate: Date.distantFuture) - context.updated(postStatus: .draft) - - XCTAssertEqual(PostEditorAction.update, context.action, "should return Update if the post is scheduled, dated in the future, and next status is draft") - } - - func testContextDraftPost() { - context = PostEditorStateContext(originalPostStatus: nil, userCanPublish: true, delegate: self) - - XCTAssertEqual(PostEditorAction.publish, context.action, "should return Publish if the post is a draft") - } - - func testContextUserCannotPublish() { - context = PostEditorStateContext(originalPostStatus: nil, userCanPublish: false, delegate: self) - - XCTAssertEqual(PostEditorAction.submitForReview, context.action, "should return 'Submit for Review' if the post is a draft and user can't publish") - } - - func testPublishEnabledHasContentAndChangesNotPublishing() { - context = PostEditorStateContext(originalPostStatus: .draft, userCanPublish: true, delegate: self) - context.updated(hasContent: true) - context.updated(hasChanges: true) - context.updated(isBeingPublished: false) - - XCTAssertTrue(context.isPublishButtonEnabled, "should return true if form is not publishing and post is not empty") - } - - func testPublishDisabledHasContentAndNoChangesNotPublishing() { - context = PostEditorStateContext(originalPostStatus: .draft, userCanPublish: true, delegate: self) - context.updated(hasContent: true) - context.updated(hasChanges: false) - context.updated(isBeingPublished: false) - - XCTAssertFalse(context.isPublishButtonEnabled, "should return true if form is not publishing and post is not empty") - } - - // Missing test: should return false if form is not publishing and post is not empty, but user is not verified - - // Missing test: should return true if form is not published and post is new and has content, but is not dirty - - func testPublishDisabledDuringPublishing() { - context = PostEditorStateContext(originalPostStatus: .draft, userCanPublish: true, delegate: self) - context.updated(isBeingPublished: true) - - XCTAssertFalse(context.isPublishButtonEnabled, "should return false if form is publishing") - } - - // Missing test: should return false if saving is blocked - - // Missing test: should return false if not dirty and has no content - - func testPublishDisabledNoContent() { - context = PostEditorStateContext(originalPostStatus: .draft, userCanPublish: true, delegate: self) - context.updated(hasContent: false) - - XCTAssertFalse(context.isPublishButtonEnabled, "should return false if post has no content") - } -} - -extension PostEditorStateTests { - func testPublishSecondaryDisabledNoContent() { - context = PostEditorStateContext(originalPostStatus: nil, userCanPublish: true, delegate: self) - context.updated(hasContent: false) - - XCTAssertFalse(context.isSecondaryPublishButtonShown, "should return false if post has no content") - } - - func testPublishSecondaryAlreadyPublishedPosts() { - context = PostEditorStateContext(originalPostStatus: .publish, userCanPublish: true, delegate: self) - context.updated(hasContent: true) - - XCTAssertEqual(PostEditorAction.update, context.action) - XCTAssertFalse(context.isSecondaryPublishButtonShown, "should return false for already published posts") - } - - func testPublishSecondaryAlreadyDraftedPosts() { - context = PostEditorStateContext(originalPostStatus: .draft, userCanPublish: true, delegate: self) - context.updated(hasContent: true) - - XCTAssertTrue(context.isSecondaryPublishButtonShown, "should return true for existing drafts (publish now)") - } - - func testPublishSecondaryExistingFutureDatedDrafts() { - context = PostEditorStateContext(originalPostStatus: .draft, userCanPublish: true, publishDate: Date.distantFuture, delegate: self) - context.updated(hasContent: true) - - XCTAssertFalse(context.isSecondaryPublishButtonShown, "should return false for existing future-dated drafts (no publish now)") - } - - func testPublishSecondaryAlreadyScheduledPosts() { - context = PostEditorStateContext(originalPostStatus: .scheduled, userCanPublish: true, publishDate: Date.distantFuture, delegate: self) - context.updated(hasContent: true) - - XCTAssertFalse(context.isSecondaryPublishButtonShown, "should return false for existing scheduled drafts (no publish now)") - } -} - -extension PostEditorStateTests: PostEditorStateContextDelegate { - func context(_ context: PostEditorStateContext, didChangeAction: PostEditorAction) { - - } - - func context(_ context: PostEditorStateContext, didChangeActionAllowed: Bool) { - - } -}