Skip to content

Commit

Permalink
Navigation List View: Add block movers to the more menu (#48099)
Browse files Browse the repository at this point in the history
* Navigation List View: Add block movers to the more menu

* add arrows

* put the remove action in its own group
  • Loading branch information
scruffian committed Feb 16, 2023
1 parent d8121e6 commit 11525f7
Showing 1 changed file with 52 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@
* WordPress dependencies
*/
import { createBlock } from '@wordpress/blocks';
import { addSubmenu, moreVertical } from '@wordpress/icons';
import {
addSubmenu,
chevronUp,
chevronDown,
moreVertical,
} from '@wordpress/icons';
import { DropdownMenu, MenuItem, MenuGroup } from '@wordpress/components';
import { useDispatch } from '@wordpress/data';
import { useDispatch, useSelect } from '@wordpress/data';
import { __, sprintf } from '@wordpress/i18n';

/**
Expand Down Expand Up @@ -80,14 +85,24 @@ function AddSubmenuItem( { block, onClose } ) {
export default function LeafMoreMenu( props ) {
const { clientId, block } = props;

const { removeBlocks } = useDispatch( blockEditorStore );
const { moveBlocksDown, moveBlocksUp, removeBlocks } =
useDispatch( blockEditorStore );

const label = sprintf(
const removeLabel = sprintf(
/* translators: %s: block name */
__( 'Remove %s' ),
BlockTitle( { clientId, maximumLength: 25 } )
);

const rootClientId = useSelect(
( select ) => {
const { getBlockRootClientId } = select( blockEditorStore );

return getBlockRootClientId( clientId );
},
[ clientId ]
);

return (
<DropdownMenu
icon={ moreVertical }
Expand All @@ -98,17 +113,39 @@ export default function LeafMoreMenu( props ) {
{ ...props }
>
{ ( { onClose } ) => (
<MenuGroup>
<AddSubmenuItem block={ block } onClose={ onClose } />
<MenuItem
onClick={ () => {
removeBlocks( [ clientId ], false );
onClose();
} }
>
{ label }
</MenuItem>
</MenuGroup>
<>
<MenuGroup>
<MenuItem
icon={ chevronUp }
onClick={ () => {
moveBlocksUp( [ clientId ], rootClientId );
onClose();
} }
>
{ __( 'Move up' ) }
</MenuItem>
<MenuItem
icon={ chevronDown }
onClick={ () => {
moveBlocksDown( [ clientId ], rootClientId );
onClose();
} }
>
{ __( 'Move down' ) }
</MenuItem>
<AddSubmenuItem block={ block } onClose={ onClose } />
</MenuGroup>
<MenuGroup>
<MenuItem
onClick={ () => {
removeBlocks( [ clientId ], false );
onClose();
} }
>
{ removeLabel }
</MenuItem>
</MenuGroup>
</>
) }
</DropdownMenu>
);
Expand Down

1 comment on commit 11525f7

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in 11525f7.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/4193416155
📝 Reported issues:

Please sign in to comment.