Skip to content

Commit

Permalink
Move the label map at the file level to avoid recreating the object o…
Browse files Browse the repository at this point in the history
…n every render
  • Loading branch information
Mamaduka committed Aug 9, 2023
1 parent 2697402 commit 4187634
Showing 1 changed file with 8 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -138,7 +145,7 @@ function TemplateDocumentActions( { className, onBack } ) {
onBack={ onBack }
>
<VisuallyHidden as="span">
{ getEntityLabel( record.type ) }
{ typeLabels[ record.type ] ?? typeLabels.wp_template }
</VisuallyHidden>
{ getTitle() }
</BaseDocumentActions>
Expand Down Expand Up @@ -184,14 +191,3 @@ function BaseDocumentActions( { className, icon, children, onBack } ) {
</div>
);
}

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;
}

0 comments on commit 4187634

Please sign in to comment.