Skip to content

Commit

Permalink
Global styles revisions: migrate API call to getRevisions() (#56349)
Browse files Browse the repository at this point in the history
* Migrating global styles revisions to new core data API and deprecating *ThemeGlobalStyleRevision selector and action.

* Limiting the results to 100
  • Loading branch information
ramonjd authored Nov 21, 2023
1 parent e95bb8c commit 68b0d5b
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 3 deletions.
2 changes: 2 additions & 0 deletions docs/reference-guides/data/data-core.md
Original file line number Diff line number Diff line change
Expand Up @@ -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_
Expand Down
2 changes: 2 additions & 0 deletions packages/core-data/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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_
Expand Down
9 changes: 9 additions & 0 deletions packages/core-data/src/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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,
Expand Down
9 changes: 8 additions & 1 deletion packages/core-data/src/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 68b0d5b

Please sign in to comment.