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

Projects
None yet
3 participants
@jorgefilipecosta
Copy link
Member

commented Nov 6, 2018

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.

@@ -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.

This comment has been minimized.

Copy link
@chrisvanpatten

chrisvanpatten Nov 6, 2018

Member

Small nit but these should all be one line, no line breaks :)

@aduth

aduth approved these changes Nov 6, 2018

Copy link
Member

left a comment

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

This comment has been minimized.

Copy link
@aduth

aduth Nov 6, 2018

Member

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() &&

This comment has been minimized.

Copy link
@aduth

aduth Nov 6, 2018

Member

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

This comment has been minimized.

Copy link
@aduth

aduth Nov 6, 2018

Member

👍

@@ -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,

This comment has been minimized.

Copy link
@aduth

aduth Nov 6, 2018

Member

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 Nov 7, 2018

@jorgefilipecosta jorgefilipecosta merged commit 7c63d10 into master Nov 7, 2018

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details

@jorgefilipecosta jorgefilipecosta deleted the add/flag-that-allows-disable-of-the-converstion-to-reusable-blocks branch Nov 7, 2018

@jorgefilipecosta jorgefilipecosta added this to the 4.3 milestone Nov 7, 2018

daniloercoli added a commit that referenced this pull request Nov 7, 2018

Merge branch 'master' of https://github.com/WordPress/gutenberg into …
…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)

grey-rsi pushed a commit to OnTheGoSystems/gutenberg that referenced this pull request Nov 22, 2018

grey-rsi pushed a commit to OnTheGoSystems/gutenberg that referenced this pull request Jan 4, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.