Skip to content

Commit

Permalink
Site Editor: tidy up the generation of the site editor page title (#4…
Browse files Browse the repository at this point in the history
…8053)

* Tidy up the generation of the edit site page title

* Remove isReady as doesn't seem to add anything above the isLoaded from useEditedEntityRecord
  • Loading branch information
glendaviesnz authored and ntsekouras committed Feb 14, 2023
1 parent 6191e20 commit da748bc
Showing 1 changed file with 21 additions and 31 deletions.
52 changes: 21 additions & 31 deletions packages/edit-site/src/components/editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { useMemo } from '@wordpress/element';
import { useSelect, useDispatch } from '@wordpress/data';
import { Notice } from '@wordpress/components';
import { EntityProvider, store as coreStore } from '@wordpress/core-data';
import { EntityProvider } from '@wordpress/core-data';
import { store as preferencesStore } from '@wordpress/preferences';
import {
BlockContextProvider,
Expand All @@ -17,7 +17,7 @@ import {
store as interfaceStore,
} from '@wordpress/interface';
import { EditorNotices, EditorSnackbars } from '@wordpress/editor';
import { __ } from '@wordpress/i18n';
import { __, sprintf } from '@wordpress/i18n';

/**
* Internal dependencies
Expand All @@ -35,6 +35,7 @@ import { GlobalStylesProvider } from '../global-styles/global-styles-provider';
import useTitle from '../routes/use-title';
import CanvasSpinner from '../canvas-spinner';
import { unlock } from '../../private-apis';
import useEditedEntityRecord from '../use-edited-entity-record';

const interfaceLabels = {
/* translators: accessibility text for the editor content landmark region. */
Expand All @@ -49,11 +50,15 @@ const interfaceLabels = {

export default function Editor() {
const {
editedPostId,
editedPostType,
editedPost,
record: editedPost,
getTitle,
isLoaded: hasLoadedPost,
} = useEditedEntityRecord();

const { id: editedPostId, type: editedPostType } = editedPost;

const {
context,
hasLoadedPost,
editorMode,
canvasMode,
blockEditorMode,
Expand All @@ -63,36 +68,19 @@ export default function Editor() {
showIconLabels,
} = useSelect( ( select ) => {
const {
getEditedPostType,
getEditedPostId,
getEditedPostContext,
getEditorMode,
getCanvasMode,
isInserterOpened,
isListViewOpened,
} = unlock( select( editSiteStore ) );
const { hasFinishedResolution, getEntityRecord } = select( coreStore );
const { __unstableGetEditorMode } = select( blockEditorStore );
const { getActiveComplementaryArea } = select( interfaceStore );
const postType = getEditedPostType();
const postId = getEditedPostId();

// The currently selected entity to display.
// Typically template or template part in the site editor.
return {
editedPostId: postId,
editedPostType: postType,
editedPost: postId
? getEntityRecord( 'postType', postType, postId )
: null,
context: getEditedPostContext(),
hasLoadedPost: postId
? hasFinishedResolution( 'getEntityRecord', [
'postType',
postType,
postId,
] )
: false,
editorMode: getEditorMode(),
canvasMode: getCanvasMode(),
blockEditorMode: __unstableGetEditorMode(),
Expand Down Expand Up @@ -134,26 +122,28 @@ export default function Editor() {
} ),
],
} ),
[ context ]
[ context, setEditedPostContext ]
);
const isReady = editedPostType !== undefined && editedPostId !== undefined;

let title;
if ( isReady && editedPost ) {
if ( hasLoadedPost ) {
const type =
editedPostType === 'wp_template'
? __( 'Template' )
: __( 'Template Part' );
title = `${ editedPost.title?.rendered }${ type }${ __(
'Editor (beta)'
) }`;
title = sprintf(
// translators: A breadcrumb trail in browser tab. %1$s: title of template being edited, %2$s: type of template (Template or Template Part).
__( '%1$s ‹ %2$s ‹ Editor' ),
getTitle(),
type
);
}

// Only announce the title once the editor is ready to prevent "Replace"
// action in <URlQueryController> from double-announcing.
useTitle( isReady && title );
useTitle( hasLoadedPost && title );

if ( ! isReady ) {
if ( ! hasLoadedPost ) {
return <CanvasSpinner />;
}

Expand Down

1 comment on commit da748bc

@github-actions
Copy link

Choose a reason for hiding this comment

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

Flaky tests detected in da748bc.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/4172367389
📝 Reported issues:

Please sign in to comment.