-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Search: Hide label when inserted in Navigation block #36026
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8e05f25
Search: Hide label when inserted in Navigation block
Mamaduka b37f9f5
More contextual defaults
Mamaduka a895df9
Include attributes with default values in check
Mamaduka d968075
Use getBlockParentsByBlockName
Mamaduka 78ba3d3
Remove context
Mamaduka File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This only works when we first insert a Search block in Navigation. If we insert the block, save and reload the page, and then try changing the settings back to the defaults, they just change back 😬
We should probably also return if any of the settings have been edited.
Another potential edge case is already existing Search-within-Nav patterns: if the Search settings are the defaults, they'll be auto-changed, which might not be the desired outcome if the block has already been edited and saved before. I'm wondering if we should do this only for newly-inserted blocks - that would fix the issue of having edited settings reset after page reload too.
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 added few more checks in a895df9, to mitigate this. But I agree it's not most elegant solution.
I also tried using the
wasBlockJustInserted
selector, but it wasn't working for some reason. I will give this another go in a moment.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.
@tellthemachines, thanks for the great feedback.
The
wasBlockJustInserted
selector doesn't work in the Navigation block context. It always returnsfalse
for the Search block. I think it's a bug that needs to be addressed separately.Unfortunately, I'm not aware of another selector to check if the block is new.
As for the edge cases, I'm not sure. Should we consider it a bug we can live with while the
wasBlockJustInserted
selector issue is fixed?I will leave that decision to you and @jasmussen.
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.
Hmm, this is tricky because
wasBlockJustInserted
only works for newly inserted blocks, not transformed blocks, and with how Navigation currently works chances are high that folks will be coming to the Search block via a transform.To mitigate the issue with resetting the block to defaults after reload, we can store refs to the attribute values and return early in the effect if they change. I'm not sure there's an easy way to handle not changing existing blocks though.
Given Navigation is still experimental, perhaps there are not that many existing Navigations with Search blocks using all the default settings out there 😅
@jasmussen what are your thoughts on this?
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.
Apologies I missed the first ping!
I took the latest for a quick spin to just check things out, and I'm seeing the correctly-configured-for-nav search block work well:
I understand something happens if/when you reload? Or were you referring to existing navigation block that feature search?
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 was kindly explained that the problem might be that the action that sets the new defaults might fire every time the block loads, and therefore might reset back to the new defaults even if you want something else. Is that correct?
I wasn't actually able to reproduce this — it seems to continue working for me:
But more high level — while this is a really nice one that makes for a better navigation block experience, I wouldn't consider it crucial that this land in 5.9. If we can make it, nice. Otherwise, with 6.0 won't be that far behind!
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's is true that the effect will run on every page reload. But the
setAttribute
will only fire ifshowLabel
andbuttonUseIcon
attributes use the same value, so this is quite a specific situation.@jasmussen to reproduce the issue, set button to use text and then enable label. You'll see that block will reset to the insertion state.
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.
Ah gotcha, so if you basically reset the navigation block to specifically look like the default state, it will reset on reload?
If we think we can fix the underlying bug in a followup and improve that, I'd be tempted to accept that tradeoff to get the feature landed.
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.
That's correct.
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.
Yes, but most importantly it will update existing
Search
blocks.I made an alternative here: #36125, keeping some of this logic from George.