Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I put ? just in case. This implementation is also done in the following locations:

const templateTitle = typeof title === 'string' ? title : 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