Skip to content

Commit

Permalink
Lodash: Refactor away from BlockActionsMenu (RN) (#43849)
Browse files Browse the repository at this point in the history
  • Loading branch information
tyxla authored Sep 5, 2022
1 parent 031fdb6 commit 35b0bd0
Showing 1 changed file with 15 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* External dependencies
*/
import { Platform, findNodeHandle } from 'react-native';
import { partial, first, castArray, last, every } from 'lodash';

/**
* WordPress dependencies
*/
Expand Down Expand Up @@ -307,21 +307,25 @@ export default compose(
canInsertBlockType,
getTemplateLock,
} = select( blockEditorStore );
const normalizedClientIds = castArray( clientIds );
const normalizedClientIds = Array.isArray( clientIds )
? clientIds
: [ clientIds ];
const block = getBlock( normalizedClientIds );
const blockName = getBlockName( normalizedClientIds );
const blockType = getBlockType( blockName );
const blockTitle = blockType?.title;
const firstClientId = first( normalizedClientIds );
const firstClientId = normalizedClientIds[ 0 ];
const rootClientId = getBlockRootClientId( firstClientId );
const blockOrder = getBlockOrder( rootClientId );

const firstIndex = getBlockIndex( firstClientId );
const lastIndex = getBlockIndex( last( normalizedClientIds ) );
const lastIndex = getBlockIndex(
normalizedClientIds[ normalizedClientIds.length - 1 ]
);

const innerBlocks = getBlocksByClientId( clientIds );

const canDuplicate = every( innerBlocks, ( innerBlock ) => {
const canDuplicate = innerBlocks.every( ( innerBlock ) => {
return (
!! innerBlock &&
hasBlockSupport( innerBlock.name, 'multiple', true ) &&
Expand All @@ -336,9 +340,9 @@ export default compose(
isExactlyOneBlock && isDefaultBlock && isEmptyContent;
const isLocked = !! getTemplateLock( rootClientId );

const selectedBlockClientId = first( getSelectedBlockClientIds() );
const selectedBlockClientId = getSelectedBlockClientIds()[ 0 ];
const selectedBlock = selectedBlockClientId
? first( getBlocksByClientId( selectedBlockClientId ) )
? getBlocksByClientId( selectedBlockClientId )[ 0 ]
: undefined;
const selectedBlockPossibleTransformations = selectedBlock
? getBlockTransformItems( [ selectedBlock ], rootClientId )
Expand Down Expand Up @@ -406,8 +410,10 @@ export default compose(
duplicateBlock() {
return duplicateBlocks( clientIds );
},
onMoveDown: partial( moveBlocksDown, clientIds, rootClientId ),
onMoveUp: partial( moveBlocksUp, clientIds, rootClientId ),
onMoveDown: ( ...args ) =>
moveBlocksDown( clientIds, rootClientId, ...args ),
onMoveUp: ( ...args ) =>
moveBlocksUp( clientIds, rootClientId, ...args ),
openGeneralSidebar: () =>
openGeneralSidebar( 'edit-post/block' ),
pasteBlock: ( clipboardBlock ) => {
Expand Down

0 comments on commit 35b0bd0

Please sign in to comment.