Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Global styles revisions: migrate API call to getRevisions() #56349

Merged
merged 2 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the moment there's a limit of 100 revisions set by WP_REST_Controller

Limit the results per page to 100 until we can implement pagination. See:

Thanks to @andrewserong for reminding me 😴

}
) || EMPTY_ARRAY;
const _authors = getUsers( SITE_EDITOR_AUTHORS_QUERY ) || EMPTY_ARRAY;

return {
Expand Down
Loading