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

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 self-assigned this Jun 25, 2019

@getdave getdave referenced this pull request Jun 25, 2019
6 of 6 tasks complete

@getdave getdave marked this pull request as ready for review Jun 25, 2019

@getdave getdave force-pushed the update/grouping-mechanic-to-use-registered-block branch from a492fb0 to dc3bfb2 Jul 3, 2019

@getdave getdave requested a review from gziolo Jul 3, 2019

@getdave

This comment has been minimized.

Copy link
Contributor Author

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.

@aduth
Copy link
Member

left a comment

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 added a commit that referenced this pull request Jul 8, 2019

@getdave

This comment has been minimized.

Copy link
Contributor Author

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 Jul 8, 2019

getdave added a commit that referenced this pull request Jul 8, 2019

getdave added some commits Jun 25, 2019

Updates factory util to reference registered Grouping Block
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.
Attempt e2e test to validate usage of alternate Block for grouping
Currently this doesn’t work because window doesn’t have NODE defined.
Adds e2e test to confirm ability to register alternative Block for Gr…
…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 Jul 9, 2019

@getdave getdave requested a review from aduth Jul 9, 2019

@aduth

aduth approved these changes Jul 9, 2019

Copy link
Member

left a comment

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

aduth added some commits Jul 9, 2019

@getdave getdave merged commit 5cb8b8f into master Jul 9, 2019

1 of 2 checks passed

Filter merged Filter merged
Details
Travis CI - Pull Request Build Passed
Details

@github-actions github-actions bot added this to the Gutenberg 6.2 milestone Jul 9, 2019

@getdave

This comment has been minimized.

Copy link
Contributor Author

commented Jul 9, 2019

Thanks @aduth 👍

@aduth aduth deleted the update/grouping-mechanic-to-use-registered-block branch Jul 10, 2019

jg314 added a commit to jg314/gutenberg that referenced this pull request Jul 19, 2019

Update to allow alternative Blocks to handle Grouping interactions (W…
…ordPress#16278)

* Updates factory util to reference registered Grouping Block

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.

* Attempt e2e test to validate usage of alternate Block for grouping

Currently this doesn’t work because window doesn’t have NODE defined.

* Adds e2e test to confirm ability to register alternative Block for Grouping

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.

* Utilise withSelect to get the current Grouping Block name

* Removes unrequired test suite

* Fix bug with misnamed variable

* Remove hardcoded group block ref

Addresses WordPress#16278 (review)

* Remove / update refs to core/group within comments

* Block API: Stub default attributes, keywords values for block type registration

* Revert "Block API: Stub default attributes, keywords values for block type registration"

This reverts commit be6e767.

sbardian added a commit to sbardian/gutenberg that referenced this pull request Jul 29, 2019

Update to allow alternative Blocks to handle Grouping interactions (W…
…ordPress#16278)

* Updates factory util to reference registered Grouping Block

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.

* Attempt e2e test to validate usage of alternate Block for grouping

Currently this doesn’t work because window doesn’t have NODE defined.

* Adds e2e test to confirm ability to register alternative Block for Grouping

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.

* Utilise withSelect to get the current Grouping Block name

* Removes unrequired test suite

* Fix bug with misnamed variable

* Remove hardcoded group block ref

Addresses WordPress#16278 (review)

* Remove / update refs to core/group within comments

* Block API: Stub default attributes, keywords values for block type registration

* Revert "Block API: Stub default attributes, keywords values for block type registration"

This reverts commit be6e767.
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.