Skip to content

Commit

Permalink
Core Data: Set auto-drafts to drafts when autosaving them.
Browse files Browse the repository at this point in the history
  • Loading branch information
epiqueras committed Aug 21, 2019
1 parent fa5365e commit 4d5de1b
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions packages/core-data/src/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -275,7 +278,7 @@ export function* saveEntityRecord(
yield receiveEntityRecords(
kind,
name,
{ ...persistedRecord, ...updatedRecord },
{ ...persistedRecord, ...data, ...updatedRecord },
undefined,
true
);
Expand Down

0 comments on commit 4d5de1b

Please sign in to comment.