Skip to content

Commit

Permalink
Add context to the "Reset template" "Delete template" and "Edit templ…
Browse files Browse the repository at this point in the history
…ate" commands (#52989)

* Add context to the "Reset template" and "Edit template" commands

* update delete labels and change to emdash

* update to use `:` and rtl icon
  • Loading branch information
ntsekouras authored Aug 2, 2023
1 parent b340afd commit 67154dc
Showing 1 changed file with 31 additions and 8 deletions.
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 {
keyboard,
} 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

0 comments on commit 67154dc

Please sign in to comment.