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

Fix: Don't show stacked icon on parent blocks if all of its children are hidden from the inserter #9337

Conversation

jorgefilipecosta
Copy link
Member

Until now even if all the children of a block were hidden from the inserter we showed the stacked icon in the parent.
Given that for this cases no child blocks will appear on the inserter of the parent we should not show the stacked icon.
This fix is important for the hidden blocks feature and this PR was partially extracted from there #9259.

We also move the logic of getBlockSupport to a selector so other selectors can use it. Some of the other simpler functions available in the block registration API are also promoted to selectors so we can add the new selector needed that uses them.

How has this been tested?

I used the following test block https://gist.github.com/jorgefilipecosta/7dbcf8ce79c57acc6eb2c64f0088f480 and checked that the parent block does not contain a stacked icon.

@jorgefilipecosta jorgefilipecosta changed the title Don't show stacked icon on parent blocks if all of its children are hidden from the inserter Fix: Don't show stacked icon on parent blocks if all of its children are hidden from the inserter Aug 24, 2018
@mtias mtias added this to the 3.8 milestone Aug 31, 2018
@jorgefilipecosta jorgefilipecosta force-pushed the fix/dont-show-child-stacked-icon-if-childs-are-hidden-on-inserter branch from 29bf1f0 to b95a287 Compare September 1, 2018 00:28
@youknowriad youknowriad modified the milestones: 3.8, 3.9 Sep 5, 2018
@jorgefilipecosta jorgefilipecosta force-pushed the fix/dont-show-child-stacked-icon-if-childs-are-hidden-on-inserter branch 3 times, most recently from c88dbf9 to 2f6c034 Compare September 7, 2018 16:54
@aduth
Copy link
Member

aduth commented Sep 13, 2018

I guess I'm a bit confused / conflicted on what the stacking icon is meant to convey. To me, I had understood it to mean that there are additional blocks which can be inserted only within the context of this top-level block. That, and/or simply that it supports block nesting. For the Columns block, both are true: It supports nesting, and specifically nesting of blocks only supported within that type (the "Column" block), regardless whether those block types are surfaced via an inserter present.

* @param {string} feature Feature to retrieve
* @param {*} defaultSupports Default value to return if not
* explicitly defined
* @return {?*} Block support value
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Newline between @param and @return. No alignment of @return description to @param.

https://make.wordpress.org/core/handbook/best-practices/inline-documentation-standards/javascript/

*
* @return {boolean} True if a block contains at least one child blocks with inserter support and false otherwise.
*/
export const hasChildBlocksWithInserterSupport = createSelector(
Copy link
Member

Choose a reason for hiding this comment

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

Minor: I don't think it's critical to memoize this. The performance should be good enough, and it returns a value of type which can be strictly compared true === true.

*/
export const hasChildBlocksWithInserterSupport = createSelector(
( state, blockName ) => {
return some( getChildBlockNames( state, blockName ), ( currentBlockName ) => {
Copy link
Member

Choose a reason for hiding this comment

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

Minor: Would child make more sense as a prefix in place of current ? It wasn't immediately clear to me what's "current" about what we're iterating.

export const hasChildBlocksWithInserterSupport = createSelector(
( state, blockName ) => {
return some( getChildBlockNames( state, blockName ), ( currentBlockName ) => {
return hasBlockSupport( state, currentBlockName, 'inserter', true );
Copy link
Member

Choose a reason for hiding this comment

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

Curious: Do we use this true value for 'inserter' supports elsewhere? Wondering at what point we'll start running into issues of magic constants being used in multiple places.

Copy link
Member Author

Choose a reason for hiding this comment

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

It was already being used in getInserterItems selector but it was not used in any other place.

@jorgefilipecosta jorgefilipecosta force-pushed the fix/dont-show-child-stacked-icon-if-childs-are-hidden-on-inserter branch 2 times, most recently from 6b14f1b to f2acc2f Compare September 13, 2018 18:19
@jorgefilipecosta
Copy link
Member Author

Hi @aduth, thank you for the review the feedback was applied.

I guess I'm a bit confused / conflicted on what the stacking icon is meant to convey. To me, I had understood it to mean that there are additional blocks which can be inserted only within the context of this top-level block. That, and/or simply that it supports block nesting.

I think the meaning we want for the icon is to indicate to the user that inside that block (item on the inserter) there will be more inserter items available. On the columns case that's not the case, nothing exclusive to columns will appear on the inserter so that's the reason we are thinking about removing the icon from the columns (and similar external blocks).

@aduth
Copy link
Member

aduth commented Sep 13, 2018

If I'm of the minority opinion, I'm fine to relent and move forward with this change.

@aduth
Copy link
Member

aduth commented Sep 13, 2018

Am I missing something, or should I not expect to see the stacking effect here?

image

@jorgefilipecosta jorgefilipecosta force-pushed the fix/dont-show-child-stacked-icon-if-childs-are-hidden-on-inserter branch from f2acc2f to 0dda16e Compare September 13, 2018 21:41
@jorgefilipecosta
Copy link
Member Author

Hi @aduth this PR does not change the columns it just changes the mechanism so a change to the columns can be applied. It can be tested using this block https://gist.github.com/jorgefilipecosta/7dbcf8ce79c57acc6eb2c64f0088f480.

The PR that applies a very trivial change to the column block (disables the inserter) is this one #9523. Probably I should have not divided the PR's given that it was a very simple change.

@aduth aduth added the [Feature] Inserter The main way to insert blocks using the + button in the editing interface label Sep 14, 2018
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 we have the other pull request to be in the 3.9 milestone then?

@jorgefilipecosta jorgefilipecosta merged commit cd167ce into master Sep 14, 2018
@mtias mtias deleted the fix/dont-show-child-stacked-icon-if-childs-are-hidden-on-inserter branch September 14, 2018 13:45
@aduth
Copy link
Member

aduth commented Sep 14, 2018

Missed running docs update. Local changes on master after running npm run docs:build

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Inserter The main way to insert blocks using the + button in the editing interface
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants