fix(ui): preserve selected options in hasMany relationship filter while searching#17088
Open
jhjh1214 wants to merge 3 commits into
Open
Conversation
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #17048
What?
Filtering by a
hasManyrelationship field in the admin where-builder could intermittently drop a previously-selected item after selecting/searching for another one.Why?
findOptionsByValue()'s multi-value branch returnedundefinedfor any selected value not currently present in the loadedoptionslist. This happens any time the user types into the search box:handleInputChangesynchronously clearsoptionsvia the reducer'sCLEARaction, before the async re-fetch (which patches missing selections back in) completes. During that window,ReactSelectis a fully-controlled component, so any interaction with it (selecting/removing another chip) reports back a selection containing that hole, andonChangepropagates it upward, genuinely losing the item from the filter's value, not just visually.The single-value branch right below it already guards against this exact case with a
|| valuefallback; the multi-value branch was missing the equivalent per-entry protection.How?
Fall back to a placeholder
{ label, value, relationTo }option instead ofundefinedwhen no match is found, so the array fed intoReactSelectnever has holes. Once the real document loads via the existing patch effect, the next render naturally replaces the placeholder with the properly-labeled option.Tests
Added a regression e2e test that selects two items, then types a search query and uses
page.route()to hold back the reload request, deterministically asserting both previously-selected chips remain visible during that window.