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 @@ -31,6 +31,7 @@ import {
3131import { store as editorStore } from '../../store' ;
3232import { unlock } from '../../lock-unlock' ;
3333import isTemplateRevertable from '../../store/utils/is-template-revertable' ;
34+ import isTemplatePartRevertable from '../../store/utils/is-template-part-revertable' ;
3435import { exportPatternAsJSONAction } from './export-pattern-action' ;
3536import { CreateTemplatePartModalContents } from '../create-template-part-modal' ;
3637
@@ -870,22 +871,6 @@ const useDuplicatePostAction = ( postType ) => {
870871 ) ;
871872} ;
872873
873- const isTemplatePartRevertable = ( item ) => {
874- if ( ! item ) {
875- return false ;
876- }
877- // In patterns list page we map the templates parts to a different object
878- // than the one returned from the endpoint. This is why we need to check for
879- // two props whether is custom or has a theme file.
880- const hasThemeFile =
881- item . has_theme_file || item . templatePart ?. has_theme_file ;
882- const isCustom = [ item . source , item . templatePart ?. source ] . includes (
883- TEMPLATE_ORIGINS . custom
884- ) ;
885-
886- return hasThemeFile && isCustom ;
887- } ;
888-
889874const resetTemplateAction = {
890875 id : 'reset-template' ,
891876 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