-
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
Block Directory: Filter out disallowed blocks before showing available blocks #25926
Block Directory: Filter out disallowed blocks before showing available blocks #25926
Conversation
Size Change: +274 B (0%) Total Size: 1.28 MB
ℹ️ View Unchanged
|
packages/block-directory/src/components/downloadable-blocks-panel/index.js
Outdated
Show resolved
Hide resolved
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 @ryelle - thanks for your work here 👍 .
I tested it and seems to be working well! I've left a couple of comments but nothing major.
7025c56
to
fd89921
Compare
I'm not sure what the issue is with the tests — I can't reproduce the |
fd89921
to
1930bfc
Compare
1930bfc
to
6208e90
Compare
@ryelle Is there anything specific left for this PR before it can be merged? |
@StevenDufresne It's been awhile since the original PR, if you could just check it over to make sure nothing slipped by in the rebase I'd appreciate it. |
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 checked it out, it does work as expected.
Description
Some blocks (or post types) have a restricted list of what can be added (
allowedBlocks
, aka child blocks), and we might not be able to add a new block to those containers. Currently, we list all found blocks regardless of this issue, which causes unexpected results when the user tries to add them.This PR follows from #22240 & #24148, but should fix the root issue at both.
I've updated the
canInsertBlockType
selector to accept an object for the blockType. If an object is passed in, it will not usegetBlockType
, which would only work for an already-installed block type. This should be fine for existing uses of the selector, since they'll pass in a string & behavior will stay the same. For the block directory, we can pass in our block object, so that potential downloadable blocks can be checked against the current container.How has this been tested?
You can download & install this example container block that only allows
"core/image", "core/heading", "core/paragraph", "book-review-block/book-review"
in the container, and has a filter in the PHP file to restrict blocks in all post types to justNow search for "Stars", and you'll see two results in the main editor content, and 1 available result in the demo block. Search for something totally different (ex, recipe), and you'll get the "No blocks found in your library." result.
Screenshots
In the post, I've set allowedBlocks to allow these 2 blocks that return for the query
stars
(in reality, 4 blocks are returned)In this container block, only one block matches allowedBlocks, so only one is shown: