From 9e4ceb6906d4a0702f97c0b9ec223914f684c6ca Mon Sep 17 00:00:00 2001 From: Lourens Schep Date: Fri, 13 Dec 2024 12:59:10 +0100 Subject: [PATCH] Move getEntityConfig inside of other useSelect --- .../src/components/post-actions/index.js | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/packages/editor/src/components/post-actions/index.js b/packages/editor/src/components/post-actions/index.js index 784fd42b1b50a..deb621c9d058e 100644 --- a/packages/editor/src/components/post-actions/index.js +++ b/packages/editor/src/components/post-actions/index.js @@ -21,16 +21,19 @@ import { usePostActions } from './actions'; const { Menu, kebabCase } = unlock( componentsPrivateApis ); function useEditedEntityRecordsWithPermissions( postType, postIds ) { - const entityConfig = useSelect( - ( select ) => - select( coreStore ).getEntityConfig( 'postType', postType ), - [ postType ] - ); - const { items } = useSelect( + const { items, entityConfig } = useSelect( ( select ) => { + const { getEntityConfig } = select( coreStore ); const { getEditedEntityRecords } = unlock( select( coreStore ) ); + const entityRecords = getEditedEntityRecords( + 'postType', + postType, + postIds + ); + return { - items: getEditedEntityRecords( 'postType', postType, postIds ), + items: entityRecords, + entityConfig: getEntityConfig( 'postType', postType ), }; }, [ postIds, postType ] @@ -38,10 +41,8 @@ function useEditedEntityRecordsWithPermissions( postType, postIds ) { const ids = useMemo( () => - items?.map( - // @ts-ignore - ( record ) => record[ entityConfig?.key ?? 'id' ] - ) ?? [], + items?.map( ( record ) => record[ entityConfig?.key ?? 'id' ] ) ?? + [], [ items, entityConfig?.key ] ); @@ -59,7 +60,7 @@ function useEditedEntityRecordsWithPermissions( postType, postIds ) { return ( items?.map( ( item, index ) => ( { ...item, - permissions: permissions[ index ], + permissions: permissions ? permissions[ index ] : undefined, } ) ) ?? [] ); }, [ items, permissions ] );