@@ -31,7 +31,6 @@ import {
3131} from '../../store/constants' ;
3232import { store as editorStore } from '../../store' ;
3333import { unlock } from '../../lock-unlock' ;
34- import isTemplateRevertable from '../../store/utils/is-template-revertable' ;
3534import { exportPatternAsJSONAction } from './export-pattern-action' ;
3635import { CreateTemplatePartModalContents } from '../create-template-part-modal' ;
3736
@@ -804,114 +803,6 @@ const useDuplicatePostAction = ( postType ) => {
804803 ) ;
805804} ;
806805
807- const resetTemplateAction = {
808- id : 'reset-template' ,
809- label : __ ( 'Reset' ) ,
810- isEligible : ( item ) => {
811- return isTemplateRevertable ( item ) ;
812- } ,
813- icon : backup ,
814- supportsBulk : true ,
815- hideModalHeader : true ,
816- RenderModal : ( { items, closeModal, onActionPerformed } ) => {
817- const [ isBusy , setIsBusy ] = useState ( false ) ;
818- const { revertTemplate } = unlock ( useDispatch ( editorStore ) ) ;
819- const { saveEditedEntityRecord } = useDispatch ( coreStore ) ;
820- const { createSuccessNotice, createErrorNotice } =
821- useDispatch ( noticesStore ) ;
822- const onConfirm = async ( ) => {
823- try {
824- for ( const template of items ) {
825- await revertTemplate ( template , {
826- allowUndo : false ,
827- } ) ;
828- await saveEditedEntityRecord (
829- 'postType' ,
830- template . type ,
831- template . id
832- ) ;
833- }
834- createSuccessNotice (
835- items . length > 1
836- ? sprintf (
837- /* translators: The number of items. */
838- __ ( '%s items reset.' ) ,
839- items . length
840- )
841- : sprintf (
842- /* translators: The template/part's name. */
843- __ ( '"%s" reset.' ) ,
844- decodeEntities ( getItemTitle ( items [ 0 ] ) )
845- ) ,
846- {
847- type : 'snackbar' ,
848- id : 'revert-template-action' ,
849- }
850- ) ;
851- } catch ( error ) {
852- let fallbackErrorMessage ;
853- if ( items [ 0 ] . type === TEMPLATE_POST_TYPE ) {
854- fallbackErrorMessage =
855- items . length === 1
856- ? __ (
857- 'An error occurred while reverting the template.'
858- )
859- : __ (
860- 'An error occurred while reverting the templates.'
861- ) ;
862- } else {
863- fallbackErrorMessage =
864- items . length === 1
865- ? __ (
866- 'An error occurred while reverting the template part.'
867- )
868- : __ (
869- 'An error occurred while reverting the template parts.'
870- ) ;
871- }
872- const errorMessage =
873- error . message && error . code !== 'unknown_error'
874- ? error . message
875- : fallbackErrorMessage ;
876-
877- createErrorNotice ( errorMessage , { type : 'snackbar' } ) ;
878- }
879- } ;
880- return (
881- < VStack spacing = "5" >
882- < Text >
883- { __ ( 'Reset to default and clear all customizations?' ) }
884- </ Text >
885- < HStack justify = "right" >
886- < Button
887- variant = "tertiary"
888- onClick = { closeModal }
889- disabled = { isBusy }
890- __experimentalIsFocusable
891- >
892- { __ ( 'Cancel' ) }
893- </ Button >
894- < Button
895- variant = "primary"
896- onClick = { async ( ) => {
897- setIsBusy ( true ) ;
898- await onConfirm ( items ) ;
899- onActionPerformed ?. ( items ) ;
900- setIsBusy ( false ) ;
901- closeModal ( ) ;
902- } }
903- isBusy = { isBusy }
904- disabled = { isBusy }
905- __experimentalIsFocusable
906- >
907- { __ ( 'Reset' ) }
908- </ Button >
909- </ HStack >
910- </ VStack >
911- ) ;
912- } ,
913- } ;
914-
915806export const duplicatePatternAction = {
916807 id : 'duplicate-pattern' ,
917808 label : _x ( 'Duplicate' , 'action label' ) ,
@@ -1037,9 +928,7 @@ export function usePostActions( { postType, onActionPerformed, context } ) {
1037928 isPattern && userCanCreatePostType && duplicatePatternAction ,
1038929 supportsTitle && renamePostActionForPostType ,
1039930 isPattern && exportPatternAsJSONAction ,
1040- isTemplateOrTemplatePart
1041- ? resetTemplateAction
1042- : restorePostActionForPostType ,
931+ ! isTemplateOrTemplatePart && restorePostActionForPostType ,
1043932 ! isTemplateOrTemplatePart &&
1044933 ! isPattern &&
1045934 trashPostActionForPostType ,
0 commit comments