File tree Expand file tree Collapse file tree 3 files changed +37
-17
lines changed Expand file tree Collapse file tree 3 files changed +37
-17
lines changed Original file line number Diff line number Diff line change @@ -32,6 +32,7 @@ import {
3232import { store as editorStore } from '../../store' ;
3333import { unlock } from '../../lock-unlock' ;
3434import isTemplateRevertable from '../../store/utils/is-template-revertable' ;
35+ import isTemplatePartRevertable from '../../store/utils/is-template-part-revertable' ;
3536import { exportPatternAsJSONAction } from './export-pattern-action' ;
3637import { CreateTemplatePartModalContents } from '../create-template-part-modal' ;
3738
@@ -787,22 +788,6 @@ const useDuplicatePostAction = ( postType ) => {
787788 ) ;
788789} ;
789790
790- const isTemplatePartRevertable = ( item ) => {
791- if ( ! item ) {
792- return false ;
793- }
794- // In patterns list page we map the templates parts to a different object
795- // than the one returned from the endpoint. This is why we need to check for
796- // two props whether is custom or has a theme file.
797- const hasThemeFile =
798- item . has_theme_file || item . templatePart ?. has_theme_file ;
799- const isCustom = [ item . source , item . templatePart ?. source ] . includes (
800- TEMPLATE_ORIGINS . custom
801- ) ;
802-
803- return hasThemeFile && isCustom ;
804- } ;
805-
806791const resetTemplateAction = {
807792 id : 'reset-template' ,
808793 label : __ ( 'Reset' ) ,
Original file line number Diff line number Diff line change @@ -15,6 +15,8 @@ import { decodeEntities } from '@wordpress/html-entities';
1515 * Internal dependencies
1616 */
1717import isTemplateRevertable from './utils/is-template-revertable' ;
18+ import isTemplatePartRevertable from './utils/is-template-part-revertable' ;
19+ import { TEMPLATE_PART_POST_TYPE } from './constants' ;
1820export * from '../dataviews/store/private-actions' ;
1921
2022/**
@@ -241,7 +243,12 @@ export const revertTemplate =
241243 async ( { registry } ) => {
242244 const noticeId = 'edit-site-template-reverted' ;
243245 registry . dispatch ( noticesStore ) . removeNotice ( noticeId ) ;
244- if ( ! isTemplateRevertable ( template ) ) {
246+
247+ const isRevertable =
248+ template . type === TEMPLATE_PART_POST_TYPE
249+ ? isTemplatePartRevertable
250+ : isTemplateRevertable ;
251+ if ( ! isRevertable ( template ) ) {
245252 registry
246253 . dispatch ( noticesStore )
247254 . createErrorNotice ( __ ( 'This template is not revertable.' ) , {
Original file line number Diff line number Diff line change 1+ /**
2+ * Internal dependencies
3+ */
4+ import { TEMPLATE_ORIGINS } from '../constants' ;
5+
6+ /**
7+ * Check if a template part is revertable to its original theme-provided template file.
8+ *
9+ * @param {Object } templatePart The template part entity to check.
10+ * @return {boolean } Whether the template part is revertable.
11+ */
12+ export default function isTemplatePartRevertable ( templatePart ) {
13+ if ( ! templatePart ) {
14+ return false ;
15+ }
16+ // In patterns list page we map the templates parts to a different object
17+ // than the one returned from the endpoint. This is why we need to check for
18+ // two props whether is custom or has a theme file.
19+ const hasThemeFile =
20+ templatePart . has_theme_file ||
21+ templatePart . templatePart ?. has_theme_file ;
22+ const isCustom = [
23+ templatePart . source ,
24+ templatePart . templatePart ?. source ,
25+ ] . includes ( TEMPLATE_ORIGINS . custom ) ;
26+
27+ return hasThemeFile && isCustom ;
28+ }
You can’t perform that action at this time.
0 commit comments