diff --git a/packages/core-data/src/entities.js b/packages/core-data/src/entities.js index e85673492ef56e..9f736af1c83784 100644 --- a/packages/core-data/src/entities.js +++ b/packages/core-data/src/entities.js @@ -209,10 +209,12 @@ export const rootEntitiesConfig = [ kind: 'root', baseURL: '/wp/v2/global-styles', baseURLParams: { context: 'edit' }, - plural: 'globalStylesVariations', // Should be different than name. + plural: 'globalStylesVariations', // Should be different from name. getTitle: ( record ) => record?.title?.rendered || record?.title, - getRevisionsUrl: ( parentId ) => - `/wp/v2/global-styles/${ parentId }/revisions`, + getRevisionsUrl: ( parentId, revisionId ) => + `/wp/v2/global-styles/${ parentId }/revisions${ + revisionId ? '/' + revisionId : '' + }`, supports: { revisions: true, }, diff --git a/packages/core-data/src/queried-data/reducer.js b/packages/core-data/src/queried-data/reducer.js index 3462f00b685693..1f9bb64c7889d7 100644 --- a/packages/core-data/src/queried-data/reducer.js +++ b/packages/core-data/src/queried-data/reducer.js @@ -57,7 +57,7 @@ export function getMergedItemIds( itemIds, nextItemIds, page, perPage ) { for ( let i = 0; i < size; i++ ) { // Preserve existing item ID except for subset of range of next items. // We need to check against the possible maximum upper boundary because - // a page could recieve less items than what was previously stored. + // a page could receive fewer than what was previously stored. const isInNextItemsRange = i >= nextItemIdsStartIndex && i < nextItemIdsStartIndex + perPage; mergedItemIds[ i ] = isInNextItemsRange diff --git a/packages/core-data/src/resolvers.js b/packages/core-data/src/resolvers.js index 8735764a880b8b..6e821183e3116b 100644 --- a/packages/core-data/src/resolvers.js +++ b/packages/core-data/src/resolvers.js @@ -801,6 +801,26 @@ export const getRevisions = false, meta ); + + // When requesting all fields, the list of results can be used to + // resolve the `getRevision` selector in addition to `getRevisions`. + if ( ! query?._fields && ! query.context ) { + const key = entityConfig.key || DEFAULT_ENTITY_KEY; + const resolutionsArgs = records + .filter( ( record ) => record[ key ] ) + .map( ( record ) => [ kind, name, recordKey, record[ key ] ] ); + + dispatch( { + type: 'START_RESOLUTIONS', + selectorName: 'getRevision', + args: resolutionsArgs, + } ); + dispatch( { + type: 'FINISH_RESOLUTIONS', + selectorName: 'getRevision', + args: resolutionsArgs, + } ); + } }; // Invalidate cache when a new revision is created. @@ -823,7 +843,7 @@ getRevisions.shouldInvalidate = ( action, kind, name, recordKey ) => * fields, fields must always include the ID. */ export const getRevision = - ( kind, name, recordKey, revisionKey, query = {} ) => + ( kind, name, recordKey, revisionKey, query ) => async ( { dispatch } ) => { const configs = await dispatch( getOrLoadEntitiesConfig( kind ) ); const entityConfig = configs.find(