-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Conversation
fromIndex: index, | ||
rootClientId, | ||
clientId, | ||
layout, |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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
.
- if it is drop into one of its dropzones - if it is drop into one of its descendant blocks' dropzones
19a3421
to
b53d8c6
Compare
// so we also need to account for that case separately. | ||
return ( srcRoot === dstRoot ) || ( ! srcRoot === true && ! dstRoot === true ); | ||
}; | ||
const isSameBlock = ( src, dst ) => src === dst; |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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 ) ) { |
There was a problem hiding this comment.
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 ) => { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this 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).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
Fixes #9823, #10202 and #9303.
Testing