From 4187634c159fe530bb2afdd078043039a74c843d Mon Sep 17 00:00:00 2001 From: George Mamadashvili Date: Wed, 9 Aug 2023 08:00:16 +0400 Subject: [PATCH] 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 dec728b62bb61a..058dd1d054aed5 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; -}