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

Site Editor: Fix document actions label helper method #52974

Merged
merged 4 commits into from
Aug 9, 2023
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -33,8 +33,18 @@ 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() );
const isPage = useSelect(
( select ) => select( editSiteStore ).isPage(),
[]
);
Comment on lines +44 to +47
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated to the actual fix but a small code quality improvement.

return isPage ? <PageDocumentActions /> : <TemplateDocumentActions />;
}

Expand Down Expand Up @@ -118,8 +128,6 @@ function TemplateDocumentActions( { className, onBack } ) {
);
}

const entityLabel = getEntityLabel( record.type );

let typeIcon = icon;
if ( record.type === 'wp_navigation' ) {
typeIcon = navigationIcon;
Expand All @@ -137,11 +145,7 @@ function TemplateDocumentActions( { className, onBack } ) {
onBack={ onBack }
>
<VisuallyHidden as="span">
{ sprintf(
/* translators: %s: the entity being edited, like "template"*/
__( 'Editing %s: ' ),
entityLabel
) }
{ typeLabels[ record.type ] ?? typeLabels.wp_template }
</VisuallyHidden>
{ getTitle() }
</BaseDocumentActions>
Expand Down Expand Up @@ -187,20 +191,3 @@ function BaseDocumentActions( { className, icon, children, onBack } ) {
</div>
);
}

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;
}
4 changes: 2 additions & 2 deletions test/e2e/specs/site-editor/title.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' );
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there's no need for space here. a11y tree renders text correctly, and I re-tested with VoiceOver, which also reads it correctly.

} );

test( 'displays the selected template name in the title for the header template', async ( {
Expand All @@ -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' );
} );
} );
Loading