From 847d3e9f2336582daebc74c8b3a4de8590a2eac3 Mon Sep 17 00:00:00 2001 From: George Mamadashvili Date: Wed, 26 Jul 2023 14:23:09 +0400 Subject: [PATCH 1/4] Site Editor: Fix document actions label helper method --- .../document-actions/index.js | 32 ++++++------------- 1 file changed, 10 insertions(+), 22 deletions(-) diff --git a/packages/edit-site/src/components/header-edit-mode/document-actions/index.js b/packages/edit-site/src/components/header-edit-mode/document-actions/index.js index 049cdf4c40109..119d0d366028f 100644 --- a/packages/edit-site/src/components/header-edit-mode/document-actions/index.js +++ b/packages/edit-site/src/components/header-edit-mode/document-actions/index.js @@ -6,7 +6,7 @@ import classnames from 'classnames'; /** * WordPress dependencies */ -import { sprintf, __, isRTL } from '@wordpress/i18n'; +import { __, isRTL } from '@wordpress/i18n'; import { useSelect, useDispatch } from '@wordpress/data'; import { Button, @@ -118,8 +118,6 @@ function TemplateDocumentActions( { className, onBack } ) { ); } - const entityLabel = getEntityLabel( record.type ); - let typeIcon = icon; if ( record.type === 'wp_navigation' ) { typeIcon = navigationIcon; @@ -137,11 +135,7 @@ function TemplateDocumentActions( { className, onBack } ) { onBack={ onBack } > - { sprintf( - /* translators: %s: the entity being edited, like "template"*/ - __( 'Editing %s: ' ), - entityLabel - ) } + { getEntityLabel( record.type ) } { getTitle() } @@ -189,18 +183,12 @@ function BaseDocumentActions( { className, icon, children, onBack } ) { } function getEntityLabel( entityType ) { - let label = ''; - switch ( entityType ) { - case 'wp_navigation': - label = 'navigation menu'; - break; - case 'wp_template_part': - label = 'template part'; - break; - default: - label = 'template'; - break; - } - - return label; + const labels = { + wp_block: __( 'Editing pattern:' ), + wp_navigation: __( 'Editing navigation menu:' ), + wp_template: __( 'Editing template:' ), + wp_template_part: __( 'Editing template part:' ), + }; + + return labels[ entityType ] ?? labels.wp_template; } From 53b87a28c750bce38f9f6fa8753fba6da0ab6de9 Mon Sep 17 00:00:00 2001 From: George Mamadashvili Date: Wed, 26 Jul 2023 14:23:45 +0400 Subject: [PATCH 2/4] Add missing useSelect dep --- .../components/header-edit-mode/document-actions/index.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/edit-site/src/components/header-edit-mode/document-actions/index.js b/packages/edit-site/src/components/header-edit-mode/document-actions/index.js index 119d0d366028f..dec728b62bb61 100644 --- a/packages/edit-site/src/components/header-edit-mode/document-actions/index.js +++ b/packages/edit-site/src/components/header-edit-mode/document-actions/index.js @@ -34,7 +34,10 @@ import useEditedEntityRecord from '../../use-edited-entity-record'; import { store as editSiteStore } from '../../../store'; export default function DocumentActions() { - const isPage = useSelect( ( select ) => select( editSiteStore ).isPage() ); + const isPage = useSelect( + ( select ) => select( editSiteStore ).isPage(), + [] + ); return isPage ? : ; } From 2697402ddc4ac988a5d4ae3b74d6ab5d869b1a04 Mon Sep 17 00:00:00 2001 From: George Mamadashvili Date: Wed, 26 Jul 2023 15:05:50 +0400 Subject: [PATCH 3/4] Fix e2e tests --- test/e2e/specs/site-editor/title.spec.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/e2e/specs/site-editor/title.spec.js b/test/e2e/specs/site-editor/title.spec.js index 21cfc54482970..aa2942670c5a8 100644 --- a/test/e2e/specs/site-editor/title.spec.js +++ b/test/e2e/specs/site-editor/title.spec.js @@ -26,7 +26,7 @@ test.describe( 'Site editor title', () => { 'role=region[name="Editor top bar"i] >> role=heading[level=1]' ); - await expect( title ).toHaveText( 'Editing template: Index' ); + await expect( title ).toHaveText( 'Editing template:Index' ); } ); test( 'displays the selected template name in the title for the header template', async ( { @@ -43,6 +43,6 @@ test.describe( 'Site editor title', () => { 'role=region[name="Editor top bar"i] >> role=heading[level=1]' ); - await expect( title ).toHaveText( 'Editing template part: header' ); + await expect( title ).toHaveText( 'Editing template part:header' ); } ); } ); From 4187634c159fe530bb2afdd078043039a74c843d Mon Sep 17 00:00:00 2001 From: George Mamadashvili Date: Wed, 9 Aug 2023 08:00:16 +0400 Subject: [PATCH 4/4] Move the label map at the file level to avoid recreating the object on every render --- .../document-actions/index.js | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/packages/edit-site/src/components/header-edit-mode/document-actions/index.js b/packages/edit-site/src/components/header-edit-mode/document-actions/index.js index dec728b62bb61..058dd1d054aed 100644 --- a/packages/edit-site/src/components/header-edit-mode/document-actions/index.js +++ b/packages/edit-site/src/components/header-edit-mode/document-actions/index.js @@ -33,6 +33,13 @@ import { store as coreStore } from '@wordpress/core-data'; import useEditedEntityRecord from '../../use-edited-entity-record'; import { store as editSiteStore } from '../../../store'; +const typeLabels = { + wp_block: __( 'Editing pattern:' ), + wp_navigation: __( 'Editing navigation menu:' ), + wp_template: __( 'Editing template:' ), + wp_template_part: __( 'Editing template part:' ), +}; + export default function DocumentActions() { const isPage = useSelect( ( select ) => select( editSiteStore ).isPage(), @@ -138,7 +145,7 @@ function TemplateDocumentActions( { className, onBack } ) { onBack={ onBack } > - { getEntityLabel( record.type ) } + { typeLabels[ record.type ] ?? typeLabels.wp_template } { getTitle() } @@ -184,14 +191,3 @@ function BaseDocumentActions( { className, icon, children, onBack } ) { ); } - -function getEntityLabel( entityType ) { - const labels = { - wp_block: __( 'Editing pattern:' ), - wp_navigation: __( 'Editing navigation menu:' ), - wp_template: __( 'Editing template:' ), - wp_template_part: __( 'Editing template part:' ), - }; - - return labels[ entityType ] ?? labels.wp_template; -}