From 61f965533542941fd9ffe525933fa61c52464f00 Mon Sep 17 00:00:00 2001 From: Luigi Teschio Date: Wed, 30 Oct 2024 19:52:22 +0100 Subject: [PATCH] implement logic to reset to default template --- .../src/fields/template/template-edit.tsx | 29 ++++++++++++++++--- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/packages/fields/src/fields/template/template-edit.tsx b/packages/fields/src/fields/template/template-edit.tsx index aee40d792afeff..e323da91bd4bdd 100644 --- a/packages/fields/src/fields/template/template-edit.tsx +++ b/packages/fields/src/fields/template/template-edit.tsx @@ -192,11 +192,29 @@ export const TemplateEdit = ( { : '' } ) } - renderContent={ () => ( + renderContent={ ( { onToggle } ) => ( - setShowModal( true ) }> + { + setShowModal( true ); + onToggle(); + } } + > { __( 'Swap template' ) } + { + // The default template in a post is indicated by an empty string + value !== '' && ( + { + onChangeControl( '' ); + onToggle(); + } } + > + { __( 'Use default template' ) } + + ) + } ) } /> @@ -212,8 +230,11 @@ export const TemplateEdit = ( { label={ __( 'Templates' ) } blockPatterns={ templatesAsPatterns } shownPatterns={ shownTemplates } - onClickPattern={ ( template: WpTemplate ) => { - onChangeControl( template.id ); + onClickPattern={ ( + template: ( typeof templatesAsPatterns )[ 0 ] + ) => { + onChangeControl( template.name ); + setShowModal( false ); } } />