-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Add contentRole to Query block and make sure Change design always works as expected #71686
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
Conversation
|
Flaky tests detected in 2a11acc. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/17785068630
|
7394b6c to
2e9cf6a
Compare
|
Size Change: +34 B (0%) Total Size: 1.94 MB
ℹ️ View Unchanged
|
|
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. |
ramonjd
left a comment
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 agree with your statement over in #67763 (comment)
contentOnly does mitigate the problem somewhat so maybe we can do that first and then iterate further.
| const allPatterns = usePatterns( clientId, blockNameForPatterns ); | ||
| // Filter out any patterns that don't have Query as their root block | ||
| // so that a Query block is always replaced by another Query block. | ||
| const rootBlockPatterns = useMemo( () => { | ||
| return allPatterns.filter( ( pattern ) => { | ||
| return pattern.blocks?.[ 0 ]?.name === blockNameForPatterns; | ||
| } ); | ||
| }, [ allPatterns, blockNameForPatterns ] ); |
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 is working pretty well for me, and I think the trade off (that it might reduce the number of available patterns) is probably worth it.
Do you think there's a case for best practice eduction that Query patterns should ideally be wrapped in a Query block?
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 don't know. Conceivably you may want to create a complex pattern with a query in it, or even multiple queries. I think there's a place for those, but they aren't viable as replacements for a single Query block.
Co-authored-by: Ramon <[email protected]>
| const allPatterns = usePatterns( clientId, blockNameForPatterns ); | ||
| // Filter out any patterns that don't have Query as their root block | ||
| // so that a Query block is always replaced by another Query block. | ||
| const rootBlockPatterns = useMemo( () => { | ||
| return allPatterns.filter( ( pattern ) => { | ||
| return pattern.blocks?.[ 0 ]?.name === blockNameForPatterns; | ||
| } ); | ||
| }, [ allPatterns, blockNameForPatterns ] ); |
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.
Hey folks! 👋
I’m maintaining Sensei LMS and noticed that one of our blocks (block variation of core/query) stopped showing the “Choose” patterns button, and it looks like this change is related. For context, the custom patterns are registered here. Could you give me a hand with finding a solution?
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.
@m1r0 would you be able to create a new issue for this and then link to it from here?
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.
Oh I think the problem might be we're filtering for whatever variation is active, so you won't get other variations or the default query block in the results. We should probably filter for all instances of query block, whatever the variation. I'll try and get a fix up soon!
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.
Awesome! Thank you so much for the quick reaction, @tellthemachines!
What?
Fixes #67763.
The Query block is currently unselectable if it's nested inside a pattern. Adding
contentRolemakes it selectable in instances where it's not buried too deep in the pattern 😅 (see nesting issue I commented on here)Also, when we "Change design", some of the designs that come up don't have Query as their root block, and that can cause all sorts of problems like adding extra layers of nesting to a pattern, which then changes its layout in undesirable ways (you can end up with a really squished Query inside several Groups that each add extra margins).
I believe the best way of addressing this is by making sure that we always replace a Query with another Query, by not providing more complex patterns as options in the "Change design" modal, so this PR filters out those other patterns.
Testing Instructions