-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Editor: Reset Post Edits when switching posts in the post editor #10177
Changes from all commits
b641420
d029c25
31c9c58
de3074e
f8f19dd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -36,8 +36,8 @@ const actions = require( 'lib/posts/actions' ), | |||||||||||||||||||||||||||||||||
import { getSelectedSiteId } from 'state/ui/selectors'; | ||||||||||||||||||||||||||||||||||
import { setEditorLastDraft, resetEditorLastDraft } from 'state/ui/editor/last-draft/actions'; | ||||||||||||||||||||||||||||||||||
import { isEditorDraftsVisible, getEditorPostId, getEditorPath } from 'state/ui/editor/selectors'; | ||||||||||||||||||||||||||||||||||
import { toggleEditorDraftsVisible, setEditorPostId } from 'state/ui/editor/actions'; | ||||||||||||||||||||||||||||||||||
import { receivePost, resetPostEdits } from 'state/posts/actions'; | ||||||||||||||||||||||||||||||||||
import { toggleEditorDraftsVisible } from 'state/ui/editor/actions'; | ||||||||||||||||||||||||||||||||||
import { receivePost, savePostSuccess } from 'state/posts/actions'; | ||||||||||||||||||||||||||||||||||
import { getPostEdits, isEditedPostDirty } from 'state/posts/selectors'; | ||||||||||||||||||||||||||||||||||
import EditorDocumentHead from 'post-editor/editor-document-head'; | ||||||||||||||||||||||||||||||||||
import EditorPostTypeUnsupported from 'post-editor/editor-post-type-unsupported'; | ||||||||||||||||||||||||||||||||||
|
@@ -138,9 +138,6 @@ export const PostEditor = React.createClass( { | |||||||||||||||||||||||||||||||||
componentWillUnmount: function() { | ||||||||||||||||||||||||||||||||||
PostEditStore.removeListener( 'change', this.onEditedPostChange ); | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
// Reset post edits after leaving editor | ||||||||||||||||||||||||||||||||||
this.props.resetPostEdits( this.props.siteId, this.props.postId ); | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
// TODO: REDUX - remove flux actions when whole post-editor is reduxified | ||||||||||||||||||||||||||||||||||
actions.stopEditing(); | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
|
@@ -690,19 +687,12 @@ export const PostEditor = React.createClass( { | |||||||||||||||||||||||||||||||||
this.props.resetEditorLastDraft(); | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
// Assign editor post ID to saved value (especially important when | ||||||||||||||||||||||||||||||||||
// transitioning from an unsaved post to a saved one) | ||||||||||||||||||||||||||||||||||
if ( post.ID !== this.props.postId ) { | ||||||||||||||||||||||||||||||||||
this.props.setEditorPostId( post.ID ); | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
// Remove this when the editor is completely reduxified ( When using Redux actions for all post saving requests ) | ||||||||||||||||||||||||||||||||||
this.props.savePostSuccess( post.site_ID, this.props.postId, post, {} ); | ||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Only by a bit of luck does this not cause a notice to be shown (which would be non-ideal, at least for now, given that it's redundant with the editor's own notice). See: wp-calypso/client/state/notices/middleware.js Lines 78 to 93 in 795cd4d
{} instead included a status property).
Arguably this is an argument against the lack of discoverability of middlewares 😄 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I noticed these notices as well :). I'm starting to think, we should avoid using the middleware to automatically trigger notices on request success. I had to revert my own save settings global notices here #10278 to avoid double notices. I think we should rely on There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Alternatively we could create separate extended action creators for a more specific variations if we only want a notice to be shown in some cases, e.g. adding a meta flag that the middleware checks the presence of. |
||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
// Receive updated post into state | ||||||||||||||||||||||||||||||||||
this.props.receivePost( post ); | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
// Reset previous edits, preserving type | ||||||||||||||||||||||||||||||||||
this.props.resetPostEdits( this.props.siteId ); | ||||||||||||||||||||||||||||||||||
this.props.resetPostEdits( post.site_ID, post.ID ); | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
const nextState = { | ||||||||||||||||||||||||||||||||||
isSaving: false, | ||||||||||||||||||||||||||||||||||
isPublishing: false | ||||||||||||||||||||||||||||||||||
|
@@ -785,8 +775,7 @@ export default connect( | |||||||||||||||||||||||||||||||||
setEditorLastDraft, | ||||||||||||||||||||||||||||||||||
resetEditorLastDraft, | ||||||||||||||||||||||||||||||||||
receivePost, | ||||||||||||||||||||||||||||||||||
resetPostEdits, | ||||||||||||||||||||||||||||||||||
setEditorPostId, | ||||||||||||||||||||||||||||||||||
savePostSuccess, | ||||||||||||||||||||||||||||||||||
setEditorModePreference: savePreference.bind( null, 'editor-mode' ), | ||||||||||||||||||||||||||||||||||
setLayoutFocus, | ||||||||||||||||||||||||||||||||||
}, dispatch ); | ||||||||||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,17 +9,19 @@ import { get, set, omit, omitBy, isEqual, reduce, merge, findKey, mapValues } fr | |
*/ | ||
import PostQueryManager from 'lib/query-manager/post'; | ||
import { | ||
EDITOR_START, | ||
EDITOR_STOP, | ||
POST_DELETE, | ||
POST_DELETE_SUCCESS, | ||
POST_DELETE_FAILURE, | ||
POST_EDIT, | ||
POST_EDITS_RESET, | ||
POST_REQUEST, | ||
POST_REQUEST_SUCCESS, | ||
POST_REQUEST_FAILURE, | ||
POST_RESTORE, | ||
POST_RESTORE_FAILURE, | ||
POST_SAVE, | ||
POST_SAVE_SUCCESS, | ||
POSTS_RECEIVE, | ||
POSTS_REQUEST, | ||
POSTS_REQUEST_SUCCESS, | ||
|
@@ -261,7 +263,16 @@ export function edits( state = {}, action ) { | |
} | ||
} ); | ||
|
||
case POST_EDITS_RESET: | ||
case EDITOR_START: | ||
return Object.assign( {}, state, { | ||
[ action.siteId ]: { | ||
...state[ action.siteId ], | ||
[ action.postId || '' ]: { type: action.postType } | ||
} | ||
} ); | ||
|
||
case EDITOR_STOP: | ||
case POST_SAVE_SUCCESS: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wondered if clearing edits on success would have a negative impact where we currently depend on There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. About that, I think we should move the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is an edit in that it needs to be sent with the initial payload for a new draft of non-post types. Though you're right it's not really editable for saved items and posts of type "post". |
||
if ( ! state.hasOwnProperty( action.siteId ) ) { | ||
break; | ||
} | ||
|
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 seeing a few errors here on the Calypso errors dashboard:
It's not clear to me when or why
context.store
would be ever beundefined
.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.
Maybe it's because https://github.com/Automattic/wp-calypso/blob/master/client/state/initial-state.js#L90 is async. It seems that the context is initialized on the callback of this function https://github.com/Automattic/wp-calypso/blob/master/client/boot/index.js#L260
Is this the only place we have this kind of errors? seems surprising to me
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.
@youknowriad Following the logic from boot, I don't think we render anything until the initial state has finished loading. It may have something to do with it being a
page.exit
handler, which we don't use in very many (any?) other parts of Calypso.