From 37a91675047f1e0a2bf777d8f5fb8932b84f9b5a Mon Sep 17 00:00:00 2001 From: Aki Hamano <54422211+t-hamano@users.noreply.github.com> Date: Fri, 30 Jun 2023 12:45:38 +0900 Subject: [PATCH] Command Palette: fix incorrect path and snackbar message when template part is deleted (#52034) * Command Center: Fix incorrect navigation when deleting template part * removeTemplate: consider title type --- .../src/hooks/commands/use-edit-mode-commands.js | 6 +++++- packages/edit-site/src/store/actions.js | 9 ++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/packages/edit-site/src/hooks/commands/use-edit-mode-commands.js b/packages/edit-site/src/hooks/commands/use-edit-mode-commands.js index 92ccee08592cd..e9e00b9723a12 100644 --- a/packages/edit-site/src/hooks/commands/use-edit-mode-commands.js +++ b/packages/edit-site/src/hooks/commands/use-edit-mode-commands.js @@ -111,6 +111,10 @@ function useManipulateDocumentCommands() { template.type === 'wp_template' ? __( 'Delete template' ) : __( 'Delete template part' ); + const path = + template.type === 'wp_template' + ? '/wp_template' + : '/wp_template_part/all'; commands.push( { name: 'core/remove-template', label, @@ -119,7 +123,7 @@ function useManipulateDocumentCommands() { removeTemplate( template ); // Navigate to the template list history.push( { - path: '/' + template.type, + path, } ); close(); }, diff --git a/packages/edit-site/src/store/actions.js b/packages/edit-site/src/store/actions.js index 8da362ca01f17..ac07ac5beaa2a 100644 --- a/packages/edit-site/src/store/actions.js +++ b/packages/edit-site/src/store/actions.js @@ -141,11 +141,18 @@ export const removeTemplate = throw lastError; } + // Depending on how the entity was retrieved it's title might be + // an object or simple string. + const templateTitle = + typeof template.title === 'string' + ? template.title + : template.title?.rendered; + registry.dispatch( noticesStore ).createSuccessNotice( sprintf( /* translators: The template/part's name. */ __( '"%s" deleted.' ), - decodeEntities( template.title.rendered ) + decodeEntities( templateTitle ) ), { type: 'snackbar', id: 'site-editor-template-deleted-success' } );