-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DataViews Extensibility: Allow unregistering the view post revisions …
…action (#64464) Co-authored-by: youknowriad <[email protected]> Co-authored-by: ntsekouras <[email protected]>
- Loading branch information
1 parent
7502c6a
commit ea0bcf1
Showing
5 changed files
with
66 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
packages/editor/src/dataviews/actions/view-post-revisions.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { addQueryArgs } from '@wordpress/url'; | ||
import { __, sprintf } from '@wordpress/i18n'; | ||
import type { Action } from '@wordpress/dataviews'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import type { Post } from '../types'; | ||
|
||
const viewPostRevisions: Action< Post > = { | ||
id: 'view-post-revisions', | ||
context: 'list', | ||
label( items ) { | ||
const revisionsCount = | ||
items[ 0 ]._links?.[ 'version-history' ]?.[ 0 ]?.count ?? 0; | ||
return sprintf( | ||
/* translators: %s: number of revisions */ | ||
__( 'View revisions (%s)' ), | ||
revisionsCount | ||
); | ||
}, | ||
isEligible( post ) { | ||
if ( post.status === 'trash' ) { | ||
return false; | ||
} | ||
const lastRevisionId = | ||
post?._links?.[ 'predecessor-version' ]?.[ 0 ]?.id ?? null; | ||
const revisionsCount = | ||
post?._links?.[ 'version-history' ]?.[ 0 ]?.count ?? 0; | ||
return !! lastRevisionId && revisionsCount > 1; | ||
}, | ||
callback( posts, { onActionPerformed } ) { | ||
const post = posts[ 0 ]; | ||
const href = addQueryArgs( 'revision.php', { | ||
revision: post?._links?.[ 'predecessor-version' ]?.[ 0 ]?.id, | ||
} ); | ||
document.location.href = href; | ||
if ( onActionPerformed ) { | ||
onActionPerformed( posts ); | ||
} | ||
}, | ||
}; | ||
|
||
export default viewPostRevisions; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters