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

Update to allow alternative Blocks to handle Grouping interactions #16278

Merged
merged 10 commits into from
Jul 9, 2019

Conversation

getdave
Copy link
Contributor

@getdave getdave commented Jun 25, 2019

This PR will allow alternative Blocks to be used to handle Grouping interactions. Currently, you can only use core/group but this PR will make it possible to register any valid Block as the Block to use when Grouping.

Previously the method that determined whether a given Block was the block to be used for “Grouping” interactions was hardcoded as “core/group. This PR builds upon #15774 to allow alternative Blocks to be used to handle the Grouping interactions.

This should address some of the concerns raised in #14908 (comment), namely:

  • Avoid hardcoding refs to core/group within packages/blocks/src/api/factory.js
  • Allow other Blocks to be registered to handle Grouping if required

Screenshots

Below shows me registering the test/alternative-group-block Block from a custom e2e testing Plugin as the default Grouping Block. I'm then using it within the Grouping interactions.

Screen Capture on 2019-07-03 at 13-19-25

How has this been tested?

  • Unit tests
  • e2e tests
  • Manual testing using the method outlined below.

How to test

  • Open wp-admin in the Gutenberg docker env
  • Activate the Gutenberg Test Custom Grouping Block Plugin (important: be sure to deactivate this after you have finished testing!)
  • Create a new Page and add some Blocks to be Grouped.
  • In the browser console
    • type window.wp.blocks.getGroupingBlockName() to get the current Grouping Block name - it should be core/group (the default).
    • type wp.blocks.setGroupingBlockName( 'test/alternative-group-block' ); - it should register that block (provided by the Plugin activated above) as the default for Grouping
  • using the Editor UI
    • "Group" the Blocks using the "Group" item from the dropdown menu
    • Ungroup the Blocks again
    • Group the Blocks using the "Transform" control by selecting the "Alternative Group Block"

Questions

  • Is relying on getGroupingBlockName() from the package here appropriate? I'm concerned I'm not using a select() here. Now uses select().
  • Should we have some kind of validation in place before we allow custom blocks to be set as the Grouping Block? At the moment you can register any old Block but only Blocks which support the necessary transforms and utilise InnerBlocks are allowed. For example, you could try and register coblocks/column to act as the Grouping Block (it supports InnerBlocks after all) but within the correct convert() (transform) definition it won't function as you'd expect.
  • Where should I write documentation to cover this feature (if at all)?

Types of changes

New feature (non-breaking change which adds functionality).

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.

@getdave getdave added [Feature] Block API API that allows to express the block paradigm. [Block] Group Affects the Group Block labels Jun 25, 2019
@getdave getdave self-assigned this Jun 25, 2019
@getdave getdave marked this pull request as ready for review June 25, 2019 10:32
@getdave getdave added the Needs Technical Feedback Needs testing from a developer perspective. label Jun 25, 2019
@getdave
Copy link
Contributor Author

getdave commented Jul 4, 2019

@aduth @gziolo This PR is now passing all builds and is "ready to go" feature wise. However it still needs another tech review and manual test. Much appreciated.

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.

Should this other reference be updated as well?

// Activate the `transform` on `core/group` which does the conversion
const newBlocks = switchToBlockType( blocks, 'core/group' );

Less important, comment updates:

// Don't allow single 'core/group' blocks to be transformed into

// Unless it's a `core/group` Block then for multi block selections

// Activate the `transform` on `core/group` which does the conversion

@getdave
Copy link
Contributor Author

getdave commented Jul 8, 2019

@aduth I've addressed those CR points.

I have no clue why the PHP unit tests have suddenly started failing...

@getdave getdave force-pushed the update/grouping-mechanic-to-use-registered-block branch from 3124452 to 46e6e15 Compare July 8, 2019 13:03
Previously the method that determined whether a given Block was the block to be used for “Grouping” interactions was hardcoded as “core/group” within `isContainerBlock`. Updated to utilise the registered Grouping Block in order to allow alternative Blocks to be utilised for Grouping.
Currently this doesn’t work because window doesn’t have NODE defined.
…ouping

Now using custom Gutenberg Plugin. Currently failing as the test Block appears to be unavailable within the Editor and doesn’t pass the `canInsertBlockType` test.
@getdave getdave force-pushed the update/grouping-mechanic-to-use-registered-block branch from 46e6e15 to c7339a6 Compare July 9, 2019 08:58
@getdave getdave requested a review from aduth July 9, 2019 18:03
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.

Another potentially useful consequence of these functions is to better accommodate scenarios where the grouping block isn't available (either because it's not been registered or in allowing to explicitly unset by setGroupingBlockName( null )).

@getdave getdave merged commit 5cb8b8f into master Jul 9, 2019
@github-actions github-actions bot added this to the Gutenberg 6.2 milestone Jul 9, 2019
@getdave
Copy link
Contributor Author

getdave commented Jul 9, 2019

Thanks @aduth 👍

@aduth aduth deleted the update/grouping-mechanic-to-use-registered-block branch July 10, 2019 12:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Group Affects the Group Block [Feature] Block API API that allows to express the block paradigm. Needs Technical Feedback Needs testing from a developer perspective.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants