Skip to content

Commit

Permalink
Core Data: Fix undo to fit e2e expected behaviors.
Browse files Browse the repository at this point in the history
  • Loading branch information
epiqueras committed Aug 9, 2019
1 parent 28bae58 commit afaec5e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 21 deletions.
14 changes: 6 additions & 8 deletions packages/core-data/src/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,21 +330,19 @@ export function undo( state = UNDO_INITIAL_STATE, action ) {
edits: { ...state.flattenedUndo, ...action.meta.undo.edits },
},
];
} else {
// Clear potential redos, because this only supports linear history.
nextState = state.slice( 0, state.offset || undefined );
const lastItem = nextState[ nextState.length - 1 ];
if ( lastItem ) {
lastItem.edits = { ...lastItem.edits, ...state.flattenedUndo };
}
nextState.offset = 0;
return nextState;
}

// Clear potential redos, because this only supports linear history.
nextState = state.slice( 0, state.offset || undefined );
nextState.offset = 0;

nextState.push( {
kind: action.kind,
name: action.name,
recordId: action.recordId,
edits: action.edits,
edits: { ...action.edits, ...state.flattenedUndo },
} );

return nextState;
Expand Down
6 changes: 3 additions & 3 deletions packages/editor/src/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -379,12 +379,12 @@ export function __experimentalOptimisticUpdatePost( edits ) {
* @param {Object} options
*/
export function* savePost( options = {} ) {
yield dispatch( STORE_KEY, 'editPost', {
content: yield select( 'core/editor', 'getEditedPostContent' ),
} );
if ( ! ( yield select( STORE_KEY, 'isEditedPostSaveable' ) ) ) {
return;
}
yield dispatch( STORE_KEY, 'editPost', {
content: yield select( 'core/editor', 'getEditedPostContent' ),
} );

yield __experimentalRequestPostUpdateStart( options );
const postType = yield select( 'core/editor', 'getCurrentPostType' );
Expand Down
20 changes: 10 additions & 10 deletions packages/editor/src/store/test/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,42 +75,42 @@ describe( 'Post generator actions', () => {
);
const testConditions = [
[
'yields an action for selecting the current edited post content',
'yields an action for checking if the post is saveable',
() => true,
() => {
reset( isAutosave );
const { value } = fulfillment.next();
expect( value ).toEqual(
select( STORE_KEY, 'getEditedPostContent' )
select( STORE_KEY, 'isEditedPostSaveable' )
);
},
],
[
"yields an action for editing the post entity's content",
'yields an action for selecting the current edited post content',
() => true,
() => {
const edits = { content: currentPost().content };
const { value } = fulfillment.next( edits.content );
const { value } = fulfillment.next( true );
expect( value ).toEqual(
dispatch( STORE_KEY, 'editPost', edits )
select( STORE_KEY, 'getEditedPostContent' )
);
},
],
[
'yields an action for checking if the post is saveable',
"yields an action for editing the post entity's content",
() => true,
() => {
const { value } = fulfillment.next();
const edits = { content: currentPost().content };
const { value } = fulfillment.next( edits.content );
expect( value ).toEqual(
select( STORE_KEY, 'isEditedPostSaveable' )
dispatch( STORE_KEY, 'editPost', edits )
);
},
],
[
'yields an action for signalling that an update to the post started',
() => true,
() => {
const { value } = fulfillment.next( true );
const { value } = fulfillment.next();
expect( value ).toEqual( {
type: 'REQUEST_POST_UPDATE_START',
options: { isAutosave },
Expand Down

0 comments on commit afaec5e

Please sign in to comment.