Skip to content

Commit

Permalink
Editor: Don't use selector shortcuts for the Site data (#64884)
Browse files Browse the repository at this point in the history
Co-authored-by: Mamaduka <[email protected]>
Co-authored-by: jsnajdr <[email protected]>
  • Loading branch information
3 people authored Aug 28, 2024
1 parent 49a3187 commit affacdb
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 45 deletions.
11 changes: 4 additions & 7 deletions packages/block-library/src/home-link/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,10 @@ import { useEffect } from '@wordpress/element';
const preventDefault = ( event ) => event.preventDefault();

export default function HomeEdit( { attributes, setAttributes, context } ) {
const { homeUrl } = useSelect( ( select ) => {
const {
getUnstableBase, // Site index.
} = select( coreStore );
return {
homeUrl: getUnstableBase()?.home,
};
const homeUrl = useSelect( ( select ) => {
// Site index.
return select( coreStore ).getEntityRecord( 'root', '__unstableBase' )
?.home;
}, [] );
const { __unstableMarkNextChangeAsNotPersistent } =
useDispatch( blockEditorStore );
Expand Down
5 changes: 3 additions & 2 deletions packages/edit-post/src/store/private-selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ export const getEditedPostTemplateId = createRegistrySelector(
type: postType,
slug,
} = select( editorStore ).getCurrentPost();
const { getSite, getEntityRecords, canUser } = select( coreStore );
const { getEntityRecord, getEntityRecords, canUser } =
select( coreStore );
const siteSettings = canUser( 'read', {
kind: 'root',
name: 'site',
} )
? getSite()
? getEntityRecord( 'root', 'site' )
: undefined;
// First check if the current page is set as the posts page.
const isPostsPage = +postId === siteSettings?.page_for_posts;
Expand Down
12 changes: 4 additions & 8 deletions packages/edit-site/src/components/add-new-template/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,10 @@ function NewTemplateModal( { onClose } ) {

const isMobile = useViewportMatch( 'medium', '<' );

const { homeUrl } = useSelect( ( select ) => {
const {
getUnstableBase, // Site index.
} = select( coreStore );

return {
homeUrl: getUnstableBase()?.home,
};
const homeUrl = useSelect( ( select ) => {
// Site index.
return select( coreStore ).getEntityRecord( 'root', '__unstableBase' )
?.home;
}, [] );

const TEMPLATE_SHORT_DESCRIPTIONS = {
Expand Down
18 changes: 6 additions & 12 deletions packages/edit-site/src/components/site-hub/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,12 @@ const SiteHub = memo(
const { dashboardLink, homeUrl, siteTitle } = useSelect( ( select ) => {
const { getSettings } = unlock( select( editSiteStore ) );

const {
getSite,
getUnstableBase, // Site index.
} = select( coreStore );
const _site = getSite();
const { getEntityRecord } = select( coreStore );
const _site = getEntityRecord( 'root', 'site' );
return {
dashboardLink:
getSettings().__experimentalDashboardLink || 'index.php',
homeUrl: getUnstableBase()?.home,
homeUrl: getEntityRecord( 'root', '__unstableBase' )?.home,
siteTitle:
! _site?.title && !! _site?.url
? filterURLForDisplay( _site?.url )
Expand Down Expand Up @@ -128,13 +125,10 @@ export const SiteHubMobile = memo(
const { navigate } = useContext( SidebarNavigationContext );

const { homeUrl, siteTitle } = useSelect( ( select ) => {
const {
getSite,
getUnstableBase, // Site index.
} = select( coreStore );
const _site = getSite();
const { getEntityRecord } = select( coreStore );
const _site = getEntityRecord( 'root', 'site' );
return {
homeUrl: getUnstableBase()?.home,
homeUrl: getEntityRecord( 'root', '__unstableBase' )?.home,
siteTitle:
! _site?.title && !! _site?.url
? filterURLForDisplay( _site?.url )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,9 @@ function useResolveEditedEntityAndContext( { postId, postType } ) {
url,
frontPageTemplateId,
} = useSelect( ( select ) => {
const { getSite, getUnstableBase, getEntityRecords } =
select( coreDataStore );
const siteData = getSite();
const base = getUnstableBase();
const { getEntityRecord, getEntityRecords } = select( coreDataStore );
const siteData = getEntityRecord( 'root', 'site' );
const base = getEntityRecord( 'root', '__unstableBase' );
const templates = getEntityRecords( 'postType', TEMPLATE_POST_TYPE, {
per_page: -1,
} );
Expand Down
8 changes: 3 additions & 5 deletions packages/edit-site/src/hooks/commands/use-common-commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,11 +287,9 @@ function useGlobalStylesOpenRevisionsCommands() {

export function useCommonCommands() {
const homeUrl = useSelect( ( select ) => {
const {
getUnstableBase, // Site index.
} = select( coreStore );

return getUnstableBase()?.home;
// Site index.
return select( coreStore ).getEntityRecord( 'root', '__unstableBase' )
?.home;
}, [] );

useCommand( {
Expand Down
9 changes: 5 additions & 4 deletions packages/editor/src/components/page-attributes/parent.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,11 @@ function PostParentToggle( { isOpen, onClick } ) {
}

export function ParentRow() {
const homeUrl = useSelect(
( select ) => select( coreStore ).getUnstableBase()?.home,
[]
);
const homeUrl = useSelect( ( select ) => {
// Site index.
return select( coreStore ).getEntityRecord( 'root', '__unstableBase' )
?.home;
}, [] );
// Use internal state instead of a ref to make sure that the component
// re-renders when the popover's anchor updates.
const [ popoverAnchor, setPopoverAnchor ] = useState( null );
Expand Down
4 changes: 2 additions & 2 deletions packages/editor/src/components/preview-dropdown/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ export default function PreviewDropdown( { forceIsAutosaveable, disabled } ) {
showIconLabels,
} = useSelect( ( select ) => {
const { getDeviceType, getCurrentPostType } = select( editorStore );
const { getUnstableBase, getPostType } = select( coreStore );
const { getEntityRecord, getPostType } = select( coreStore );
const { get } = select( preferencesStore );
const { __unstableGetEditorMode } = select( blockEditorStore );
const _currentPostType = getCurrentPostType();
return {
deviceType: getDeviceType(),
editorMode: __unstableGetEditorMode(),
homeUrl: getUnstableBase()?.home,
homeUrl: getEntityRecord( 'root', '__unstableBase' )?.home,
isTemplate: _currentPostType === 'wp_template',
isViewable: getPostType( _currentPostType )?.viewable ?? false,
showIconLabels: get( 'core', 'showIconLabels' ),
Expand Down
4 changes: 3 additions & 1 deletion packages/editor/src/store/private-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,9 @@ export const saveDirtyEntities =
{ kind: 'postType', name: 'wp_navigation' },
];
const saveNoticeId = 'site-editor-save-success';
const homeUrl = registry.select( coreStore ).getUnstableBase()?.home;
const homeUrl = registry
.select( coreStore )
.getEntityRecord( 'root', '__unstableBase' )?.home;
registry.dispatch( noticesStore ).removeNotice( saveNoticeId );
const entitiesToSave = dirtyEntityRecords.filter(
( { kind, name, key, property } ) => {
Expand Down

0 comments on commit affacdb

Please sign in to comment.