Skip to content

Commit 1a29800

Browse files
committed
Reuse the check
1 parent 2018be8 commit 1a29800

File tree

4 files changed

+10
-40
lines changed

4 files changed

+10
-40
lines changed

packages/editor/src/components/post-actions/actions.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ import {
3232
import { store as editorStore } from '../../store';
3333
import { unlock } from '../../lock-unlock';
3434
import isTemplateRevertable from '../../store/utils/is-template-revertable';
35-
import isTemplatePartRevertable from '../../store/utils/is-template-part-revertable';
3635
import { exportPatternAsJSONAction } from './export-pattern-action';
3736
import { CreateTemplatePartModalContents } from '../create-template-part-modal';
3837

@@ -792,9 +791,7 @@ const resetTemplateAction = {
792791
id: 'reset-template',
793792
label: __( 'Reset' ),
794793
isEligible: ( item ) => {
795-
return item.type === TEMPLATE_PART_POST_TYPE
796-
? isTemplatePartRevertable( item )
797-
: isTemplateRevertable( item );
794+
return isTemplateRevertable( item );
798795
},
799796
icon: backup,
800797
supportsBulk: true,

packages/editor/src/store/private-actions.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ import { decodeEntities } from '@wordpress/html-entities';
1515
* Internal dependencies
1616
*/
1717
import isTemplateRevertable from './utils/is-template-revertable';
18-
import isTemplatePartRevertable from './utils/is-template-part-revertable';
19-
import { TEMPLATE_PART_POST_TYPE } from './constants';
2018
export * from '../dataviews/store/private-actions';
2119

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

247-
const isRevertable =
248-
template.type === TEMPLATE_PART_POST_TYPE
249-
? isTemplatePartRevertable
250-
: isTemplateRevertable;
251-
if ( ! isRevertable( template ) ) {
245+
if ( ! isTemplateRevertable( template ) ) {
252246
registry
253247
.dispatch( noticesStore )
254248
.createErrorNotice( __( 'This template is not revertable.' ), {

packages/editor/src/store/utils/is-template-part-revertable.js

Lines changed: 0 additions & 21 deletions
This file was deleted.

packages/editor/src/store/utils/is-template-revertable.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@ import { TEMPLATE_ORIGINS } from '../constants';
66
// Copy of the function from packages/edit-site/src/utils/is-template-revertable.js
77

88
/**
9-
* Check if a template is revertable to its original theme-provided template file.
9+
* Check if a template or template part is revertable to its original theme-provided file.
1010
*
11-
* @param {Object} template The template entity to check.
12-
* @return {boolean} Whether the template is revertable.
11+
* @param {Object} templateOrTemplatePart The entity to check.
12+
* @return {boolean} Whether the entity is revertable.
1313
*/
14-
export default function isTemplateRevertable( template ) {
15-
if ( ! template ) {
14+
export default function isTemplateRevertable( templateOrTemplatePart ) {
15+
if ( ! templateOrTemplatePart ) {
1616
return false;
1717
}
18-
/* eslint-disable camelcase */
18+
1919
return (
20-
template?.source === TEMPLATE_ORIGINS.custom && template?.has_theme_file
20+
templateOrTemplatePart.source === TEMPLATE_ORIGINS.custom &&
21+
templateOrTemplatePart.has_theme_file
2122
);
22-
/* eslint-enable camelcase */
2323
}

0 commit comments

Comments
 (0)