From 4d5de1b9e12353872a4ecdbdfed773cfe3dd5571 Mon Sep 17 00:00:00 2001 From: epiqueras Date: Wed, 21 Aug 2019 13:55:16 -0700 Subject: [PATCH] Core Data: Set auto-drafts to drafts when autosaving them. --- packages/core-data/src/actions.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/packages/core-data/src/actions.js b/packages/core-data/src/actions.js index 91f284959d7967..b19aa86775b074 100644 --- a/packages/core-data/src/actions.js +++ b/packages/core-data/src/actions.js @@ -256,13 +256,16 @@ export function* saveEntityRecord( // to the actual persisted entity if the edits don't // have a value. let data = { ...persistedRecord, ...autosavePost, ...record }; - data = Object.keys( data ).reduce( ( acc, key ) => { - if ( [ 'title', 'excerpt', 'content' ].includes( key ) ) { - // Edits should be the "raw" attribute values. - acc[ key ] = get( data[ key ], 'raw', data[ key ] ); - } - return acc; - }, {} ); + data = Object.keys( data ).reduce( + ( acc, key ) => { + if ( [ 'title', 'excerpt', 'content' ].includes( key ) ) { + // Edits should be the "raw" attribute values. + acc[ key ] = get( data[ key ], 'raw', data[ key ] ); + } + return acc; + }, + { status: data.status === 'auto-draft' ? 'draft' : data.status } + ); updatedRecord = yield apiFetch( { path: `${ path }/autosaves`, method: 'POST', @@ -275,7 +278,7 @@ export function* saveEntityRecord( yield receiveEntityRecords( kind, name, - { ...persistedRecord, ...updatedRecord }, + { ...persistedRecord, ...data, ...updatedRecord }, undefined, true );