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

Fix calculation of new block index on drop #10201

Merged
merged 8 commits into from
Oct 4, 2018
Merged

Conversation

oandregal
Copy link
Member

@oandregal oandregal commented Sep 26, 2018

Fixes #9823, #10202 and #9303.

Testing

  • Drag any block and drop it at the place you want. Check that it behaves as expected.
  • Drag any block and drop it ot its own top/bottom zones (see).
  • Drag a columns block and drop it within one of its columns (see).
  • Drag a block and drop it in the top zone of any block below it (see).

@oandregal oandregal self-assigned this Sep 26, 2018
@oandregal oandregal added the [Feature] Drag and Drop Drag and drop functionality when working with blocks label Sep 26, 2018
fromIndex: index,
rootClientId,
clientId,
layout,
Copy link
Member Author

Choose a reason for hiding this comment

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

layout was unnecessary so I took advantage of this PR to clean that as well in c7af125

rootClientId,
clientId,
layout,
srcIndex: index,
Copy link
Member Author

Choose a reason for hiding this comment

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

Improve nomenclature, as it was inconsistent (fromIndex but not fromClientId?), especially when this data was used in the BlockDropZone.

@oandregal oandregal added this to the 4.0 milestone Sep 26, 2018
@oandregal oandregal added the [Type] Bug An existing feature does not function as intended label Sep 26, 2018
@oandregal oandregal force-pushed the fix/drop-move-calculation branch from 19a3421 to b53d8c6 Compare September 27, 2018 10:03
@oandregal oandregal requested a review from a team September 27, 2018 10:06
@oandregal oandregal added the [Priority] High Used to indicate top priority items that need quick attention label Sep 27, 2018
@oandregal oandregal changed the title Fix/drop move calculation Fix drop mechanism Sep 27, 2018
@oandregal oandregal changed the title Fix drop mechanism Fixes how the new position of the block is calculated on drop Sep 27, 2018
@oandregal oandregal changed the title Fixes how the new position of the block is calculated on drop Fix calculation of new block index on drop Sep 27, 2018
// so we also need to account for that case separately.
return ( srcRoot === dstRoot ) || ( ! srcRoot === true && ! dstRoot === true );
};
const isSameBlock = ( src, dst ) => src === dst;
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor: I feel extracting this to a separate function doesn't provide anything "useful" as it's just a === check. (nothing block related)

Copy link
Member Author

Choose a reason for hiding this comment

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

I know it seems straightforward code, but I like how having the function helps document the intent for the reader.

} catch ( err ) {
if ( ! isBlockDropType( type ) ||
isSameBlock( srcClientId, dstClientId ) ||
isSrcBlockAnAncestorOfDstBlock( srcClientId, dstClientId ) ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor: Could it be useful to extract the behavior of this function to something like getInsertIndex( src, dest ) to test it properly?

*
* @return {Array} ids of descendants.
*/
export const getDescendants = ( state, clientIds ) => flatMap( clientIds, ( clientId ) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel the name is not very explicit. Could it be getBlocksDescendantsClientIds or something in that vein?

Copy link
Member Author

Choose a reason for hiding this comment

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

Renamed it to getClientIdsOfDescendants in bebfdbd.

Copy link
Contributor

@youknowriad youknowriad left a comment

Choose a reason for hiding this comment

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

Tested and works properly, I'd appreciate if we can just change the name of getDescendants.

Also, it's important to run npm run docs:build to regenerate the new selector's docs (and commit the changes).

Copy link
Contributor

@youknowriad youknowriad left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@oandregal oandregal merged commit b6303f1 into master Oct 4, 2018
@oandregal oandregal deleted the fix/drop-move-calculation branch October 4, 2018 14:10
@oandregal oandregal mentioned this pull request Oct 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Drag and Drop Drag and drop functionality when working with blocks [Priority] High Used to indicate top priority items that need quick attention [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants