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: Use new action REPLACE_INNER_BLOCKS for InnerBlocks replacement #14291

Merged

Conversation

jorgefilipecosta
Copy link
Member

Description

Adds a new action REPLACE_INNER_BLOCKS that is used during the inner block creation/update to set its template.
We are updating the insert/replace and move actions to restrict if the new blocks can be added in the specific locations. During the set of an inner blocks template even if restrictions exist e.g: locking, the blocks should be added, this would require flags in the existing actions to not apply restriction in that case.
@gziolo suggested that we use a new specific action, and this PR implements it.

Pending: test cases, after we check if this approach (use a High Order Reducer) is valid I will add them to this PR.

How has this been tested?

I used the columns block, changed the number of columns, and verified everything still works as before.
I used the Media & Text block and verified the heading block still does not get selected by default.
I tried a sample block with inner blocks https://gist.github.com/jorgefilipecosta/b7194daac3ce26827522694fb4252c1c#file-testallowedblocksmiddleware-js and checked the block still work as before.

Copy link
Member

@gziolo gziolo left a comment

Choose a reason for hiding this comment

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

Thanks for updating this PR. I don't quite know how blocks reducer works at the moment so I would need to invest some time to understand it better. Seeing the complexity here, it feels like it could use some unit testing for the new action integrated into the reducer.

} else {
insertBlocks( blocks, undefined, clientId, templateInsertUpdatesSelection );
}
replaceInnerBlocks( clientId, blocks, block.innerBlocks.length === 0 && templateInsertUpdatesSelection );
Copy link
Member

Choose a reason for hiding this comment

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

block.innerBlocks.length === 0 - can be computed inside replaceInnerBlocks. Is there any reason it has to be placed here?

Copy link
Member Author

Choose a reason for hiding this comment

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

The selection is managed on a reducer that does not have access to the blocks themselves. In order to the check in a reducer, we would need a top-level high order reducer. We don't have any top-level higher-order reducer yet. I'm not sure we want to open that precedent.
But the main reason was to make easier to debug state changes. Currently, if the replaceInnerFlags action updateSelection flag is true the selection is updated if it is false the selection is not updated. If this logic was inside the reducer if the flag was false the selection was not updated, but if the flag was true the selection may or may not be updated.

@jorgefilipecosta
Copy link
Member Author

Hi @gziolo that you for the review, I agree that unit tests need to be added, I did not add them yet because I want to validate this approach before investing the time in the test creation.

@gziolo gziolo added this to the 5.3 (Gutenberg) milestone Mar 11, 2019
@gziolo gziolo added [Package] Block editor /packages/block-editor [Type] Enhancement A suggestion for improvement. labels Mar 11, 2019
@jorgefilipecosta jorgefilipecosta force-pushed the update/use-new-action-for-inner-blocks-replacement branch from a6afb8e to a2a982a Compare March 15, 2019 11:50
@jorgefilipecosta
Copy link
Member Author

The unit tests were added.

@jorgefilipecosta jorgefilipecosta added the [Status] In Progress Tracking issues with work in progress label Mar 15, 2019
@jorgefilipecosta jorgefilipecosta force-pushed the update/use-new-action-for-inner-blocks-replacement branch from a2a982a to c765b6e Compare March 15, 2019 14:39
@jorgefilipecosta jorgefilipecosta removed the [Status] In Progress Tracking issues with work in progress label Mar 15, 2019
@youknowriad youknowriad removed this from the 5.3 (Gutenberg) milestone Mar 18, 2019
Copy link
Member

@gziolo gziolo left a comment

Choose a reason for hiding this comment

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

Thanks for adding unit tests. This gives much more confidence into the newly introduced logic moving forward. Everything looked good in my testing. Great work 👍

I left some minor proposals for changes in tests names.

packages/block-editor/src/store/test/reducer.js Outdated Show resolved Hide resolved
packages/block-editor/src/store/test/reducer.js Outdated Show resolved Hide resolved
packages/block-editor/src/store/test/reducer.js Outdated Show resolved Hide resolved
packages/block-editor/src/store/test/reducer.js Outdated Show resolved Hide resolved
gziolo and others added 4 commits March 18, 2019 08:13
Co-Authored-By: jorgefilipecosta <jorge.costa@developer.pt>
Co-Authored-By: jorgefilipecosta <jorge.costa@developer.pt>
Co-Authored-By: jorgefilipecosta <jorge.costa@developer.pt>
Co-Authored-By: jorgefilipecosta <jorge.costa@developer.pt>
@jorgefilipecosta jorgefilipecosta added this to the 5.4 (Gutenberg) milestone Mar 18, 2019
@jorgefilipecosta jorgefilipecosta merged commit 1936caa into master Mar 18, 2019
@jorgefilipecosta jorgefilipecosta deleted the update/use-new-action-for-inner-blocks-replacement branch March 18, 2019 12:48
@jorgefilipecosta
Copy link
Member Author

Thank you for the review and suggestions @gziolo!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package] Block editor /packages/block-editor [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants