Skip to content

Commit 2ab3ec7

Browse files
authored
fix: auto-run search when opening auto-add modal (#148) (#151)
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.
1 parent dbb7fe9 commit 2ab3ec7

1 file changed

Lines changed: 14 additions & 10 deletions

File tree

packages/frontend/src/pages/Models.tsx

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -190,20 +190,14 @@ export const Models = () => {
190190
setEditingAlias({ ...editingAlias, targets: newTargets });
191191
};
192192

193-
const handleOpenAutoAdd = () => {
194-
setSubstring(editingAlias.id || '');
195-
setFilteredModels([]);
196-
setSelectedModels(new Set());
197-
setIsAutoAddModalOpen(true);
198-
};
199-
200-
const handleSearchModels = () => {
201-
if (!substring.trim()) {
193+
const handleSearchModels = (query?: string) => {
194+
const searchTerm = query !== undefined ? query : substring;
195+
if (!searchTerm.trim()) {
202196
setFilteredModels([]);
203197
return;
204198
}
205199

206-
const searchLower = substring.toLowerCase();
200+
const searchLower = searchTerm.toLowerCase();
207201

208202
const matches: Array<{ model: Model; provider: Provider }> = [];
209203
availableModels.forEach((model) => {
@@ -220,6 +214,16 @@ export const Models = () => {
220214
setFilteredModels(matches);
221215
};
222216

217+
const handleOpenAutoAdd = () => {
218+
const query = editingAlias.id || '';
219+
setSubstring(query);
220+
setSelectedModels(new Set());
221+
setIsAutoAddModalOpen(true);
222+
// Run search immediately with the pre-filled query so results appear
223+
// without requiring a manual button click (fixes #148).
224+
handleSearchModels(query);
225+
};
226+
223227
const handleToggleModelSelection = (modelId: string, providerId: string) => {
224228
const key = `${providerId}|${modelId}`;
225229
const newSelection = new Set(selectedModels);

0 commit comments

Comments
 (0)