Skip to content

Commit

Permalink
Add: See revisions template action.
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgefilipecosta committed Dec 18, 2023
1 parent 20aaae7 commit 76e14af
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/edit-site/src/components/page-templates/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import {
useResetTemplateAction,
deleteTemplateAction,
renameTemplateAction,
seeRevisionsAction,
} from './template-actions';
import usePatternSettings from '../page-patterns/use-pattern-settings';
import { unlock } from '../../lock-unlock';
Expand Down Expand Up @@ -332,6 +333,7 @@ export default function DataviewsTemplates() {
resetTemplateAction,
deleteTemplateAction,
renameTemplateAction,
seeRevisionsAction,
],
[ resetTemplateAction ]
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
__experimentalHStack as HStack,
__experimentalVStack as VStack,
} from '@wordpress/components';
import { addQueryArgs } from '@wordpress/url';

/**
* Internal dependencies
Expand Down Expand Up @@ -207,3 +208,23 @@ export const renameTemplateAction = {
);
},
};

export const seeRevisionsAction = {
id: 'see-revisions',
label: __( 'See revisions' ),
isEligible: ( template ) => {
if ( template?._links && template?._links[ 'predecessor-version' ] ) {
const predecessorVersions =
template._links[ 'predecessor-version' ];
return predecessorVersions.length > 0;
}
return false;
},
callback( template ) {
const lastRevisionId =
template?._links[ 'predecessor-version' ][ 0 ].id;
document.location.href = addQueryArgs( 'revision.php', {
revision: lastRevisionId,
} );
},
};

0 comments on commit 76e14af

Please sign in to comment.