Skip to content

Commit

Permalink
Fix: Action order is different from inspector and dataviews. (#60877)
Browse files Browse the repository at this point in the history
Co-authored-by: jorgefilipecosta <jorgefilipecosta@git.wordpress.org>
Co-authored-by: jameskoster <jameskoster@git.wordpress.org>
  • Loading branch information
3 people authored Apr 18, 2024
1 parent b34daf3 commit d9f9653
Showing 1 changed file with 3 additions and 47 deletions.
50 changes: 3 additions & 47 deletions packages/editor/src/components/post-actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* WordPress dependencies
*/
import { useSelect } from '@wordpress/data';
import { useMemo, useState, Fragment, Children } from '@wordpress/element';
import { useState } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import {
privateApis as componentsPrivateApis,
Expand All @@ -28,7 +28,6 @@ const {
DropdownMenuGroupV2: DropdownMenuGroup,
DropdownMenuItemV2: DropdownMenuItem,
DropdownMenuItemLabelV2: DropdownMenuItemLabel,
DropdownMenuSeparatorV2: DropdownMenuSeparator,
kebabCase,
} = unlock( componentsPrivateApis );

Expand All @@ -52,22 +51,6 @@ export default function PostActions( { onActionPerformed, buttonProps } ) {
POST_ACTIONS_WHILE_EDITING
);

const { primaryActions, secondaryActions } = useMemo( () => {
return actions.reduce(
( accumulator, action ) => {
if ( action.isEligible && ! action.isEligible( item ) ) {
return accumulator;
}
if ( action.isPrimary ) {
accumulator.primaryActions.push( action );
} else {
accumulator.secondaryActions.push( action );
}
return accumulator;
},
{ primaryActions: [], secondaryActions: [] }
);
}, [ actions, item ] );
if (
[
TEMPLATE_POST_TYPE,
Expand All @@ -84,29 +67,14 @@ export default function PostActions( { onActionPerformed, buttonProps } ) {
size="small"
icon={ moreVertical }
label={ __( 'Actions' ) }
disabled={
! primaryActions.length && ! secondaryActions.length
}
disabled={ ! actions.length }
className="editor-all-actions-button"
{ ...buttonProps }
/>
}
placement="bottom-end"
>
<WithDropDownMenuSeparators>
{ !! primaryActions.length && (
<ActionsDropdownMenuGroup
actions={ primaryActions }
item={ item }
/>
) }
{ !! secondaryActions.length && (
<ActionsDropdownMenuGroup
actions={ secondaryActions }
item={ item }
/>
) }
</WithDropDownMenuSeparators>
<ActionsDropdownMenuGroup actions={ actions } item={ item } />
</DropdownMenu>
);
}
Expand Down Expand Up @@ -160,18 +128,6 @@ function ActionWithModal( { action, item, ActionTrigger } ) {
);
}

// Copied as is from packages/dataviews/src/view-table.js
function WithDropDownMenuSeparators( { children } ) {
return Children.toArray( children )
.filter( Boolean )
.map( ( child, i ) => (
<Fragment key={ i }>
{ i > 0 && <DropdownMenuSeparator /> }
{ child }
</Fragment>
) );
}

// Copied as is from packages/dataviews/src/item-actions.js
function ActionsDropdownMenuGroup( { actions, item } ) {
return (
Expand Down

0 comments on commit d9f9653

Please sign in to comment.