Try allowing transforms to a variation of another block#78713
Conversation
|
Size Change: +531 B (+0.01%) Total Size: 8.21 MB 📦 View Changed
ℹ️ View Unchanged
|
|
Flaky tests detected in cccbadf. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/26495672690
|
|
The idea makes sense to me, being able to transform directly to a variation is pretty useful. 👍 There are some bugs, but I guess this is not yet finalized:
|
This is what I was most unsure about, because I can't think of many other use cases apart from transforming blocks to Group variations for the layout benefits (which could be solved in other ways). That's why I tried the alternative approach in #78716. Do you think this approach is better than that one? |
|
I do prefer this one personally. The block types have a more defined purpose with this approach In the other PR, if column has a grid layout then it starts to become confusing about when a user might use a column grid vs. a regular grid. |
cccbadf to
a61f63e
Compare
I've fixed these now! |
|
Given Dan's happy with the direction and I've now double-checked the code, marking this ready for review. |
|
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. |
talldan
left a comment
There was a problem hiding this comment.
This tests well. I left a code quality comment, but it's up to you 😄
| if ( ! variationName ) { | ||
| return item; | ||
| } | ||
| const variation = getBlockVariations( item.name, 'transform' )?.find( | ||
| ( { name } ) => name === variationName | ||
| ); | ||
| if ( ! variation ) { | ||
| return item; | ||
| } |
There was a problem hiding this comment.
It works, but I think this function does more than it should and creates a bit of indirection. Most of the time it'll be returning item, the exact same value it was passed, so calling into it for that doesn't seem worthwhile
All the highlighted code could be moved to the call site (the reduce callback) so it ends up like this or similar:
if ( ! variationName ) {
accumulator.push( item );
}
// etc.
Then what's left in the function is just buildBlockVariationItem, which parallels nicely with the existing buildBlockTypeItem.
2ebaa4a to
a45d73e
Compare
5a67394 to
3bbe0f7
Compare
What?
Fixes #70355 while enabling transforms to variations of another block.
It looks like a big changeset but mostly revolves around adding a
variationNameparameter toswitchToBlockType. My main reservation is that this is only going to be useful for transforming blocks into specific Group variations, with the purpose of changing their layout type. I wonder whether that type of problem would be more easily solved by enabling different layouts on the original blocks.For testing purposes, I added a "transform to grid" to both Columns and Gallery blocks (there's a prior attempt to convert Gallery to a grid layout in #60022)
As an alternative, in #78716 I added a grid variation to the Columns block.
Testing Instructions
gallery-to-grid.mp4
Use of AI Tools
Mostly gpt 5.5/codexed