-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Make BlockManager
component reusable
#67052
Conversation
Size Change: +54 B (0%) Total Size: 1.82 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. |
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 have any comment on the master plan, but this PR makes sense and there are no regressions between trunk and this PR when toggling visibility of blocks in the preferences pane 👍🏻
LGTM so far
*/ | ||
export default function BlockManager( { | ||
blockTypes, | ||
selectedBlockTypes, |
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 can't see any errors so it might be a small thing, but I'm wondering that, if this is going to be a shared component, do you think any data validation is appropriate?
If selectedBlockTypes
isn't an array, a bunch of stuff would break.
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.
For now, I plan to release this component as a private component, so there shouldn't be any problems as long as it's used correctly within Gutenberg.
However, it would be better to at least have a conversion to an array, so I dealt with it in 242ba0e.
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 think we don't really do any validation for any component to be honest, so this would create a precedent that I'm not sure is good to make.
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 see, let's remove this validation for now.
Flaky tests detected in 242ba0e. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/11911466530
|
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 a good change
This reverts commit 242ba0e.
Part of #62703 (comment)
What?
This PR makes the
BlockManager
component reusable in preparation for building a UI for the allowedBlocks setting.Why?
The current
BlockManager
component is tightly coupled to theshowBlockTypes
andhideBlockTypes
actions and cannot be used for other purposes.How?
Change the
BlockManager
component to receive the following three props.blockTypes
: A list of blocks to display.selectedBlockTypes
: A list of currently selected blocks.onChange
: Called when the selected block is changed.Next, I reconstructed the current "Manage block visibility" settings as a
BlockVisibility
component that wraps theBlockManager
component. TheBlockVisibility
component controls the available blocks using theshowBlockTypes
andhideBlockTypes
via theonChange
prop of theBlockManager
component.Testing Instructions
The "Manage block visibility" setting should continue to work as before. Most of the functionality should be guaranteed by this E2E test.