Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Editor: Revert bulk editing support for post actions #69341

Merged
merged 1 commit into from
Feb 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading