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: Don't edit the post when autosaving. #17420

Merged
merged 1 commit into from
Sep 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions packages/editor/src/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -375,13 +375,16 @@ export function* savePost( options = {} ) {
if ( ! ( yield select( STORE_KEY, 'isEditedPostSaveable' ) ) ) {
return;
}
yield dispatch( STORE_KEY, 'editPost', {
let edits = {
content: yield select( STORE_KEY, 'getEditedPostContent' ),
} );
};
if ( ! options.isAutosave ) {
yield dispatch( STORE_KEY, 'editPost', edits );
}

yield __experimentalRequestPostUpdateStart( options );
const previousRecord = yield select( STORE_KEY, 'getCurrentPost' );
const edits = {
edits = {
id: previousRecord.id,
...( yield select(
'core',
Expand All @@ -390,6 +393,7 @@ export function* savePost( options = {} ) {
previousRecord.type,
previousRecord.id
) ),
...edits,
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you explain this concatenation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We still want autosaves to have the latest content. This makes sure of that without editing the entity.

};
yield dispatch(
'core',
Expand Down
12 changes: 7 additions & 5 deletions packages/editor/src/store/test/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,14 @@ describe( 'Post generator actions', () => {
},
],
[
"yields an action for editing the post entity's content",
"yields an action for editing the post entity's content if not an autosave",
() => true,
() => {
const edits = { content: currentPost().content };
const { value } = fulfillment.next( edits.content );
expect( value ).toEqual( dispatch( STORE_KEY, 'editPost', edits ) );
if ( ! isAutosave ) {
const edits = { content: currentPost().content };
const { value } = fulfillment.next( edits.content );
expect( value ).toEqual( dispatch( STORE_KEY, 'editPost', edits ) );
}
},
],
[
Expand Down Expand Up @@ -148,7 +150,7 @@ describe( 'Post generator actions', () => {
'saveEntityRecord',
'postType',
post.type,
post,
isAutosave ? { ...post, content: undefined } : post,
{
isAutosave,
}
Expand Down