Skip to content
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

Conversation

jorgefilipecosta
Copy link
Member

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.

@jorgefilipecosta jorgefilipecosta added [Type] Bug An existing feature does not function as intended [Feature] Block API API that allows to express the block paradigm. [Feature] Blocks Overall functionality of blocks [Feature] Synced Patterns Related to synced patterns (formerly reusable blocks) labels Nov 6, 2018
@@ -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.
Copy link
Contributor

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 :)

Copy link
Member

@aduth aduth left a 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
Copy link
Member

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() &&
Copy link
Member

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 );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@@ -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,
Copy link
Member

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"

@jorgefilipecosta jorgefilipecosta force-pushed the add/flag-that-allows-disable-of-the-converstion-to-reusable-blocks branch from 9e127e0 to e5325fc Compare November 7, 2018 09:54
@jorgefilipecosta jorgefilipecosta merged commit 7c63d10 into master Nov 7, 2018
@jorgefilipecosta jorgefilipecosta deleted the add/flag-that-allows-disable-of-the-converstion-to-reusable-blocks branch November 7, 2018 12:01
@jorgefilipecosta jorgefilipecosta added this to the 4.3 milestone Nov 7, 2018
daniloercoli added a commit that referenced this pull request Nov 7, 2018
…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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Block API API that allows to express the block paradigm. [Feature] Blocks Overall functionality of blocks [Feature] Synced Patterns Related to synced patterns (formerly reusable blocks) [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants