-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Fix: Don't show stacked icon on parent blocks if all of its children are hidden from the inserter #9337
Conversation
29bf1f0
to
b95a287
Compare
c88dbf9
to
2f6c034
Compare
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 |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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 ) => { |
There was a problem hiding this comment.
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 ); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
6b14f1b
to
f2acc2f
Compare
Hi @aduth, thank you for the review the feedback was applied.
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). |
If I'm of the minority opinion, I'm fine to relent and move forward with this change. |
…idden from the inserter.
f2acc2f
to
0dda16e
Compare
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. |
There was a problem hiding this 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?
Missed running docs update. Local changes on master after running |
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.