Skip to content

Commit

Permalink
Editor: Revert bulk editing support for post actions (#69341)
Browse files Browse the repository at this point in the history
Co-authored-by: Mamaduka <[email protected]>
Co-authored-by: t-hamano <[email protected]>
  • Loading branch information
3 people authored Feb 27, 2025
1 parent d8de061 commit 079996b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 42 deletions.
56 changes: 19 additions & 37 deletions packages/editor/src/components/post-actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<>
Expand All @@ -90,15 +72,15 @@ export default function PostActions( { postType, postId, onActionPerformed } ) {
<Menu.Popover>
<ActionsDropdownMenuGroup
actions={ actions }
items={ itemsWithPermissions }
items={ [ itemWithPermissions ] }
setActiveModalAction={ setActiveModalAction }
/>
</Menu.Popover>
</Menu>
{ !! activeModalAction && (
<ActionModal
action={ activeModalAction }
items={ itemsWithPermissions }
items={ [ itemWithPermissions ] }
closeModal={ () => setActiveModalAction( null ) }
/>
) }
Expand Down
12 changes: 7 additions & 5 deletions packages/editor/src/components/post-card-panel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,13 @@ export default function PostCardPanel( {
<Badge>{ pageTypeBadge }</Badge>
) }
</Text>
<PostActions
postType={ postType }
postId={ postId }
onActionPerformed={ onActionPerformed }
/>
{ postIds.length === 1 && (
<PostActions
postType={ postType }
postId={ postIds[ 0 ] }
onActionPerformed={ onActionPerformed }
/>
) }
</HStack>
{ postIds.length > 1 && (
<Text className="editor-post-card-panel__description">
Expand Down

0 comments on commit 079996b

Please sign in to comment.