From dc9ffbbbc98e84a4d46e0c386369d5262f222bb2 Mon Sep 17 00:00:00 2001 From: epiqueras Date: Thu, 12 Sep 2019 14:26:07 -0400 Subject: [PATCH] Editor: Don't edit the post when autosaving. --- packages/editor/src/store/actions.js | 10 +++++++--- packages/editor/src/store/test/actions.js | 12 +++++++----- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/packages/editor/src/store/actions.js b/packages/editor/src/store/actions.js index a20b0624fa3ea9..371cee91eb0495 100644 --- a/packages/editor/src/store/actions.js +++ b/packages/editor/src/store/actions.js @@ -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', @@ -390,6 +393,7 @@ export function* savePost( options = {} ) { previousRecord.type, previousRecord.id ) ), + ...edits, }; yield dispatch( 'core', diff --git a/packages/editor/src/store/test/actions.js b/packages/editor/src/store/test/actions.js index cdc354dca9346c..f7260918d3a655 100644 --- a/packages/editor/src/store/test/actions.js +++ b/packages/editor/src/store/test/actions.js @@ -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 ) ); + } }, ], [ @@ -148,7 +150,7 @@ describe( 'Post generator actions', () => { 'saveEntityRecord', 'postType', post.type, - post, + isAutosave ? { ...post, content: undefined } : post, { isAutosave, }