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: Remove useEditedEntityRecord hook #66955

Merged
merged 2 commits into from
Nov 13, 2024
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
7 changes: 5 additions & 2 deletions packages/edit-site/src/components/editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,15 @@ export default function EditSiteEditor( { isPostsList = false } ) {
hasSiteIcon: !! siteData?.site_icon_url,
};
}, [] );
useEditorTitle();
const postWithTemplate = !! contextPostId;
useEditorTitle(
postWithTemplate ? contextPostType : editedPostType,
postWithTemplate ? contextPostId : editedPostId
youknowriad marked this conversation as resolved.
Show resolved Hide resolved
);
const _isPreviewingTheme = isPreviewingTheme();
const hasDefaultEditorCanvasView = ! useHasEditorCanvasContainer();
const iframeProps = useEditorIframeProps();
const isEditMode = canvas === 'edit';
const postWithTemplate = !! contextPostId;
const loadingProgressId = useInstanceId(
CanvasLoader,
'edit-site-editor__loading-progress'
Expand Down
50 changes: 37 additions & 13 deletions packages/edit-site/src/components/editor/use-editor-title.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,58 @@
* WordPress dependencies
*/
import { _x, sprintf } from '@wordpress/i18n';
import { useSelect } from '@wordpress/data';
import { store as coreStore } from '@wordpress/core-data';
import { store as editorStore } from '@wordpress/editor';
import { decodeEntities } from '@wordpress/html-entities';

/**
* Internal dependencies
*/
import useEditedEntityRecord from '../use-edited-entity-record';
import useTitle from '../routes/use-title';
import { POST_TYPE_LABELS, TEMPLATE_POST_TYPE } from '../../utils/constants';

function useEditorTitle() {
const {
record: editedPost,
getTitle,
isLoaded: hasLoadedPost,
} = useEditedEntityRecord();
let title;
if ( hasLoadedPost ) {
title = sprintf(
function useEditorTitle( postType, postId ) {
const { title, isLoaded } = useSelect(
( select ) => {
const { getEditedEntityRecord, hasFinishedResolution } =
select( coreStore );
const { __experimentalGetTemplateInfo: getTemplateInfo } =
select( editorStore );
const _record = getEditedEntityRecord(
'postType',
postType,
postId
);
const _isLoaded = hasFinishedResolution( 'getEditedEntityRecord', [
'postType',
postType,
postId,
] );
const templateInfo = getTemplateInfo( _record );

return {
title: templateInfo.title,
isLoaded: _isLoaded,
};
},
[ postType, postId ]
);

let editorTitle;
if ( isLoaded ) {
editorTitle = sprintf(
// translators: A breadcrumb trail for the Admin document title. 1: title of template being edited, 2: type of template (Template or Template Part).
_x( '%1$s ‹ %2$s', 'breadcrumb trail' ),
getTitle(),
POST_TYPE_LABELS[ editedPost.type ] ??
decodeEntities( title ),
POST_TYPE_LABELS[ postType ] ??
POST_TYPE_LABELS[ TEMPLATE_POST_TYPE ]
);
}

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

export default useEditorTitle;

This file was deleted.

Loading