-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Fix a few issues with saving post titles, dirty handling, etc. #848
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
Conversation
editor/index.js
Outdated
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.
Trying to think broadly. I see edits as an object of attributes explicitly modified by the user, IMO I don't think we should do this because it creates confusion on what the edit reducer contains.
That said, I've already noticed the bug and as you said, the need for this may disappear when we'll drop the post-content file. An alternative could be to merge the edits with currentPost in the savePost action instead.
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 see edits as more like "the attributes of the post that need to be saved, but haven't yet". status: 'draft' is a good one, along with whatever other defaults we choose for things like visibility. I think this might keep our code a bit cleaner because we can use the same logic to read the current state of the post, for our controls UI.
I don't think we should send the entire currentPost output with each save request. I'm aware of at one core bug that we would hit if we did this: https://core.trac.wordpress.org/ticket/39996 - and I suspect there are probably still a few more.
e8113a8 to
f41e647
Compare
|
Copy/pasting #848 (review) here because it is still relevant, let's move this discussion into the main thread here.
Me
|
|
e8113a8 does a bit to address my first question from the original post. Instead of an |
Me too (just phrased differently) and that's exactly why we shouldn't do this
Setting those sounds good to me (only for the new posts though, not while editing saved posts). But I don't think we should include the title, I don't mind leaving the bug specific to
Fair enough! |
Ah, you are totally right! I forgot this would also be called when initializing the editor using an existing post. Addressed in 9fd008d. |
|
How do you expect us to provide the "default" edits for newly created posts? Should these be included in the By this question, I'm trying to anticipate the behaviour of the editor when we'll drop the default |
I'm imagining something like this, yes. Or maybe the default values could be part of the reducer that handles
This part isn't totally clear to me either. I'd like to avoid a lot of logic like I'll think about it some more over the weekend, hopefully I will get some more ideas while sleeping 😴 |
|
I've worked on something similar in Calypso and IIRC we don't have default edits aside the post type. But like you, I do think it's a good thing to have I was thinking these default values should be part of the editor itself (reducer or a constant in What default edits I'm expecting, I don't know, maybe status, postType, defaultCategory And Enjoy your weekend James 🙂 |
|
Some of this defaulting need assumes we'll stick with a flow where const DEFAULT_EDITS = { status: 'draft' };
function edits( state = DEFAULT_EDITS, action ) {
switch ( action.type ) {
case 'RESET_BLOCKS':
if ( action.post.id ) {
return {};
}
return state;
}
return state;
}What are the cases we'd need to know the default values? Is it just dirty detection, or do we think it'd be useful to say In Calypso we only use it for the former (but could easily do both), comparing against a https://github.com/Automattic/wp-calypso/blob/c7ea1a5/client/state/posts/constants.js#L16-L26 This is another reason I'd like to see "dirtiness" determined by a selector, not tracked in state itself. |
I don't follow this bit... I tried to remove a lot of this logic where
+1 on this approach, but it's not clear to me whether or not we should do that now, with
As currently structured, the default edits don't matter for dirty detection. I do think this will also be useful to avoid a lot of logic like
I'm still sort of worried about this, because of the issues we've seen in the past with dirty detection in Calypso. In theory, editing a block's content and then changing it back should not be a "dirty" state. However, this means that dirty detection has to rely on the block serialization logic. It seems preferable to me to keep this simple and explicit rather than having it depend on a lot of other complicated behavior. At least, because |
Is this referring to false positives on dirtiness when switching between modes? What is it about the current direction here that will address this problem better? |
This, and things like the editor starting as dirty when opening a new page.
For both of the cases above, we take a simple approach based on an explicit list of user-generated actions. Catching all the different (broad) types of user actions, and deciding for each action whether it represents a "dirtying" change, seems easier and simpler to me than serializing all content and post state and comparing it for changes. However I would think redesigning the dirty detection is better addressed in a separate issue/PR. |
Adds a new selector: `isEditedPostNew` based on whether or not our representation of the currently edited post has an ID.
58df2e7 to
1bfcd1b
Compare
|
Any objections to me merging this in the next day or so? |
youknowriad
left a comment
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.
LGTM 👍
I originally started this PR to fix the following bug:
In the process it became a bit sprawly because I found some other related issues to fix.
The original bug is fixed by sending an
EDIT_POSTaction when the editor is initialized with the new post content. This currently containstitleandstatus. Addingstatushere also allowed me to eliminate the distinction thePublishButtoncurrently makes betweenonSaveDraftandonUpdate, unifying these into a singleonSavecallback.I also discovered that editing post visiblility or other properties was not registered as a change by the "dirty" logic. Adding
EDIT_POSTto the list of "dirtying" actions (except for the initialEDIT_POSTaction) fixes this.Finally, it seems useful to have another flag that determines the information
SavedStatedisplays: whether the current post is new or existing. If the current post has not yet been saved, we should indicate this here. This component now has 4 states (the first 2 are new):To test
Test various combinations of loading new and existing posts, modifying them or not, then saving them. For example:
SavedStateindicator displays an "editing" icon and the text "New post".SavedStateindicator displays "Saved".SavedStateindicator still displays "Saved".Load a new post. Make a change to the visibility under "Post settings" and verify that the
SavedStateindicator changes to "New post with changes" (fixed in this PR).Load an existing post. Verify that the
SavedStateindicator switches between "Saved" and "Unsaved changes" when edits are made, Undo/Redo is clicked, and the post is saved (as appropriate). Fixed in this PR for updates like post visibility.Questions
It seems like we need a way to initialize the
editsstate with properties that should be sent to save a new post. The need to initialize the title this way will go away when we removepost-content.js; however, there will probably be other properties we should set this way (statusfor example). Currently this PR accomplishes the task using anEDIT_POSTaction withshouldMarkDirty: false- but this feels like a bit of a hack to me. Can you think of a better way?This PR introduces a new selector:
isEditedPostNew. It feels to me like maybe we should be using this in the publish button and thesavePostaction as well, but it's not entirely clear to me how, because we do still need the actual post ID here to send it to the API. How can this be improved?