From de578ad3ce3e94a4d58582f41fef35d5ae08e353 Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Tue, 8 Aug 2023 12:14:52 +0100 Subject: [PATCH] Revert all changes from https://github.com/WordPress/gutenberg/pull/52338 (#53419) --- .../index.js | 7 +++---- .../sidebar-navigation-screen-page/index.js | 6 +++--- .../sidebar-navigation-screen-pattern/index.js | 7 ++----- .../use-pattern-details.js | 3 --- .../use-init-edited-entity-from-url.js | 10 ++-------- .../src/components/use-edited-entity-record/index.js | 7 +------ packages/edit-site/src/utils/normalize-record-key.js | 11 ----------- 7 files changed, 11 insertions(+), 40 deletions(-) delete mode 100644 packages/edit-site/src/utils/normalize-record-key.js diff --git a/packages/edit-site/src/components/sidebar-navigation-screen-navigation-menu/index.js b/packages/edit-site/src/components/sidebar-navigation-screen-navigation-menu/index.js index 562b18def4fcfb..5ae860d4bb8298 100644 --- a/packages/edit-site/src/components/sidebar-navigation-screen-navigation-menu/index.js +++ b/packages/edit-site/src/components/sidebar-navigation-screen-navigation-menu/index.js @@ -22,10 +22,9 @@ import buildNavigationLabel from '../sidebar-navigation-screen-navigation-menus/ export const postType = `wp_navigation`; export default function SidebarNavigationScreenNavigationMenu() { - const { params } = useNavigator(); - - // See https://github.com/WordPress/gutenberg/pull/52120. - const postId = Number( params?.postId ); + const { + params: { postId }, + } = useNavigator(); const { record: navigationMenu, isResolving } = useEntityRecord( 'postType', diff --git a/packages/edit-site/src/components/sidebar-navigation-screen-page/index.js b/packages/edit-site/src/components/sidebar-navigation-screen-page/index.js index cd5869cfceb8fb..c5799d97a80645 100644 --- a/packages/edit-site/src/components/sidebar-navigation-screen-page/index.js +++ b/packages/edit-site/src/components/sidebar-navigation-screen-page/index.js @@ -30,9 +30,9 @@ import SidebarNavigationScreenDetailsFooter from '../sidebar-navigation-screen-d export default function SidebarNavigationScreenPage() { const navigator = useNavigator(); const { setCanvasMode } = unlock( useDispatch( editSiteStore ) ); - const { params } = useNavigator(); - - const postId = Number( params?.postId ); + const { + params: { postId }, + } = useNavigator(); const { record } = useEntityRecord( 'postType', 'page', postId ); const { featuredMediaAltText, featuredMediaSourceUrl } = useSelect( diff --git a/packages/edit-site/src/components/sidebar-navigation-screen-pattern/index.js b/packages/edit-site/src/components/sidebar-navigation-screen-pattern/index.js index 5815c4818fe9b0..39f28dba6d5204 100644 --- a/packages/edit-site/src/components/sidebar-navigation-screen-pattern/index.js +++ b/packages/edit-site/src/components/sidebar-navigation-screen-pattern/index.js @@ -16,16 +16,13 @@ import useInitEditedEntityFromURL from '../sync-state-with-url/use-init-edited-e import usePatternDetails from './use-pattern-details'; import { store as editSiteStore } from '../../store'; import { unlock } from '../../lock-unlock'; -import normalizeRecordKey from '../../utils/normalize-record-key'; export default function SidebarNavigationScreenPattern() { + const { params } = useNavigator(); const { categoryType } = getQueryArgs( window.location.href ); + const { postType, postId } = params; const { setCanvasMode } = unlock( useDispatch( editSiteStore ) ); - const { params } = useNavigator(); - const { postType } = params; - const postId = normalizeRecordKey( params?.postId ); - useInitEditedEntityFromURL(); const patternDetails = usePatternDetails( postType, postId ); diff --git a/packages/edit-site/src/components/sidebar-navigation-screen-pattern/use-pattern-details.js b/packages/edit-site/src/components/sidebar-navigation-screen-pattern/use-pattern-details.js index 5aed89955ba4fc..60fbb7161d160e 100644 --- a/packages/edit-site/src/components/sidebar-navigation-screen-pattern/use-pattern-details.js +++ b/packages/edit-site/src/components/sidebar-navigation-screen-pattern/use-pattern-details.js @@ -24,11 +24,8 @@ import { SidebarNavigationScreenDetailsPanelLabel, SidebarNavigationScreenDetailsPanelValue, } from '../sidebar-navigation-screen-details-panel'; -import normalizeRecordKey from '../../utils/normalize-record-key'; export default function usePatternDetails( postType, postId ) { - postId = normalizeRecordKey( postId ); - const { getDescription, getTitle, record } = useEditedEntityRecord( postType, postId diff --git a/packages/edit-site/src/components/sync-state-with-url/use-init-edited-entity-from-url.js b/packages/edit-site/src/components/sync-state-with-url/use-init-edited-entity-from-url.js index dee20963cfc60c..19518f650c0be3 100644 --- a/packages/edit-site/src/components/sync-state-with-url/use-init-edited-entity-from-url.js +++ b/packages/edit-site/src/components/sync-state-with-url/use-init-edited-entity-from-url.js @@ -11,17 +11,11 @@ import { privateApis as routerPrivateApis } from '@wordpress/router'; */ import { store as editSiteStore } from '../../store'; import { unlock } from '../../lock-unlock'; -import normalizeRecordKey from '../../utils/normalize-record-key'; const { useLocation } = unlock( routerPrivateApis ); export default function useInitEditedEntityFromURL() { - const { params } = useLocation(); - - const { postType } = params; - - const postId = normalizeRecordKey( params?.postId ); - + const { params: { postId, postType } = {} } = useLocation(); const { isRequestingSite, homepageId, url } = useSelect( ( select ) => { const { getSite, getUnstableBase } = select( coreDataStore ); const siteData = getSite(); @@ -72,7 +66,7 @@ export default function useInitEditedEntityFromURL() { // In all other cases, we need to set the home page in the site editor view. if ( homepageId ) { setPage( { - context: { postType: 'page', postId: Number( homepageId ) }, + context: { postType: 'page', postId: homepageId }, } ); } else if ( ! isRequestingSite ) { setPage( { diff --git a/packages/edit-site/src/components/use-edited-entity-record/index.js b/packages/edit-site/src/components/use-edited-entity-record/index.js index 30d1429ff92472..22a8bdc32a94a0 100644 --- a/packages/edit-site/src/components/use-edited-entity-record/index.js +++ b/packages/edit-site/src/components/use-edited-entity-record/index.js @@ -10,7 +10,6 @@ import { decodeEntities } from '@wordpress/html-entities'; * Internal dependencies */ import { store as editSiteStore } from '../../store'; -import normalizeRecordKey from '../../utils/normalize-record-key'; export default function useEditedEntityRecord( postType, postId ) { const { record, title, description, isLoaded, icon } = useSelect( @@ -22,11 +21,7 @@ export default function useEditedEntityRecord( postType, postId ) { const { __experimentalGetTemplateInfo: getTemplateInfo } = select( editorStore ); const usedPostType = postType ?? getEditedPostType(); - - let usedPostId = postId ?? getEditedPostId(); - - usedPostId = normalizeRecordKey( usedPostId, usedPostType ); - + const usedPostId = postId ?? getEditedPostId(); const _record = getEditedEntityRecord( 'postType', usedPostType, diff --git a/packages/edit-site/src/utils/normalize-record-key.js b/packages/edit-site/src/utils/normalize-record-key.js deleted file mode 100644 index 48036656c8a646..00000000000000 --- a/packages/edit-site/src/utils/normalize-record-key.js +++ /dev/null @@ -1,11 +0,0 @@ -function isNumericID( str ) { - return /^\s*\d+\s*$/.test( str ); -} - -export default function normalizeRecordKey( postId ) { - if ( isNumericID( postId ) ) { - postId = Number( postId ); - } - - return postId; -}