@@ -338,9 +338,12 @@ export function setIsListViewOpened( isOpen ) {
338338/**
339339 * Reverts a template to its original theme-provided file.
340340 *
341- * @param {Object } template The template to revert.
341+ * @param {Object } template The template to revert.
342+ * @param {Object } [options]
343+ * @param {boolean } [options.allowUndo] Whether to allow the user to undo
344+ * reverting the template. Default true.
342345 */
343- export function * revertTemplate ( template ) {
346+ export function * revertTemplate ( template , { allowUndo = false } = { } ) {
344347 if ( ! isTemplateRevertable ( template ) ) {
345348 yield controls . dispatch (
346349 noticesStore ,
@@ -428,32 +431,40 @@ export function* revertTemplate( template ) {
428431 }
429432 ) ;
430433
431- const undoRevert = async ( ) => {
432- await dispatch ( coreStore ) . editEntityRecord (
433- 'postType' ,
434- template . type ,
435- edited . id ,
434+ if ( allowUndo ) {
435+ const undoRevert = async ( ) => {
436+ await dispatch ( coreStore ) . editEntityRecord (
437+ 'postType' ,
438+ template . type ,
439+ edited . id ,
440+ {
441+ content : serializeBlocks ,
442+ blocks : edited . blocks ,
443+ source : 'custom' ,
444+ }
445+ ) ;
446+ } ;
447+ yield controls . dispatch (
448+ noticesStore ,
449+ 'createSuccessNotice' ,
450+ __ ( 'Template reverted.' ) ,
436451 {
437- content : serializeBlocks ,
438- blocks : edited . blocks ,
439- source : 'custom' ,
452+ type : 'snackbar' ,
453+ actions : [
454+ {
455+ label : __ ( 'Undo' ) ,
456+ onClick : undoRevert ,
457+ } ,
458+ ] ,
440459 }
441460 ) ;
442- } ;
443- yield controls . dispatch (
444- noticesStore ,
445- 'createSuccessNotice' ,
446- __ ( 'Template reverted.' ) ,
447- {
448- type : 'snackbar' ,
449- actions : [
450- {
451- label : __ ( 'Undo' ) ,
452- onClick : undoRevert ,
453- } ,
454- ] ,
455- }
456- ) ;
461+ } else {
462+ yield controls . dispatch (
463+ noticesStore ,
464+ 'createSuccessNotice' ,
465+ __ ( 'Template reverted.' )
466+ ) ;
467+ }
457468 } catch ( error ) {
458469 const errorMessage =
459470 error . message && error . code !== 'unknown_error'
0 commit comments