-
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
Allow a block to disable being converted into a reusable block; Fix: Column block #11550
Allow a block to disable being converted into a reusable block; Fix: Column block #11550
Conversation
docs/block-api.md
Outdated
@@ -504,6 +504,14 @@ inserter: false, | |||
multiple: false, | |||
``` | |||
|
|||
- `reusable` (default `true`): A block may want to disable the ability of being converted into a reusable block. | |||
By default all blocks can be converted to a reusable block if supports reusable is set to false, | |||
the option to convert the block into a reusable block will not appear. |
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.
Small nit but these should all be one line, no line breaks :)
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.
A few small non-code details to fix up, but code looks / works great 👍
( blocks.length !== 1 || ( | ||
blocks[ 0 ].name !== getFreeformFallbackBlockName() && | ||
blocks[ 0 ].name !== getUnregisteredFallbackBlockName() | ||
// Guard against the case where a regular block has *just* been converted to a |
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 comment now only really covers part of what's being done with the every
condition. We might want to enhance it slightly, or even move it to cover the specific parts of the predicate for which it is relevant (!! block && block.isValid
, with complementing comment for the hasBlockSupport
check).
// Hide 'Add to Reusable Blocks' on Classic blocks. Showing it causes a | ||
// confusing UX, because of its similarity to the 'Convert to Blocks' button. | ||
( blocks.length !== 1 || ( | ||
blocks[ 0 ].name !== getFreeformFallbackBlockName() && |
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 like that we formalize this on the blocks API rather than ad hoc exemptions 👍
|
||
const blocks = map( clientIds, ( clientId ) => getBlock( clientId ) ); | ||
const blocks = getBlocksByClientId( clientIds ); |
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.
👍
docs/block-api.md
Outdated
@@ -504,6 +504,14 @@ inserter: false, | |||
multiple: false, | |||
``` | |||
|
|||
- `reusable` (default `true`): A block may want to disable the ability of being converted into a reusable block. | |||
By default all blocks can be converted to a reusable block if supports reusable is set to false, |
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 this is missing a sentence stop between "block" and "if"
9e127e0
to
e5325fc
Compare
…rnmobile/fix-merge-content-not-refreshed-UI * 'master' of https://github.com/WordPress/gutenberg: Fix the isBeingScheduled Selector. (#11572) Slot/Fill pattern with Toolbar #199 (#11115) Add mechanism to avoid forced child selection on blocks with templates. (#10696) Allow a block to disable being converted into a reusable block; Fix: Column block (#11550)
Fixes: #10679
This PR adds a flag that allows a block to opt-out being converted into a reusable block as discussed in #10679.
This new logic is used to disable the conversion of column block into a reusable block and to simplify existing logic that disables classic and missing block conversion to reusable blocks.
These simplifications add a behavior change.
Before it was not possible to convert classic or missing block into a reusable block, but if another block was selected with it (even an empty paragraph) it was possible to convert that blocks into reusable blocks, now that's not the case.
If a block that is part of the selection cannot be converted into a reusable block, the option to convert the selected blocks into a reusable block will not be shown.
I think that is the desired behavior.
How has this been tested?
Verify it is not possible to convert to reusable blocks, the "Column" block, the classic block or an invalid block.
Verify it is still possible to convert to reusable blocks the "Columns" block.
Test complex scenarios e.g. multiple selections of Columns and a paragraph, and verify the conversion is possible.