Skip to content

Commit

Permalink
Update/multi block mover (#5864)
Browse files Browse the repository at this point in the history
* Update block-mover sources for isFirst/isLast.

* Move logic to multi-controls.

* Calculate isFirst/isLast within connect.

* Linting.
  • Loading branch information
dom-o authored and aduth committed Mar 30, 2018
1 parent 161f3f0 commit d78163d
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions editor/components/block-list/multi-controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* External dependencies
*/
import { connect } from 'react-redux';
import { first, last } from 'lodash';

/**
* Internal dependencies
Expand All @@ -11,9 +12,11 @@ import BlockSettingsMenu from '../block-settings-menu';
import {
getMultiSelectedBlockUids,
isMultiSelecting,
getBlockIndex,
getBlockCount,
} from '../../store/selectors';

function BlockListMultiControls( { multiSelectedBlockUids, rootUID, isSelecting } ) {
function BlockListMultiControls( { multiSelectedBlockUids, rootUID, isSelecting, isFirst, isLast } ) {
if ( isSelecting ) {
return null;
}
Expand All @@ -23,6 +26,8 @@ function BlockListMultiControls( { multiSelectedBlockUids, rootUID, isSelecting
key="mover"
rootUID={ rootUID }
uids={ multiSelectedBlockUids }
isFirst={ isFirst }
isLast={ isLast }
/>,
<BlockSettingsMenu
key="menu"
Expand All @@ -33,9 +38,17 @@ function BlockListMultiControls( { multiSelectedBlockUids, rootUID, isSelecting
];
}

export default connect( ( state ) => {
export default connect( ( state, ownProps ) => {
const { rootUID } = ownProps;
const uids = getMultiSelectedBlockUids( state );

const firstIndex = getBlockIndex( state, first( uids ), rootUID );
const lastIndex = getBlockIndex( state, last( uids ), rootUID );

return {
multiSelectedBlockUids: getMultiSelectedBlockUids( state ),
multiSelectedBlockUids: uids,
isSelecting: isMultiSelecting( state ),
isFirst: firstIndex === 0,
isLast: lastIndex + 1 === getBlockCount( state ),
};
} )( BlockListMultiControls );

0 comments on commit d78163d

Please sign in to comment.