Repository navigation
fix(ui): submit the only available query type and reject an empty target - #537
Merged
Merged
Conversation
When the selected locations have one query type in common, `locationChange` set it in the store's form values but not in its selections or in react-hook-form. The select showed nothing, and a submit failed with "Query Type must be specified." until the user picked the only option by hand. `locationChange` now also sets the query type selection. The form mirrors the store's values into react-hook-form whenever they change, instead of copying them once on mount. This also covers the other values the store sets on its own: the query restored after returning from results, and a reset from the header title, which left the previous query in react-hook-form so it could still be submitted. The #506 test that documented the bug now asserts the fix, and a test covers the reset.
A target that was typed and then cleared is `['']`. The form checked only that the target list was not empty, so it submitted and switched to the results view with an empty target. Every target must now contain a non-whitespace character, so `['']`, a whitespace-only target and an empty value among several targets fail with the configured `messages.noInput` message for `web.text.queryTarget`. The #506 test that documented the bug now asserts the fix.
This was referenced Nov 21, 2026
WilhelmZA
approved these changes
Nov 21, 2026
WilhelmZA
left a comment
Collaborator
There was a problem hiding this comment.
Approving at 65c22336.
I read the changes to use-form-state.ts and looking-glass-form.tsx and followed QueryType, the hidden QueryTarget input, reset() and back(). The single query type is now selected and submitted, and a target with only whitespace is rejected. The field-less ['null'] target and select targets still pass validation. CI gate passes and both commits are verified.
#545 and #567 are stacked on this branch and change the same four files.
Nits:
- The body has a Changelog section with three entries but
CHANGELOG.mdis not edited. Please add them under[Unreleased], here or in the release PR.
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.
Problem
The query form keeps its values in three places: react-hook-form (which runs the vest validation), the
useFormStatestore'sformvalues, and the store'sselections(which the selects display). They drift apart.locationChangeset it inform.queryTypeonly. The select showed no selection, and react-hook-form still had'', so a submit failed with "Query Type must be specified." until the user picked the only option by hand.['']. The vest rule only checked that the target list was not empty, so the form submitted and switched to the results view with an empty target.Change
Two commits, one per issue.
#512 (
hooks/use-form-state.ts,components/looking-glass-form.tsx)locationChangealso setsselections.queryTypewhen it chooses the only query type, so the select shows it.formvalues into react-hook-form withsetValuein an effect that runs whenever they change. It replaces the effect that copied them once on mount to restore the previous query.Why a mirror effect rather than a
setValuenext tolocationChange: the store changes form values without going throughhandleChangein three places, and all three drift the same way.locationChangechoosing the only query type (Form rejects the only available query type as unselected #512).reset()from the header title. The title is shown with the form, and the form stays mounted, so react-hook-form kept the previous query. A submit after clicking the title passed validation with values the store no longer had.A
setValueat thelocationChangecall site would fix only the first.handleChangestill callssetValueitself, so the mirror writes the same values a second time. That is harmless, and I left those calls alone to keep the diff small. ThesetValuecalls pass no options, so the mirror does not run the vest resolver on each store change. There is no URL prefill onmain.The selection is set as
{ value, label }. react-select matches the selected option byvalue, so the option'sgroupis not needed.#514 (
components/looking-glass-form.tsx)queryTargetvest rule now requires every target to contain a non-whitespace character:isArrayOf(enforce.isString().matches(/\S/)).isNotEmpty().[''], a whitespace-only target and an empty value among several targets (['192.0.2.1', '']) all fail withmessages.noInputforweb.text.queryTarget, the message an empty target already used. vest 3.2.8 has noisNotBlank, so the rule usesmatches.Targets can be several values in the store and the API, but the UI only ever sets one. I treated a list as invalid if any value is blank, rather than dropping the blank values, so the form never sends a target the user did not see. A field-less directive's
['null']target and select targets still pass.Tests
The #506 tests that documented both bugs now assert the fix:
New tests: "does not submit the previous query after the form is reset", "reports an empty value among several targets", and a
selections.queryTypeassertion in the store's "chooses the query type when only one directive is in common".With
origin/main's code and the #512 tests:Reverting only the
locationChangeselection fails the two selection tests; reverting only the mirror effect fails the submit and reset tests:With the old
queryTargetrule and the #514 tests:With both fixes:
biome format,biome lintandtsc --noEmitare clean;Test Files 25 passed (25),Tests 207 passed (207).Changelog
Notes
Found but not changed here:
form.queryTypeandselections.queryType. Validation catches it (inside(queryTypes)), but the select still shows the old option.locationChangechooses the only query type, it does not clear an existing target, unlike a manual query type change inhandleChange.reset()does not clear react-hook-form's errors, so an error shown before a title reset stays visible.Closes #512
Closes #514