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: Append template type and name to the site editor page title #47855

Merged
merged 3 commits into from
Feb 9, 2023
Merged
Changes from 2 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
11 changes: 10 additions & 1 deletion packages/edit-site/src/components/editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,18 @@ export default function Editor() {
);
const isReady = editedPostType !== undefined && editedPostId !== undefined;

let titleBreadcrumb;
if ( isReady && editedPost ) {
const type =
editedPostType === 'wp_template'
? __( 'Template' )
: __( 'Template Part' );
titleBreadcrumb = `${ editedPost.title?.rendered } ‹ ${ type } ‹ `;
}
Copy link
Member

Choose a reason for hiding this comment

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

Nit: I think can just construct the title string here for simplicity (useMemo is probably not needed):

Suggested change
let titleBreadcrumb;
if ( isReady && editedPost ) {
const type =
editedPostType === 'wp_template'
? __( 'Template' )
: __( 'Template Part' );
titleBreadcrumb = `${ editedPost.title?.rendered }${ type } ‹ `;
}
const title = useMemo( () => {
const type =
editedPostType === 'wp_template'
? __( 'Template' )
: __( 'Template Part' );
return `${ editedPost.title?.rendered }${ type }${ __( 'Editor (beta)' ) }`
}, [ editedPost.title, editedPostType ] );

Then later we can just do:

useTitle( isReady && title );

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was thinking that there might be instances where editedPost was not set so title would then just need to be Editor (beta) but I did some more testing and this doesn't seem to ever be the case, so have simplified as you suggested, but without the useMemo - this isn't a calculation heavy bit of logic so I agree that this probably isn't needed.


// Only announce the title once the editor is ready to prevent "Replace"
// action in <URlQueryController> from double-announcing.
useTitle( isReady && __( 'Editor (beta)' ) );
useTitle( isReady && `${ titleBreadcrumb }${ __( 'Editor (beta)' ) }` );

if ( ! isReady ) {
return <CanvasSpinner />;
Expand Down