From 56d0e9ef473676cd3f2ff823beea36948dcbff46 Mon Sep 17 00:00:00 2001 From: epiqueras Date: Thu, 8 Aug 2019 19:05:14 -0400 Subject: [PATCH] Core Data: Fix autosaves filtering. --- packages/core-data/src/actions.js | 7 ++++--- packages/editor/src/store/selectors.js | 9 ++------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/packages/core-data/src/actions.js b/packages/core-data/src/actions.js index 02ad7d3176859..a56709e0b1d81 100644 --- a/packages/core-data/src/actions.js +++ b/packages/core-data/src/actions.js @@ -260,7 +260,7 @@ export function* saveEntityRecord( // have a value. let data = { ...persistedRecord, ...autosavePost, ...record }; data = Object.keys( data ).reduce( ( acc, key ) => { - if ( key in [ 'title', 'excerpt', 'content' ] ) { + if ( [ 'title', 'excerpt', 'content' ].includes( key ) ) { acc[ key ] = get( data[ key ], 'raw', data[ key ] ); } return acc; @@ -281,10 +281,11 @@ export function* saveEntityRecord( } if ( getNoticeActionArgs ) { - const args = getNoticeActionArgs( + const postType = updatedRecord.type || persistedRecord.type; + const args = postType && getNoticeActionArgs( persistedRecord, updatedRecord, - yield select( 'getPostType', updatedRecord.type ) + yield select( 'getPostType', postType ) ); if ( args && args.length ) { yield dispatch( diff --git a/packages/editor/src/store/selectors.js b/packages/editor/src/store/selectors.js index c4bf57dfb2f68..003bd720861b9 100644 --- a/packages/editor/src/store/selectors.js +++ b/packages/editor/src/store/selectors.js @@ -347,12 +347,7 @@ export function getEditedPostAttribute( state, attributeName ) { * @return {*} Autosave attribute value. */ export const getAutosaveAttribute = createRegistrySelector( ( select ) => ( state, attributeName ) => { - deprecated( '`wp.data.select( \'core/editor\' ).getAutosaveAttribute( attributeName )`', { - alternative: '`wp.data.select( \'core\' ).getAutosave( postType, postId, userId )`', - plugin: 'Gutenberg', - } ); - - if ( ! includes( AUTOSAVE_PROPERTIES, attributeName ) ) { + if ( ! includes( AUTOSAVE_PROPERTIES, attributeName ) && attributeName !== 'preview_link' ) { return; } @@ -747,7 +742,7 @@ export function getEditedPostPreviewLink( state ) { return; } - let previewLink = getEditedPostAttribute( state, 'preview_link' ); + let previewLink = getAutosaveAttribute( state, 'preview_link' ); if ( ! previewLink ) { previewLink = getEditedPostAttribute( state, 'link' ); if ( previewLink ) {