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

Conversation

Projects
None yet
2 participants
@nosolosw
Member

nosolosw 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).

@nosolosw nosolosw self-assigned this Sep 26, 2018

fromIndex: index,
rootClientId,
clientId,
layout,

This comment has been minimized.

@nosolosw

nosolosw Sep 26, 2018

Member

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

@nosolosw

nosolosw Sep 26, 2018

Member

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

rootClientId,
clientId,
layout,
srcIndex: index,

This comment has been minimized.

@nosolosw

nosolosw Sep 26, 2018

Member

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

@nosolosw

nosolosw Sep 26, 2018

Member

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

@nosolosw nosolosw requested a review from WordPress/gutenberg-core Sep 27, 2018

@nosolosw nosolosw changed the title from Fix/drop move calculation to Fix drop mechanism Sep 27, 2018

@nosolosw nosolosw changed the title from Fix drop mechanism to Fixes how the new position of the block is calculated on drop Sep 27, 2018

@nosolosw nosolosw changed the title from Fixes how the new position of the block is calculated on drop to 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;

This comment has been minimized.

@youknowriad

youknowriad Oct 4, 2018

Contributor

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

@youknowriad

youknowriad Oct 4, 2018

Contributor

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

This comment has been minimized.

@nosolosw

nosolosw Oct 4, 2018

Member

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

@nosolosw

nosolosw Oct 4, 2018

Member

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 ) ) {

This comment has been minimized.

@youknowriad

youknowriad Oct 4, 2018

Contributor

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

@youknowriad

youknowriad Oct 4, 2018

Contributor

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

@youknowriad

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).

@youknowriad

LGTM 👍

@nosolosw nosolosw merged commit b6303f1 into master Oct 4, 2018

2 checks passed

codecov/project 49.38% (+0.57%) compared to 8300578
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details

@nosolosw nosolosw deleted the fix/drop-move-calculation branch Oct 4, 2018

@nosolosw nosolosw referenced this pull request Oct 4, 2018

Merged

Fix selector import #10330

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment