From 0d7194565cc53640cded28700ec6bcb4bdd3c840 Mon Sep 17 00:00:00 2001 From: mcowger Date: Fri, 3 Apr 2026 12:12:04 -0700 Subject: [PATCH] fix: auto-run search when opening auto-add modal (#148) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- packages/frontend/src/pages/Models.tsx | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/packages/frontend/src/pages/Models.tsx b/packages/frontend/src/pages/Models.tsx index 31edd227..d405b9e1 100644 --- a/packages/frontend/src/pages/Models.tsx +++ b/packages/frontend/src/pages/Models.tsx @@ -190,20 +190,14 @@ export const Models = () => { setEditingAlias({ ...editingAlias, targets: newTargets }); }; - const handleOpenAutoAdd = () => { - setSubstring(editingAlias.id || ''); - setFilteredModels([]); - setSelectedModels(new Set()); - setIsAutoAddModalOpen(true); - }; - - const handleSearchModels = () => { - if (!substring.trim()) { + const handleSearchModels = (query?: string) => { + const searchTerm = query !== undefined ? query : substring; + if (!searchTerm.trim()) { setFilteredModels([]); return; } - const searchLower = substring.toLowerCase(); + const searchLower = searchTerm.toLowerCase(); const matches: Array<{ model: Model; provider: Provider }> = []; availableModels.forEach((model) => { @@ -220,6 +214,16 @@ export const Models = () => { setFilteredModels(matches); }; + const handleOpenAutoAdd = () => { + const query = editingAlias.id || ''; + setSubstring(query); + setSelectedModels(new Set()); + setIsAutoAddModalOpen(true); + // Run search immediately with the pre-filled query so results appear + // without requiring a manual button click (fixes #148). + handleSearchModels(query); + }; + const handleToggleModelSelection = (modelId: string, providerId: string) => { const key = `${providerId}|${modelId}`; const newSelection = new Set(selectedModels);