Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

fix(ui): keep a deleted-from search query instead of blanking the box

Yuneng Jiang02046fb7b73b
diff --git a/ui/litellm-dashboard/src/components/shared/PaginatedSearchSelect.test.tsx b/ui/litellm-dashboard/src/components/shared/PaginatedSearchSelect.test.tsx
index c37589f63f5..d248cf311cc 100644
--- a/ui/litellm-dashboard/src/components/shared/PaginatedSearchSelect.test.tsx
+++ b/ui/litellm-dashboard/src/components/shared/PaginatedSearchSelect.test.tsx
@@ -361,4 +361,32 @@ describe("PaginatedSearchSelect", () => {
await user.click(screen.getByRole("combobox"));
expect(await screen.findByTestId("paginated-search-select-loading-more")).toBeInTheDocument();
});
+
+ it("queries the trimmed label when a character is deleted from the end of the selection", async () => {
+ const user = userEvent.setup();
+ const onSearchChange = vi.fn();
+ renderSelect({ onSearchChange, value: "alias-alpha" });
+
+ const input = screen.getByRole("combobox") as HTMLInputElement;
+ input.focus();
+ input.setSelectionRange(input.value.length, input.value.length);
+ await user.keyboard("{Backspace}");
+
+ expect(input).toHaveValue("alias-alph");
+ await waitFor(() => expect(onSearchChange).toHaveBeenLastCalledWith("alias-alph"));
+ });
+
+ it("queries what is left when a character is deleted from inside the selection", async () => {
+ const user = userEvent.setup();
+ const onSearchChange = vi.fn();
+ renderSelect({ onSearchChange, value: "alias-alpha" });
+
+ const input = screen.getByRole("combobox") as HTMLInputElement;
+ input.focus();
+ input.setSelectionRange(6, 6);
+ await user.keyboard("{Backspace}");
+
+ expect(input).toHaveValue("aliasalpha");
+ await waitFor(() => expect(onSearchChange).toHaveBeenLastCalledWith("aliasalpha"));
+ });
});
diff --git a/ui/litellm-dashboard/src/components/shared/PaginatedSearchSelect.tsx b/ui/litellm-dashboard/src/components/shared/PaginatedSearchSelect.tsx
index 0f25260aad0..4b7ef7401c7 100644
--- a/ui/litellm-dashboard/src/components/shared/PaginatedSearchSelect.tsx
+++ b/ui/litellm-dashboard/src/components/shared/PaginatedSearchSelect.tsx
@@ -50,6 +50,11 @@ const typedInsertion = (previous: string, next: string): string => {
return next.slice(start, next.length - end);
};
+const editedQuery = (label: string, next: string): string => {
+ const inserted = typedInsertion(label, next);
+ return inserted === "" && next !== label ? next : inserted;
+};
+
export function PaginatedSearchSelect({
options,
value,
@@ -101,7 +106,7 @@ export function PaginatedSearchSelect({
const replacedWholeInput = wholeSelectionRef.current;
wholeSelectionRef.current = false;
handleInputValueChange(
- typedQuery === null && !replacedWholeInput ? typedInsertion(selected?.label ?? "", next) : next,
+ typedQuery === null && !replacedWholeInput ? editedQuery(selected?.label ?? "", next) : next,
reason,
);
};