Skip to content

fix: auto-run search when opening auto-add modal#151

Merged
mcowger merged 1 commit intomainfrom
fix/auto-add-modal-search-not-triggered
Apr 5, 2026
Merged

fix: auto-run search when opening auto-add modal#151
mcowger merged 1 commit intomainfrom
fix/auto-add-modal-search-not-triggered

Conversation

@mcowger
Copy link
Copy Markdown
Owner

@mcowger mcowger commented Apr 3, 2026

Fixes #148

Problem

When clicking the auto-add target button, the modal opens with the alias ID pre-filled in the search input, but no results are shown. The user has to manually click the Search button to get results, which is not obvious.

Root cause: handleOpenAutoAdd() called setSubstring() and setIsAutoAddModalOpen(true) but never executed the search. Calling handleSearchModels() immediately after setSubstring() would also not work since React state updates are batched — substring still holds the old value at that point.

Fix

  • handleSearchModels now accepts an optional query parameter. When supplied it uses that value directly instead of reading from the (potentially stale) substring state. Existing callsites (Enter key, Search button) are unaffected — they still call it with no args.
  • handleOpenAutoAdd captures the query in a local variable, sets state, then calls handleSearchModels(query) directly — no timing issues, no duplicated logic.
  • Moved handleSearchModels above handleOpenAutoAdd so the const reference is valid at the call site.

Behaviour after fix

Opening the auto-add modal immediately shows matching models for the pre-filled alias ID. The Search button and Enter key continue to work as before.

When handleOpenAutoAdd() pre-fills the substring input with the alias
ID, the search was never executed — the modal opened with the query
visible but results empty, requiring a manual click of the Search button.

Fix: accept an optional query param in handleSearchModels() so the
caller can supply the value directly rather than relying on the React
state that hasn't updated yet. handleOpenAutoAdd() now passes the query
string inline, triggering results immediately on modal open.

Also move handleSearchModels above handleOpenAutoAdd so the const
reference is valid at the call site.
@mcowger mcowger merged commit 2ab3ec7 into main Apr 5, 2026
4 of 5 checks passed
@mcowger mcowger deleted the fix/auto-add-modal-search-not-triggered branch April 5, 2026 00:23
github-actions bot pushed a commit that referenced this pull request Apr 6, 2026
When handleOpenAutoAdd() pre-fills the substring input with the alias
ID, the search was never executed — the modal opened with the query
visible but results empty, requiring a manual click of the Search button.

Fix: accept an optional query param in handleSearchModels() so the
caller can supply the value directly rather than relying on the React
state that hasn't updated yet. handleOpenAutoAdd() now passes the query
string inline, triggering results immediately on modal open.

Also move handleSearchModels above handleOpenAutoAdd so the const
reference is valid at the call site.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[UI Enhancement ] When clicked auto add model apply search query right away or indicate user need to click button for it to work

1 participant