-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add publish functionality to Gutenberg editor #10461
Conversation
Note: We should merge the PR wordpress-mobile/gutenberg-mobile#246 as a precondition for merging this PR |
Generated by 🚫 Danger |
@hypest I didn't add you to reviewers since this is highly iOS specific but feel free to contribute please. This is about the publish functionality and you might want to give feedback about "changed" flag. You can go ahead and try some of the test cases and let me know if anything seems wrong. I should say that publishing functionality is very different between iOS and Android in terms of user experience so you might want to checkout an extra WPiOS repo just to see what the default behavior is on master branch. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @pinarol - This looks super good! 🎉
I like that the Aztec part looks like no more than moving code to another file, but the execution paths are basically the same. And at the same time we can share that behavior with Gutenberg.
Note:
As we talked by PM, it's not ideal that we are still mixing together behavior and UI. Ideally we will manage to separate concerns clearly, and take this extraction also as an opportunity to make code more testable (and make tests with it). But as a first step thinking on the Alpha release, we agreed that this is the best way to go for now.
I added a couple of observations but most of them are small details. The most important one is concerning requestHTMLReason
. I think we should safeguard that in some way, but I'm fine with leaving that task for a future PR.
Regarding behavior test, it looks quite solid 🎉
The Aztec side is doing perfect. 👌
I did find a couple of issues with some corner cases using Gutenberg:
Drafts issue:
Every time I open the editor to create a new post, a local "draft" instance is saved. It should be removed if I didn't save anything when I exist the editor, but it looks like it stays there.
Note that the gif shows the Drafts
tab.
Exit without editing:
I noticed that if I add an image to the post, it will always ask me if I want to save before closing the editor, even if I didn't edit anything, or even if I press on Update
first.
I'm not sure if this issue is general for both Aztec and Gutenberg. In Aztec there is a known similar issue, so it might not be related to this PR.
If you find out that it's an issue is related to Aztec, or anywhere else that doesn't concern the specific changes made in this PR, I'd advice on leaving it for the future.
} | ||
} | ||
|
||
let navigationBarManager = PostEditorNavigationBarManager() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the name change! 👍
return PostEditorUtil(context: self) | ||
}() | ||
|
||
fileprivate let gutenberg: Gutenberg |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding access control to some properties!
I was wondering if fileprivate
is required or we can go with private
, thinking that we now can access private
properties from extensions too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good reminder 👍 I almost forgot that new behavior about private
} | ||
|
||
var isPublishButtonEnabled: Bool { | ||
return true | ||
return self.postEditorStateContext.isPublishButtonEnabled |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small nitpick: We could clean up self.
since it's not really.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, self. here has came via copy/paste.
@@ -141,6 +219,7 @@ extension GutenbergController: PostEditorNavigationBarManagerDelegate { | |||
} | |||
|
|||
func navigationBarManager(_ manager: PostEditorNavigationBarManager, publishButtonWasPressed sender: UIButton) { | |||
requestHTMLReason = .publish |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit worried about this property holding a state that will later on be used to decide what to do with the html
provided by Gutenberg.
I think we can keep it as a first step, but later on it might be dangerous, since if this property changes before Gutenberg returns the html required, it might do something we don't want to.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agreed. it is absolutely not an ideal solution, better solution would be to pass the bridge the reason of html request and take back that reason in the callback. I did this only because the bridge operation only lasted 0.004 seconds, users can't tap another place in this much little time so in terms of practical world I can say that we are safe, at least for now.
but still let's discuss on this and try to find a better solution.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the bridge operation only lasted 0.004 seconds
That is reassuring :)
} | ||
|
||
struct Analytics { | ||
static let editorSource = "aztec" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Analytics.editorSource
is now shared between Aztec and Gutenberg. We will need to make this property dynamic to take into account that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great catch 👍
This is added to make it similar to Aztec editor
Thanks for your detailed review @etoledom 🎉 I have investigated 2 issues you detected:
|
# Conflicts: # Gutenberg # WordPress/Classes/ViewRelated/Aztec/ViewControllers/AztecPostViewController.swift # WordPress/RN/Gutenberg/GutenbergController.swift
I have merged from try/gutenberg so the subrepo Gutenberg isn't used from now on you'll need to remove pods folder and run pod install all over again. And then you'll need to run yarn start on a separate gutenberg-mobile repo. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good! Great job 🎉
* Make a draft solution for gutenberg publish * Handle close button tap & fix lint issues * Update gutenberg mobile subrepo ref * Extract protocol PublishablePostEditor * Set publish button test label from postEditorStateContext * Update gutenberg-mobile subrepo ref * Update gutenberg-mobile subrepo ref to point to master * Revert Podfile.lock updates * Fix some access modifiers and make some line changes * Comment out unnecessary line * Fix code review comments * Fix always creating a new draft even if nothing changes * Add PostCoordinator cancelAnyPending call to init This is added to make it similar to Aztec editor * Remove unnecessary yarn files
Description
This change adds Publish functionality to the Gutenberg editor. Related issue: wordpress-mobile/gutenberg-mobile#182
Below buttons gain new functionality with this change:
Implementation Details
The basic idea of the implementation is to move common functionality to PostEditorUtil and use it from both GutenbergViewController and AztecPostViewController. So the change set mostly consists of cut/paste from AztecPostViewController to PostEditorUtil. Despite of being big it actually doesn't change a lot since all its doing is moving the logic to another place and solving the compile errors resulting from that. I tested AztecPostViewController by comparing the screen on 2 simulators (one is from master branch the other one is from current branch) and it looks OK but I highly encourage reviewers to do the same king of comparison test.
On the other hand, if this looks risky to you we can just reset everything we did to AztecPostViewController, the Gutenberg side wouldn't be affected from that but it'll cause duplicate logic so I would go with common utility where possible.
Test
Testing prerequisites:
I also strongly encourage opening another iOS simulator that runs the code from the master branch. It gives opportunity to compare each part and saving lots of time when we need to decide if sth is the default behavior.
Keep in mind:
currently Publish(Or Update) button is always active on Gutenberg editor unlike Aztec editor. This is done intentionally because Gutenberg side doesn't have the capability of informing every single change yet.
If the post is new or Draft you'll see button label as "Publish", but if you try to edit a published post you 'll see it as "Update". This can be confusing but it is actually a design intent.
Gutenberg tests
Test 1 - Edit published post:
Test 2: Close button
Test 2.1 - Close edited post(which was published before) with "Publish" option:
Test 2.2 - Attempt Close edited post(which was published before) and then "Keep editing":
Test 2.3 - Close edited post(which was published before) with "Discard" option:
Test 2.4 Close un-edited post
Aztec tests
Open EditorSettings.swift in branch try/gutenberg-publish.
Update this line
private var current: Editor { return .gutenberg }
as
private var current: Editor { return .aztec }
Reopen the WordPress-iOS app in try/gutenberg-publish.
Test and compare below cases between WordPress-iOS master and try/gutenberg-publish.
Create a new post and Save as draft
Create a new post and Publish
Edit a draft post and Update
Edit a draft post, tap Close button and Discard
Edit a draft post, tap Close button and Update Draft
Edit a draft post, tap Close button and Keep Editing
Edit a draft post and select navigation bar right button (...)->"Publish Now"
Edit a published post and Update
Edit a published post, tap Close button and Discard
Edit a published post, tap Close button and Update Draft
Edit a published post, tap Close button and Keep Editing
The change doesn't affect this directly but trying also uploading a media, adding a link and other things and publishing would be good.