diff --git a/packages/editor/src/components/post-actions/index.js b/packages/editor/src/components/post-actions/index.js index d6adf6c0721667..219fb19e5eb83b 100644 --- a/packages/editor/src/components/post-actions/index.js +++ b/packages/editor/src/components/post-actions/index.js @@ -20,57 +20,39 @@ import { usePostActions } from './actions'; const { Menu, kebabCase } = unlock( componentsPrivateApis ); -function useEditedEntityRecordsWithPermissions( postType, postIds ) { - const { items, permissions } = useSelect( +export default function PostActions( { postType, postId, onActionPerformed } ) { + const [ activeModalAction, setActiveModalAction ] = useState( null ); + + const { item, permissions } = useSelect( ( select ) => { const { getEditedEntityRecord, getEntityRecordPermissions } = unlock( select( coreStore ) ); return { - items: postIds.map( ( postId ) => - getEditedEntityRecord( 'postType', postType, postId ) - ), - permissions: postIds.map( ( postId ) => - getEntityRecordPermissions( 'postType', postType, postId ) + item: getEditedEntityRecord( 'postType', postType, postId ), + permissions: getEntityRecordPermissions( + 'postType', + postType, + postId ), }; }, - [ postIds, postType ] + [ postId, postType ] ); - - return useMemo( () => { - return items.map( ( item, index ) => ( { + const itemWithPermissions = useMemo( () => { + return { ...item, - permissions: permissions[ index ], - } ) ); - }, [ items, permissions ] ); -} - -export default function PostActions( { postType, postId, onActionPerformed } ) { - const [ activeModalAction, setActiveModalAction ] = useState( null ); - const _postIds = useMemo( () => { - if ( Array.isArray( postId ) ) { - return postId; - } - return postId ? [ postId ] : []; - }, [ postId ] ); - - const itemsWithPermissions = useEditedEntityRecordsWithPermissions( - postType, - _postIds - ); + permissions, + }; + }, [ item, permissions ] ); const allActions = usePostActions( { postType, onActionPerformed } ); const actions = useMemo( () => { return allActions.filter( ( action ) => { return ( - ( ! action.isEligible || - itemsWithPermissions.some( ( itemWithPermissions ) => - action.isEligible( itemWithPermissions ) - ) ) && - ( itemsWithPermissions.length < 2 || action.supportsBulk ) + ! action.isEligible || action.isEligible( itemWithPermissions ) ); } ); - }, [ allActions, itemsWithPermissions ] ); + }, [ allActions, itemWithPermissions ] ); return ( <> @@ -90,7 +72,7 @@ export default function PostActions( { postType, postId, onActionPerformed } ) { @@ -98,7 +80,7 @@ export default function PostActions( { postType, postId, onActionPerformed } ) { { !! activeModalAction && ( setActiveModalAction( null ) } /> ) } diff --git a/packages/editor/src/components/post-card-panel/index.js b/packages/editor/src/components/post-card-panel/index.js index 895545cb007f00..a2ed6f5adaad82 100644 --- a/packages/editor/src/components/post-card-panel/index.js +++ b/packages/editor/src/components/post-card-panel/index.js @@ -118,11 +118,13 @@ export default function PostCardPanel( { { pageTypeBadge } ) } - + { postIds.length === 1 && ( + + ) } { postIds.length > 1 && (