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: Ignore save edit in undo history. #17452

Merged
merged 6 commits into from
Sep 16, 2019

Conversation

epiqueras
Copy link
Contributor

Description

This PR fixes the leftover issue from #17259 (comment) by adding functionality to core-data that allows edits to opt out of being tracked in undo history and using that for the edit that persists the latest content right before saving.

It also adds a test to guard for this regression.

How has this been tested?

The steps from #17259 (comment) no longer create an extra undo level.

Types of Changes

New Feature: core-data edits can now opt out of being tracked in history through an extra optional parameter, ignoreUndo.

Bug Fix: Extra undo levels are no longer created when saving the post.

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.

@epiqueras epiqueras added [Package] Core data /packages/core-data [Package] Editor /packages/editor labels Sep 16, 2019
@epiqueras epiqueras added this to the Future milestone Sep 16, 2019
@epiqueras epiqueras self-assigned this Sep 16, 2019
@epiqueras epiqueras force-pushed the fix/ignore-save-edit-in-undo-history branch from e6c2ee3 to e8f75f7 Compare September 16, 2019 14:35
*
* @return {Object} Action object.
*/
export function* editEntityRecord( kind, name, recordId, edits ) {
export function* editEntityRecord( kind, name, recordId, edits, undoIgnore ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we mark this argument as experimental? Also maybe an object is better in case we'd need more "options" in the future?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think it should be experimental, but it should be an object.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@youknowriad youknowriad modified the milestones: Future, Gutenberg 6.5 Sep 16, 2019
Copy link
Contributor

@youknowriad youknowriad left a comment

Choose a reason for hiding this comment

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

Tested and works well for me.

Copy link
Member

@ellatrix ellatrix left a comment

Choose a reason for hiding this comment

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

I still have the issue on publish.

@ellatrix
Copy link
Member

Added an e2e test for publishing. Would be great if this could be ignored the same way.

@ellatrix
Copy link
Member

I guess publishing is something that could be undone if it actually reverts the post to a draft. But not sure if that would be an expected user experience.

@@ -155,7 +155,7 @@ export default compose( [
withDispatch( ( dispatch ) => {
const { editPost, savePost } = dispatch( 'core/editor' );
return {
onStatusChange: ( status ) => editPost( { status } ),
onStatusChange: ( status ) => editPost( { status }, { undoIgnore: true } ),
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if this is the right place to make this decision. Should status changes in general be ignored? Or publish status changes? Genuinely wondering...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It depends on the context and the entity.

This will cover publishing status changes for posts and it makes sense to ignore that.

It will be very context-dependent which is why I didn't make it part of the entity configuration.

Copy link
Member

Choose a reason for hiding this comment

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

Ok fair enough.

@epiqueras
Copy link
Contributor Author

Good catch @ellatrix! I don't think these or any other post status changes should be part of undo.

Fixed here: c95501a

@youknowriad
Copy link
Contributor

JS unit tests are failing

@epiqueras epiqueras merged commit 06ba5af into master Sep 16, 2019
@epiqueras epiqueras deleted the fix/ignore-save-edit-in-undo-history branch September 16, 2019 16:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package] Core data /packages/core-data [Package] Editor /packages/editor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants