From d7c3a32d0b9cfe588b4714c55aa1a2a295e265c5 Mon Sep 17 00:00:00 2001 From: ramon Date: Tue, 21 Nov 2023 11:22:22 +1100 Subject: [PATCH 1/2] Migrating global styles revisions to new core data API and deprecating *ThemeGlobalStyleRevision selector and action. --- 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 | 9 +++++++-- 5 files changed, 28 insertions(+), 3 deletions(-) diff --git a/docs/reference-guides/data/data-core.md b/docs/reference-guides/data/data-core.md index 6084eff930394..b2a75638ace9f 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 f7a177b5c5587..ebc467f7fede2 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 d71c5d6120089..4c5622ac78058 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 4a893f5557d86..5751a80b9106c 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 6e3573061a421..87e7339ec787b 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,19 @@ 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() + ) || EMPTY_ARRAY; const _authors = getUsers( SITE_EDITOR_AUTHORS_QUERY ) || EMPTY_ARRAY; return { From 08acb4cb9e76d11c6f3e1d62321f4848d4dcc082 Mon Sep 17 00:00:00 2001 From: ramon Date: Tue, 21 Nov 2023 15:35:18 +1100 Subject: [PATCH 2/2] Limiting the results to 100 --- .../screen-revisions/use-global-styles-revisions.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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 87e7339ec787b..0c293e417cf8e 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 @@ -43,7 +43,10 @@ export default function useGlobalStylesRevisions() { getRevisions( 'root', 'globalStyles', - __experimentalGetCurrentGlobalStylesId() + __experimentalGetCurrentGlobalStylesId(), + { + per_page: 100, + } ) || EMPTY_ARRAY; const _authors = getUsers( SITE_EDITOR_AUTHORS_QUERY ) || EMPTY_ARRAY;