Skip to content

Commit

Permalink
Set decoded title var
Browse files Browse the repository at this point in the history
Ensure correct back path when deleting templates
  • Loading branch information
ramonjd committed Sep 21, 2023
1 parent 314d5b7 commit 3ca6492
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ export default function SidebarNavigationScreenTemplate() {
postId
);

// The absence of a post type in the query params for templates
// indicates the user has arrived at the template via the "manage all"
// page and the back button should return them to that list page.
const backPath =
postType !== 'wp_template' ? `/${ postType }/all` : `/${ postType }`;
return (
<SidebarNavigationScreen
title={ title }
Expand All @@ -108,7 +113,7 @@ export default function SidebarNavigationScreenTemplate() {
postId={ postId }
toggleProps={ { as: SidebarButton } }
onRemove={ () => {
navigator.goTo( `/${ postType }/all` );
navigator.goTo( backPath );
} }
/>
<SidebarButton
Expand Down
13 changes: 6 additions & 7 deletions packages/edit-site/src/components/template-actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ export default function TemplateActions( {
}

const isEditable = isUserPattern || isRemovable;
const decodedTitle = decodeEntities(
record?.title?.rendered || record?.title?.raw
);

const deletePattern = async ( pattern ) => {
try {
Expand All @@ -71,9 +74,7 @@ export default function TemplateActions( {
sprintf(
// translators: %s: The pattern's title e.g. 'Call to action'.
__( '"%s" deleted.' ),
decodeEntities(
pattern?.title?.rendered || pattern?.title?.raw
)
decodedTitle
),
{ type: 'snackbar', id: 'edit-site-patterns-success' }
);
Expand Down Expand Up @@ -106,7 +107,7 @@ export default function TemplateActions( {
sprintf(
/* translators: The template/part's name. */
__( '"%s" reverted.' ),
decodeEntities( item.title.rendered )
decodedTitle
),
{
type: 'snackbar',
Expand Down Expand Up @@ -159,9 +160,7 @@ export default function TemplateActions( {
onRemove?.();
onClose();
} }
title={ decodeEntities(
record.title.rendered || record.title.raw
) }
title={ decodedTitle }
/>
</>
) }
Expand Down

0 comments on commit 3ca6492

Please sign in to comment.