Skip to content
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 edits when navigating away from new post without saving #4539

Merged
merged 2 commits into from
Apr 8, 2016

Conversation

aduth
Copy link
Contributor

@aduth aduth commented Apr 5, 2016

This pull request seeks to resolve an issue where navigating away from a new draft to My Sites will cause the "Add" buttons adjacent to custom post types to link incorrectly to the previously edited post.

Implementation notes:

The issue occurs in the getEditorPath selector, and is a result of how we treat getEditedPost as meaning the unsaved draft when a null post ID is passed, which is further complicated by our logic for generating an editor editor path for a new custom post type by using a null post ID. We should probably seek to create a better distinction between these use-cases, by either creating a standalone getEditorNewPostPath or not considering edits in generating the editor path (changed previously in 16976b3).

Regardless of improvements around getEditorPath, it's reasonable to expect that we should be resetting unsaved draft edits when navigating away from the editor, or at the very least when navigating to a new editor draft session. The changes here add a new exit route hook, discarding post edits if the post was not saved.

Note that the only post edit state currently tracked in Redux state is the post type, and that this issue does not currently affect production environments since the getEditorPath selector is not used in any environment aside from development.

Testing instructions:

Verify that the correct "Add" link is shown for a custom post type after navigating away from the post editor.

  1. Navigate to the post editor
  2. Select a site where a custom post type is enabled
  3. Click My Sites in the master bar
  4. Click the add button next to the custom post type sidebar item
  5. Note that you are navigated to a new editor draft for that custom post type

@aduth aduth added [Feature] Post/Page Editor The editor for editing posts and pages. [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. Custom Post Types (CPT) labels Apr 5, 2016
title: 'Hello World'
},
'': {
title: 'Ribs & Chicken'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🍖 🐔

@timmyc
Copy link
Contributor

timmyc commented Apr 6, 2016

Working well for me.

@timmyc timmyc added [Status] Ready to Merge and removed [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. labels Apr 6, 2016
@aduth aduth force-pushed the fix/cpt-editor-reset-new-post-on-exit branch from c094ed0 to b916684 Compare April 8, 2016 14:59
@aduth aduth merged commit 6adf8b6 into master Apr 8, 2016
@aduth aduth deleted the fix/cpt-editor-reset-new-post-on-exit branch April 8, 2016 15:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Custom Post Types (CPT) [Feature] Post/Page Editor The editor for editing posts and pages.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants