Skip to content

Commit

Permalink
Move getEntityConfig inside of other useSelect
Browse files Browse the repository at this point in the history
  • Loading branch information
louwie17 committed Dec 13, 2024
1 parent e4cd460 commit 9e4ceb6
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions packages/editor/src/components/post-actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,28 @@ 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 ]
);

const ids = useMemo(
() =>
items?.map(
// @ts-ignore
( record ) => record[ entityConfig?.key ?? 'id' ]
) ?? [],
items?.map( ( record ) => record[ entityConfig?.key ?? 'id' ] ) ??
[],
[ items, entityConfig?.key ]
);

Expand All @@ -59,7 +60,7 @@ function useEditedEntityRecordsWithPermissions( postType, postIds ) {
return (
items?.map( ( item, index ) => ( {
...item,
permissions: permissions[ index ],
permissions: permissions ? permissions[ index ] : undefined,
} ) ) ?? []
);
}, [ items, permissions ] );
Expand Down

0 comments on commit 9e4ceb6

Please sign in to comment.