-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Remove entity edits when deleting an entity #36030
Changes from all commits
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 |
---|---|---|
|
@@ -185,6 +185,8 @@ describe( 'undo', () => { | |
}; | ||
} else if ( args[ 0 ] === 'isCreate' ) { | ||
action = { type: 'CREATE_UNDO_LEVEL' }; | ||
} else if ( args[ 0 ] === 'isRemoveItems' ) { | ||
action = { type: 'REMOVE_ITEMS', ...createEditActionPart() }; | ||
} else if ( args.length ) { | ||
action = createNextEditAction( ...args ); | ||
} | ||
|
@@ -343,6 +345,15 @@ describe( 'undo', () => { | |
expectedUndoState.push( createEditActionPart( { value } ) ); | ||
expect( undoState ).toEqual( expectedUndoState ); | ||
} ); | ||
|
||
it( 'removes undo records when an entity is deleted', () => { | ||
undoState = createNextUndoState(); | ||
undoState = createNextUndoState( { value: 1 } ); | ||
undoState = createNextUndoState( { value: 2 } ); | ||
undoState = createNextUndoState( { value: 3 } ); | ||
undoState = createNextUndoState( 'isRemoveItems' ); | ||
expect( undoState ).toEqual( [] ); | ||
} ); | ||
Comment on lines
+349
to
+356
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. Test would ideally push a different record onto the undo stack to assert that only the deleted record is removed, but it took me so long to understand how these tests work, and it looks like the whole 'framework' for these tests would need to be re-written to support more than one record. Maybe after WordPress 5.9 I'll take some time to look at it, but right now time is something I don't have. |
||
} ); | ||
|
||
describe( 'embedPreviews()', () => { | ||
|
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.
This works, but unfortunately after the removal a new edit is pushed onto the stack for the deleted entity. It isn't undo-able though, the undo button is greyed out. Not sure why, but at least it prevents a buggy state.
I think we also need to avoid pushing
edits
on the stack for removed items to solve this.