Block API: Add block visibility control in the command center#72154
Conversation
- Added support for toggling block visibility based on block attributes. - Introduced new commands to show/hide selected blocks with appropriate labels. - Utilized existing utility functions to clean up metadata before updating block attributes. This update improves the user experience by allowing users to manage block visibility directly from the block commands.
| name: 'core/toggle-block-visibility', | ||
| label: blockVisibilityLabel, | ||
| callback: () => { | ||
| const attributesByClientId = Object.fromEntries( |
There was a problem hiding this comment.
A lot of this is copied over from:
Is there scope for centralization, e.g., a private action?
| const canToggleBlockVisibility = blocks.every( ( { clientId } ) => | ||
| hasBlockSupport( getBlockName( clientId ), 'blockVisibility', true ) | ||
| ); |
There was a problem hiding this comment.
I'm not sure if these should use useMemo - other, similar array filters don't in this file 🤔
|
Thanks for working on this PR 🙏 I've only had a quick look at it, but I think "Show" and "Hide" will probably be enough, since that's the case with the other block actions as well.
|
Ah, do you mean the label? No problem. And thanks for the very fast feedback!! 🙇🏻 |
|
Size Change: +65 B (0%) Total Size: 1.96 MB
ℹ️ View Unchanged
|
|
Flaky tests detected in a610286. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/18338236849
|
Co-authored-by: Aki Hamano <54422211+t-hamano@users.noreply.github.com>
|
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. |
…ess#72154) Co-authored-by: ramonjd <ramonopoly@git.wordpress.org> Co-authored-by: t-hamano <wildworks@git.wordpress.org>
What?
Follow up to #71203
Part of
This PR adds support for toggling block visibility based on block attributes in the command centre.
Why?
To make the show/hide function available in the command centre.
Testing Instructions
Similar to the testing instructions in #71203 but for the command centre
Cmd/Ctrl + kto open the command center, and observe the"Hide"command."Show"them.Screenshots or screencast
Kapture.2025-10-08.at.18.31.51.mp4