-
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
Drag & Drop: Fix unexpected row/gallery creation logic #64241
Conversation
Size Change: +81 B (0%) Total Size: 1.77 MB
ℹ️ View Unchanged
|
Flaky tests detected in 7856402. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/10241148533
|
if ( operation === 'replace' ) { | ||
replaceBlocks( clientId, blocks, undefined, initialPosition ); | ||
} else if ( operation === 'group' && areGroupableBlocks ) { |
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.
At this point, it is guaranteed that at least one of the Row block or Gallery block can be created, so areGroupableBlocks
is not necessary.
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.
Just double-checking, is that because this check is now happening in the throttle
'd function instead, prior to displaying the drop indicator and setting the drop target?
It looks like that other code also calls isGroupable
, too 👍. From memory the other thing we needed to check was that the hovered over block can be removed, so as long as the check is happening somewhere that sounds good to me!
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.
Just double-checking, is that because this check is now happening in the "throttle"'d function instead, prior to displaying the drop indicator and setting the drop target?
Yes. If the areGroupableBlocks
check is present here, the gallery block will not be created when the following conditions are met:
- The Group block is unregistered
- he dragged blocks and the target block are all images
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.
Thanks for clarifying!
* @param {boolean} canInsertRow | ||
* @return {boolean} Whether Row block or Gallery can be created. | ||
*/ | ||
function canCreateRowOrGallery( |
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.
This process might not even need to be made into a function.
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.
"Either or" I think.
It doesn't abstract much and could be inline and just as neat. Unless it needs unit testing.
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.
Same. Since it's only used in one place, I'd lean slightly toward inlining unless it needs unit testing.
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 removed the function and inlined it here 👍
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
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 did a smoke test on trunk and this PR and things are working as you describe. Thanks for the PR!
In trunk, adding a button block to a vertical row of button completely smashed by browser 😅
I'm not an expert in this area, so it might be good to see if @andrewserong or @kevin940726 have time to run their eyes over it.
* @param {boolean} canInsertRow | ||
* @return {boolean} Whether Row block or Gallery can be created. | ||
*/ | ||
function canCreateRowOrGallery( |
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.
"Either or" I think.
It doesn't abstract much and could be inline and just as neat. Unless it needs unit testing.
} | ||
dropTargetPosition; | ||
|
||
// Checks if it is creatable either a Row variation or a Gallery block from |
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.
Just checking, so this condition checks if a Row (Group) block or a Gallery block can be created after drop?
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.
No, it checks if it can be created before the drop. This prevents unintended inserters from appearing.
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.
Nice work @t-hamano, this is testing great for me and I could reproduce each of the issues in trunk
and those cases behaved as expected with this PR applied 👍
✅ Dragging a Button to the side of the vertical Buttons block no longer shows the dropzone
✅ The dropzone is not displayed when dragging a paragraph and the Row variation is not registered
✅ The dropzone is not displayed when dragging a paragraph and the Group block is not registered
✅ The dropzone is not displayed when dragging an image onto another image and the Gallery block and Row variations are not registered
✅ The dropzone is not displayed when dragging an image onto another image and the Gallery block, Group block and Row variations are not registered
Smoke tested dragging and dropping in the post and site editors, and otherwise all appears to be working well for me.
LGTM! 🚀
Fixes #64227
What?
This PR prevents the unintended appearance of the dropzone (vertical inserter) for creating rows or galleries in certain scenarios.
Why?
We need to consider the following scenarios:
For example, if the Gallery block, Group block, and Row variation are not all registered, the dropzone itself should not be displayed.
How?
Check in advance whether the Row block or the Gallery block can be created. If there are no creatable blocks, the dropzone itself will not be displayed.
Testing Instructions
Test the following scenarios:
Default
Row variation is not registered
layout.type
asflex
appears to be created correctly, but the block name remains Group.Group block is not registered
Gallery block and Row variation are not registered
layout.type
asflex
appears to be created correctly, but the block name remains Group.Gallery block, Group block, and Row variations are not registered