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

Add context to the "Reset template" "Delete template" and "Edit template" commands #52989

Merged
merged 3 commits into from
Aug 2, 2023
Merged
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
39 changes: 31 additions & 8 deletions packages/edit-site/src/hooks/commands/use-edit-mode-commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
* WordPress dependencies
*/
import { useSelect, useDispatch } from '@wordpress/data';
import { __, isRTL } from '@wordpress/i18n';
import { __, sprintf, isRTL } from '@wordpress/i18n';
import {
trash,
backup,
rotateLeft,
rotateRight,
layout,
page,
drawerLeft,
Expand All @@ -16,6 +17,7 @@ import {
keyboardClose,
} from '@wordpress/icons';
import { useCommandLoader } from '@wordpress/commands';
import { decodeEntities } from '@wordpress/html-entities';
import { privateApis as routerPrivateApis } from '@wordpress/router';
import { store as preferencesStore } from '@wordpress/preferences';
import { store as interfaceStore } from '@wordpress/interface';
Expand All @@ -35,6 +37,7 @@ import { unlock } from '../../lock-unlock';
const { useHistory } = unlock( routerPrivateApis );

function usePageContentFocusCommands() {
const { record: template } = useEditedEntityRecord();
const { isPage, canvasMode, hasPageContentFocus } = useSelect(
( select ) => ( {
isPage: select( editSiteStore ).isPage(),
Expand All @@ -54,7 +57,11 @@ function usePageContentFocusCommands() {
if ( hasPageContentFocus ) {
commands.push( {
name: 'core/switch-to-template-focus',
label: __( 'Edit template' ),
/* translators: %1$s: template title */
label: sprintf(
'Edit template: %s',
decodeEntities( template.title )
),
icon: layout,
callback: ( { close } ) => {
setHasPageContentFocus( false );
Expand Down Expand Up @@ -94,12 +101,20 @@ function useManipulateDocumentCommands() {
if ( isTemplateRevertable( template ) && ! hasPageContentFocus ) {
const label =
template.type === 'wp_template'
? __( 'Reset template' )
: __( 'Reset template part' );
? /* translators: %1$s: template title */
sprintf(
'Reset template: %s',
decodeEntities( template.title )
)
: /* translators: %1$s: template part title */
sprintf(
'Reset template part: %s',
decodeEntities( template.title )
);
commands.push( {
name: 'core/reset-template',
label,
icon: backup,
icon: isRTL() ? rotateRight : rotateLeft,
callback: ( { close } ) => {
revertTemplate( template );
close();
Expand All @@ -110,8 +125,16 @@ function useManipulateDocumentCommands() {
if ( isTemplateRemovable( template ) && ! hasPageContentFocus ) {
const label =
template.type === 'wp_template'
? __( 'Delete template' )
: __( 'Delete template part' );
? /* translators: %1$s: template title */
sprintf(
'Delete template: %s',
decodeEntities( template.title )
)
: /* translators: %1$s: template part title */
sprintf(
'Delete template part: %s',
decodeEntities( template.title )
);
const path =
template.type === 'wp_template'
? '/wp_template'
Expand Down
Loading