From 68b0d5b1db1a154e1b92f6ca2148a7e8ad0ef6fc Mon Sep 17 00:00:00 2001 From: Ramon Date: Wed, 22 Nov 2023 08:00:19 +1100 Subject: [PATCH] Global styles revisions: migrate API call to getRevisions() (#56349) * Migrating global styles revisions to new core data API and deprecating *ThemeGlobalStyleRevision selector and action. * Limiting the results to 100 --- docs/reference-guides/data/data-core.md | 2 ++ packages/core-data/README.md | 2 ++ packages/core-data/src/actions.js | 9 +++++++++ packages/core-data/src/selectors.ts | 9 ++++++++- .../screen-revisions/use-global-styles-revisions.js | 12 ++++++++++-- 5 files changed, 31 insertions(+), 3 deletions(-) diff --git a/docs/reference-guides/data/data-core.md b/docs/reference-guides/data/data-core.md index 6084eff930394a..b2a75638ace9fe 100644 --- a/docs/reference-guides/data/data-core.md +++ b/docs/reference-guides/data/data-core.md @@ -128,6 +128,8 @@ _Returns_ ### getCurrentThemeGlobalStylesRevisions +> **Deprecated** since WordPress 6.5.0. Callers should use `select( 'core' ).getRevisions( 'root', 'globalStyles', ${ recordKey } )` instead, where `recordKey` is the id of the global styles parent post. + Returns the revisions of the current global styles theme. _Parameters_ diff --git a/packages/core-data/README.md b/packages/core-data/README.md index f7a177b5c55872..ebc467f7fede2d 100644 --- a/packages/core-data/README.md +++ b/packages/core-data/README.md @@ -453,6 +453,8 @@ _Returns_ ### getCurrentThemeGlobalStylesRevisions +> **Deprecated** since WordPress 6.5.0. Callers should use `select( 'core' ).getRevisions( 'root', 'globalStyles', ${ recordKey } )` instead, where `recordKey` is the id of the global styles parent post. + Returns the revisions of the current global styles theme. _Parameters_ diff --git a/packages/core-data/src/actions.js b/packages/core-data/src/actions.js index d71c5d6120089e..4c5622ac780589 100644 --- a/packages/core-data/src/actions.js +++ b/packages/core-data/src/actions.js @@ -218,6 +218,8 @@ export function receiveThemeSupports() { * Returns an action object used in signalling that the theme global styles CPT post revisions have been received. * Ignored from documentation as it's internal to the data store. * + * @deprecated since WordPress 6.5.0. Callers should use `dispatch( 'core' ).receiveRevision` instead. + * * @ignore * * @param {number} currentId The post id. @@ -226,6 +228,13 @@ export function receiveThemeSupports() { * @return {Object} Action object. */ export function receiveThemeGlobalStyleRevisions( currentId, revisions ) { + deprecated( + "wp.data.dispatch( 'core' ).receiveThemeGlobalStyleRevisions()", + { + since: '6.5.0', + alternative: "wp.data.dispatch( 'core' ).receiveRevisions", + } + ); return { type: 'RECEIVE_THEME_GLOBAL_STYLE_REVISIONS', currentId, diff --git a/packages/core-data/src/selectors.ts b/packages/core-data/src/selectors.ts index 4a893f5557d862..5751a80b9106cd 100644 --- a/packages/core-data/src/selectors.ts +++ b/packages/core-data/src/selectors.ts @@ -1353,13 +1353,20 @@ export function getUserPatternCategories( /** * Returns the revisions of the current global styles theme. * - * @param state Data state. + * @deprecated since WordPress 6.5.0. Callers should use `select( 'core' ).getRevisions( 'root', 'globalStyles', ${ recordKey } )` instead, where `recordKey` is the id of the global styles parent post. + * + * @param state Data state. * * @return The current global styles. */ export function getCurrentThemeGlobalStylesRevisions( state: State ): Array< object > | null { + deprecated( "select( 'core' ).getCurrentThemeGlobalStylesRevisions()", { + since: '6.5.0', + alternative: + "select( 'core' ).getRevisions( 'root', 'globalStyles', ${ recordKey } )", + } ); const currentGlobalStylesId = __experimentalGetCurrentGlobalStylesId( state ); diff --git a/packages/edit-site/src/components/global-styles/screen-revisions/use-global-styles-revisions.js b/packages/edit-site/src/components/global-styles/screen-revisions/use-global-styles-revisions.js index 6e3573061a4214..0c293e417cf8ef 100644 --- a/packages/edit-site/src/components/global-styles/screen-revisions/use-global-styles-revisions.js +++ b/packages/edit-site/src/components/global-styles/screen-revisions/use-global-styles-revisions.js @@ -32,14 +32,22 @@ export default function useGlobalStylesRevisions() { __experimentalGetDirtyEntityRecords, getCurrentUser, getUsers, - getCurrentThemeGlobalStylesRevisions, + getRevisions, + __experimentalGetCurrentGlobalStylesId, isResolving, } = select( coreStore ); const dirtyEntityRecords = __experimentalGetDirtyEntityRecords(); const _currentUser = getCurrentUser(); const _isDirty = dirtyEntityRecords.length > 0; const globalStylesRevisions = - getCurrentThemeGlobalStylesRevisions() || EMPTY_ARRAY; + getRevisions( + 'root', + 'globalStyles', + __experimentalGetCurrentGlobalStylesId(), + { + per_page: 100, + } + ) || EMPTY_ARRAY; const _authors = getUsers( SITE_EDITOR_AUTHORS_QUERY ) || EMPTY_ARRAY; return {