diff --git a/docs/reference-guides/data/data-core.md b/docs/reference-guides/data/data-core.md index 6084eff930394a..7c5b98b48fd630 100644 --- a/docs/reference-guides/data/data-core.md +++ b/docs/reference-guides/data/data-core.md @@ -739,7 +739,7 @@ _Returns_ ### receiveRevisions -Returns an action object used in signalling that revisions have been received. +Action triggered to receive revision items. _Parameters_ @@ -751,10 +751,6 @@ _Parameters_ - _invalidateCache_ `?boolean`: Should invalidate query caches. - _meta_ `?Object`: Meta information about pagination. -_Returns_ - -- `Object`: Action object. - ### receiveThemeSupports > **Deprecated** since WP 5.9, this is not useful anymore, use the selector direclty. diff --git a/packages/core-data/README.md b/packages/core-data/README.md index f7a177b5c55872..d39db34819a734 100644 --- a/packages/core-data/README.md +++ b/packages/core-data/README.md @@ -250,7 +250,7 @@ _Returns_ ### receiveRevisions -Returns an action object used in signalling that revisions have been received. +Action triggered to receive revision items. _Parameters_ @@ -262,10 +262,6 @@ _Parameters_ - _invalidateCache_ `?boolean`: Should invalidate query caches. - _meta_ `?Object`: Meta information about pagination. -_Returns_ - -- `Object`: Action object. - ### receiveThemeSupports > **Deprecated** since WP 5.9, this is not useful anymore, use the selector direclty. diff --git a/packages/core-data/src/actions.js b/packages/core-data/src/actions.js index 5abe0b60897dc4..3a355ff672fbf8 100644 --- a/packages/core-data/src/actions.js +++ b/packages/core-data/src/actions.js @@ -926,7 +926,7 @@ export function receiveDefaultTemplateId( query, templateId ) { } /** - * Returns an action object used in signalling that revisions have been received. + * Action triggered to receive revision items. * * @param {string} kind Kind of the received entity record revisions. * @param {string} name Name of the received entity record revisions. @@ -935,27 +935,29 @@ export function receiveDefaultTemplateId( query, templateId ) { * @param {?Object} query Query Object. * @param {?boolean} invalidateCache Should invalidate query caches. * @param {?Object} meta Meta information about pagination. - * @return {Object} Action object. */ -export function receiveRevisions( - kind, - name, - recordKey, - records, - query, - invalidateCache = false, - meta -) { - const isTemplate = [ 'wp_template', 'wp_template_part' ].includes( name ); - return { - type: 'RECEIVE_ITEM_REVISIONS', - key: isTemplate ? 'wp_id' : DEFAULT_ENTITY_KEY, - items: Array.isArray( records ) ? records : [ records ], - recordKey, - meta, - query, - kind, - name, - invalidateCache, + +export const receiveRevisions = + ( kind, name, recordKey, records, query, invalidateCache = false, meta ) => + async ( { dispatch } ) => { + const configs = await dispatch( getOrLoadEntitiesConfig( kind ) ); + const entityConfig = configs.find( + ( config ) => config.kind === kind && config.name === name + ); + const key = + entityConfig && entityConfig?.revisionKey + ? entityConfig.revisionKey + : DEFAULT_ENTITY_KEY; + + dispatch( { + type: 'RECEIVE_ITEM_REVISIONS', + key, + items: Array.isArray( records ) ? records : [ records ], + recordKey, + meta, + query, + kind, + name, + invalidateCache, + } ); }; -} diff --git a/packages/core-data/src/entities.js b/packages/core-data/src/entities.js index 89d3c07ee80a00..033e7cb4598016 100644 --- a/packages/core-data/src/entities.js +++ b/packages/core-data/src/entities.js @@ -357,6 +357,7 @@ async function loadPostTypeEntities() { }/${ parentId }/revisions${ revisionId ? '/' + revisionId : '' }`, + revisionKey: isTemplate ? 'wp_id' : DEFAULT_ENTITY_KEY, }; } ); } diff --git a/packages/core-data/src/reducer.js b/packages/core-data/src/reducer.js index 6014d205970634..a499b42f175438 100644 --- a/packages/core-data/src/reducer.js +++ b/packages/core-data/src/reducer.js @@ -377,12 +377,6 @@ function entity( entityConfig ) { } if ( action.type === 'REMOVE_ITEMS' ) { - /* - For templates; - itemIds: ['twentytwentyfour//wp-custom-template-nag'] - But the state key is with one slash: twentytwentyfour/wp-custom-template-nag - So deleteEntityRecord needs send extra data to removeItems? - */ return Object.fromEntries( Object.entries( state ).filter( ( [ id ] ) => diff --git a/packages/core-data/src/resolvers.js b/packages/core-data/src/resolvers.js index 40aa5d9e3e6021..569bc00725f5e4 100644 --- a/packages/core-data/src/resolvers.js +++ b/packages/core-data/src/resolvers.js @@ -744,9 +744,7 @@ export const getRevisions = ) { return; } - const isTemplate = [ 'wp_template', 'wp_template_part' ].includes( - name - ); + if ( query._fields ) { // If requesting specific fields, items and query association to said // records are stored by ID reference. Thus, fields must always include @@ -757,7 +755,7 @@ export const getRevisions = ...new Set( [ ...( getNormalizedCommaSeparable( query._fields ) || [] ), - isTemplate ? 'wp_id' : DEFAULT_ENTITY_KEY, + entityConfig.revisionKey || DEFAULT_ENTITY_KEY, ] ), ].join(), }; @@ -839,9 +837,7 @@ export const getRevision = ) { return; } - const isTemplate = [ 'wp_template', 'wp_template_part' ].includes( - name - ); + if ( query !== undefined && query._fields ) { // If requesting specific fields, items and query association to said // records are stored by ID reference. Thus, fields must always include @@ -852,7 +848,7 @@ export const getRevision = ...new Set( [ ...( getNormalizedCommaSeparable( query._fields ) || [] ), - isTemplate ? 'wp_id' : DEFAULT_ENTITY_KEY, + entityConfig.revisionKey || DEFAULT_ENTITY_KEY, ] ), ].join(), };