Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Template parts: use the template actions component for template parts patterns #54173

Merged
merged 3 commits into from
Sep 8, 2023
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 @@ -16,11 +16,14 @@ import useInitEditedEntityFromURL from '../sync-state-with-url/use-init-edited-e
import usePatternDetails from './use-pattern-details';
import { store as editSiteStore } from '../../store';
import { unlock } from '../../lock-unlock';
import TemplateActions from '../template-actions';

export default function SidebarNavigationScreenPattern() {
const { params } = useNavigator();
const navigator = useNavigator();
const {
params: { postType, postId },
} = navigator;
const { categoryType } = getQueryArgs( window.location.href );
const { postType, postId } = params;
const { setCanvasMode } = unlock( useDispatch( editSiteStore ) );

useInitEditedEntityFromURL();
Expand All @@ -38,11 +41,21 @@ export default function SidebarNavigationScreenPattern() {
return (
<SidebarNavigationScreen
actions={
<SidebarButton
onClick={ () => setCanvasMode( 'edit' ) }
label={ __( 'Edit' ) }
icon={ pencil }
/>
<>
<TemplateActions
postType={ postType }
postId={ postId }
toggleProps={ { as: SidebarButton } }
onRemove={ () => {
navigator.goTo( backPath );
} }
/>
<SidebarButton
onClick={ () => setCanvasMode( 'edit' ) }
label={ __( 'Edit' ) }
icon={ pencil }
/>
</>
}
backPath={ backPath }
{ ...patternDetails }
Expand Down
14 changes: 7 additions & 7 deletions packages/edit-site/src/components/template-actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export default function TemplateActions( {
onRemove?.();
onClose();
} }
isTemplate={ template.type === 'wp_template' }
title={ template.title.rendered }
/>
</>
) }
Expand All @@ -120,7 +120,7 @@ export default function TemplateActions( {
);
}

function DeleteMenuItem( { onRemove, isTemplate } ) {
function DeleteMenuItem( { onRemove, title } ) {
const [ isModalOpen, setIsModalOpen ] = useState( false );
return (
<>
Expand All @@ -133,11 +133,11 @@ function DeleteMenuItem( { onRemove, isTemplate } ) {
onCancel={ () => setIsModalOpen( false ) }
confirmButtonText={ __( 'Delete' ) }
>
{ isTemplate
? __( 'Are you sure you want to delete this template?' )
: __(
'Are you sure you want to delete this template part?'
) }
{ sprintf(
// translators: %s: The template or template part's title.
__( 'Are you sure you want to delete "%s"?' ),
decodeEntities( title )
) }
</ConfirmDialog>
</>
);
Expand Down