Skip to content

Commit 37a9167

Browse files
authored
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
1 parent abe29bb commit 37a9167

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

packages/edit-site/src/hooks/commands/use-edit-mode-commands.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,10 @@ function useManipulateDocumentCommands() {
111111
template.type === 'wp_template'
112112
? __( 'Delete template' )
113113
: __( 'Delete template part' );
114+
const path =
115+
template.type === 'wp_template'
116+
? '/wp_template'
117+
: '/wp_template_part/all';
114118
commands.push( {
115119
name: 'core/remove-template',
116120
label,
@@ -119,7 +123,7 @@ function useManipulateDocumentCommands() {
119123
removeTemplate( template );
120124
// Navigate to the template list
121125
history.push( {
122-
path: '/' + template.type,
126+
path,
123127
} );
124128
close();
125129
},

packages/edit-site/src/store/actions.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,18 @@ export const removeTemplate =
141141
throw lastError;
142142
}
143143

144+
// Depending on how the entity was retrieved it's title might be
145+
// an object or simple string.
146+
const templateTitle =
147+
typeof template.title === 'string'
148+
? template.title
149+
: template.title?.rendered;
150+
144151
registry.dispatch( noticesStore ).createSuccessNotice(
145152
sprintf(
146153
/* translators: The template/part's name. */
147154
__( '"%s" deleted.' ),
148-
decodeEntities( template.title.rendered )
155+
decodeEntities( templateTitle )
149156
),
150157
{ type: 'snackbar', id: 'site-editor-template-deleted-success' }
151158
);

0 commit comments

Comments
 (0)