Skip to content

Commit

Permalink
Reuse the check
Browse files Browse the repository at this point in the history
  • Loading branch information
Mamaduka committed Jul 3, 2024
1 parent 9a30180 commit ab9e7b1
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 40 deletions.
5 changes: 1 addition & 4 deletions packages/editor/src/components/post-actions/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import {
import { store as editorStore } from '../../store';
import { unlock } from '../../lock-unlock';
import isTemplateRevertable from '../../store/utils/is-template-revertable';
import isTemplatePartRevertable from '../../store/utils/is-template-part-revertable';
import { exportPatternAsJSONAction } from './export-pattern-action';
import { CreateTemplatePartModalContents } from '../create-template-part-modal';

Expand Down Expand Up @@ -792,9 +791,7 @@ const resetTemplateAction = {
id: 'reset-template',
label: __( 'Reset' ),
isEligible: ( item ) => {
return item.type === TEMPLATE_PART_POST_TYPE
? isTemplatePartRevertable( item )
: isTemplateRevertable( item );
return isTemplateRevertable( item );
},
icon: backup,
supportsBulk: true,
Expand Down
8 changes: 1 addition & 7 deletions packages/editor/src/store/private-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ import { decodeEntities } from '@wordpress/html-entities';
* Internal dependencies
*/
import isTemplateRevertable from './utils/is-template-revertable';
import isTemplatePartRevertable from './utils/is-template-part-revertable';
import { TEMPLATE_PART_POST_TYPE } from './constants';
export * from '../dataviews/store/private-actions';

/**
Expand Down Expand Up @@ -244,11 +242,7 @@ export const revertTemplate =
const noticeId = 'edit-site-template-reverted';
registry.dispatch( noticesStore ).removeNotice( noticeId );

const isRevertable =
template.type === TEMPLATE_PART_POST_TYPE
? isTemplatePartRevertable
: isTemplateRevertable;
if ( ! isRevertable( template ) ) {
if ( ! isTemplateRevertable( template ) ) {
registry
.dispatch( noticesStore )
.createErrorNotice( __( 'This template is not revertable.' ), {
Expand Down
21 changes: 0 additions & 21 deletions packages/editor/src/store/utils/is-template-part-revertable.js

This file was deleted.

16 changes: 8 additions & 8 deletions packages/editor/src/store/utils/is-template-revertable.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ import { TEMPLATE_ORIGINS } from '../constants';
// Copy of the function from packages/edit-site/src/utils/is-template-revertable.js

/**
* Check if a template is revertable to its original theme-provided template file.
* Check if a template or template part is revertable to its original theme-provided file.
*
* @param {Object} template The template entity to check.
* @return {boolean} Whether the template is revertable.
* @param {Object} templateOrTemplatePart The entity to check.
* @return {boolean} Whether the entity is revertable.
*/
export default function isTemplateRevertable( template ) {
if ( ! template ) {
export default function isTemplateRevertable( templateOrTemplatePart ) {
if ( ! templateOrTemplatePart ) {
return false;
}
/* eslint-disable camelcase */

return (
template?.source === TEMPLATE_ORIGINS.custom && template?.has_theme_file
templateOrTemplatePart.source === TEMPLATE_ORIGINS.custom &&
templateOrTemplatePart.has_theme_file
);
/* eslint-enable camelcase */
}

0 comments on commit ab9e7b1

Please sign in to comment.