fix(company-input-v2): keep Use row on refocus, purge stale free-text (v4.x) - #291
Merged
Merged
Conversation
…exists
The Use "<typed>" row disappeared after the user committed a free-text
entry and re-focused the field, because filterOptions treated its own
prior {id:0,name} option as "already listed".
Two fixes to filterOptions:
- alreadyListed only counts real (id > 0) companies, not free-text.
- When params.inputValue is empty (passive refocus with no typing) and
the current value is a committed free-text, fall back to its name so
the Use row still appears.
Adds a regression test for the retype-same-text case.
After the user commits a free-text value via blur and starts a new
query, the previously-committed {id: 0} option lingered in the options
list until the debounced API response replaced them. In the meantime a
refocus would briefly show the stale entry ("ti" flashing while the
user was typing "tip").
The effect now purges any leftover free-text options synchronously the
moment normalizedValue or inputValue changes, before firing the request.
Adds a regression test that catches the stale entry mid-request.
…Company Mirrors the isExistingCompany predicate — pair reads more naturally as "predicate + finder for the same shape". Pure rename.
The X.trim().toLowerCase() comparison for company names appeared in three places (findExistingCompany, filterOptions, onBlur). Extracting a single namesMatch helper removes the duplication and gives the intent a name.
Moves the Use-row eligibility predicate out of the filterOptions callback for unit-testability. filterOptions now composes cleanly with the (later) getUseRowText helper. Adds four unit tests, including the id:0-doesnt-suppress-Use case that pins the recently-fixed regression.
Dedupes the findExistingCompany(opts, X) || { id: 0, name: X } pattern
that appeared in both onBlur and onChange. Both sites are answering the
same question — turn a typed string into either the canonical existing
company or a fresh free-text entry — and should agree on the answer.
…Name The ternary derivation exactly duplicates what getOptionName already does (handles string, company object, other → "").
Formalises the two-source resolution (active typing + committed free-text fallback) that filterOptions already needed. Reduces filterOptions to its two-line essence.
…ireChange in onChange The onChange handler's three-branch normalization (string, synthetic Use row, pass-through) is now a single helper call. The handler also uses the existing fireChange helper instead of hand-building the onChange envelope; matches the rest of the component and removes the onChange prop/handler name shadow.
… effect The effect callback now reads as three coherent steps: reset options, try to upgrade a stale free-text to its canonical version, done. The "is this a free-text? then look up the canonical" logic is now a named helper (findCanonicalUpgrade) instead of an inline conditional. Also collapses the six-line newOptions builder into one composed array.
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
ref: https://app.clickup.com/t/86b9rnr4r
Follow-up to #290 addressing two dropdown regressions found during local verification.
Bugs fixed
1.
Use "<typed>"row disappeared after committing free-text and refocusing — thealreadyListedcheck treated the just-committed{id: 0, name}entry as a real match and suppressed the Use row. Also affected passive refocus (click back with no typing) because MUI resetsparams.inputValueto empty when the display value matches the selection.2. Stale free-text option flashed briefly on refocus after a new commit — the previously-committed
{id: 0}option lingered in the options list until the debounced API response replaced it. Refocus in that window showed the stale entry.Changes
Fixes (2 commits):
filterOptionsnow only counts real (id > 0) companies as "already listed" for the Use row check, and falls back to the committed free-text's name whenparams.inputValueis empty.{id: 0}options synchronously the momentnormalizedValuechanges, before firing the API request.Refactors on top (8 commits, no behavior change):
findExistingByName→findExistingCompany(mirrorsisExistingCompany).namesMatch— dedupes theX.trim().toLowerCase()comparison across three sites.shouldOfferUseRow— unit-testable predicate for the Use row.resolveTypedCompany— dedupes onBlur/onChange typed-string resolution.currentNameviagetOptionName.getUseRowText— formalises the active-typing + committed-free-text fallback.resolveCommittedCompany, usefireChangein onChange (removes prop/handler name shadow, dedupes with the rest of the component).findCanonicalUpgrade, simplify effect's options builder.Naming convention
The extracted helpers follow a consistent verb-prefix convention already in the file:
is*predicates,find*returns match or null,resolve*transforms input to a Company (always returns),get*computed getter,should*boolean decision.Tests
34/34 green. Each fix commit ships with an integration test that fails without the fix (verified by reverting each in isolation). The
shouldOfferUseRowextraction adds four unit tests including the id:0-doesnt-suppress-Use case that pins the regression.