-
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
Auto-inserting blocks: Remove toggle if block is present elsewhere #54024
Auto-inserting blocks: Remove toggle if block is present elsewhere #54024
Conversation
Size Change: +21 B (0%) Total Size: 1.51 MB
ℹ️ View Unchanged
|
Flaky tests detected in ff3d13378c9a0c66bdbc842b44bd70f73e3cf8c9. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/6024828150
|
5d3eac0
to
10b0da3
Compare
Rebased (since I was seeing a few weird JS unit test errors). Should be ready for review now! |
@ockham, I resolved the remaining warning with How
I've also memoized |
The code is quite complex, and that's perfectly fine as I don't think we can much simplify it without creating even more abstractions in the block editor's store. I want to focus on testing next, and thinking about how we could cover that with e2e tests as a follow-up so we can continue iterating on the existing logic and depend less on manual testing which takes a ton of time. |
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.
Everything works as expected based on my testing using the instructions provided. Excellent work on this one.
I also tried reverting the template and the moved or removed like button shows up again in the expected place.
...clientIds, | ||
[ block.name ]: autoInsertedBlock.clientId, | ||
}; | ||
} else if ( getGlobalBlockCount( block.name ) > 0 ) { |
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.
I had this after-thought that we could put:
if ( getGlobalBlockCount( block.name ) === 0 ) {
return clientIds;
}
at the top of the function. If there is no block present in the editor, then we are sure we can show the toggle. In this place, we could simplify the check in the highlighter line to:
} else {
With proper inline comments that might also simplify following all the edge cases.
Anyway, it's a stylystic issue and I'm fine with the current approach, too. It's just something that helped me to understand the logic.
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.
Makes sense! Applied in 35ebe4e8bc 😊
31a5424
to
5f72af4
Compare
The diff after all the recent changes is much easier to follow, I like how it shaped after a few additional tweaks. |
…54024) If a block that would normally be auto-inserted is not found in its designated position but elsewhere, we can assume somewhat safely that it was inserted manually, and that the user is aware of the block and won't need any UI elements to make it more visible. Additionally, this PR fixes most of the following warnings (raised [here](#52969 (comment))): ``` The 'useSelect' hook returns different values when called with the same state and parameters. This can lead to unnecessary rerenders. ``` --------- Co-authored-by: George Mamadashvili <[email protected]>
What?
Follow-up to #52969.
Remove the Auto-inserting block inspector panel toggle for a block if it's present in a different location than expected for auto-insertion.
Additionally, this PR fixes most of the following warnings (raised here):
Why?
If a block that would normally be auto-inserted is not found in its designated position but elsewhere, we can assume somewhat safely that it was inserted manually, and that the user is aware of the block and won't need any UI elements to make it more visible.
This was first discussed here.
How?
By checking if the global block tree contains any instance of the block type in question. (Hat-tip @gziolo for pointing me to
getGlobalBlockCount
🙌 )Testing Instructions
.wp-env.override.json
file.Screenshots or screencast