Skip to content

Commit

Permalink
Command Palette: fix incorrect path and snackbar message when templat…
Browse files Browse the repository at this point in the history
…e part is deleted (#52034)

* Command Center: Fix incorrect navigation when deleting template part

* removeTemplate: consider title type
  • Loading branch information
t-hamano committed Jun 30, 2023
1 parent abe29bb commit 37a9167
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -119,7 +123,7 @@ function useManipulateDocumentCommands() {
removeTemplate( template );
// Navigate to the template list
history.push( {
path: '/' + template.type,
path,
} );
close();
},
Expand Down
9 changes: 8 additions & 1 deletion packages/edit-site/src/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' }
);
Expand Down

0 comments on commit 37a9167

Please sign in to comment.