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): stop the placeholder option clearing the picked member identity

Yuneng Jiang09ad62a40d09
diff --git a/ui/litellm-dashboard/src/components/common_components/user_search_modal.test.tsx b/ui/litellm-dashboard/src/components/common_components/user_search_modal.test.tsx
index 0e18c495145..d17948b599e 100644
--- a/ui/litellm-dashboard/src/components/common_components/user_search_modal.test.tsx
+++ b/ui/litellm-dashboard/src/components/common_components/user_search_modal.test.tsx
@@ -138,6 +138,29 @@ describe("UserSearchModal submit payload", () => {
expect(onSubmit.mock.calls[0][0]).toMatchObject({ role: "admin" });
});
+ it("keeps the picked identity when the option showing the current value is reselected", async () => {
+ const { user, onSubmit } = setup();
+
+ await searchByEmail(user, "pick");
+
+ vi.mocked(userFilterUICall).mockResolvedValue([] as never);
+ const idInput = screen.getByLabelText("User ID");
+ await user.click(idInput);
+ await user.type(idInput, "zzz");
+ await waitFor(() => expect(userFilterUICall).toHaveBeenCalledTimes(2), { timeout: 3000 });
+
+ await user.click(screen.getByPlaceholderText("Search by email"));
+ await user.click(await screen.findByRole("option", { name: "[email protected]" }));
+
+ await user.click(save());
+
+ await waitFor(() => expect(onSubmit).toHaveBeenCalledTimes(1));
+ expect(onSubmit.mock.calls[0][0]).toMatchObject({
+ user_email: "[email protected]",
+ user_id: "u-1",
+ });
+ });
+
it("does not submit on Enter in any field, while the button still does", async () => {
const { user, onSubmit } = setup();
diff --git a/ui/litellm-dashboard/src/components/common_components/user_search_modal.tsx b/ui/litellm-dashboard/src/components/common_components/user_search_modal.tsx
index 1a55fa18191..801d19244f8 100644
--- a/ui/litellm-dashboard/src/components/common_components/user_search_modal.tsx
+++ b/ui/litellm-dashboard/src/components/common_components/user_search_modal.tsx
@@ -29,7 +29,7 @@ interface User {
interface UserOption {
label: string;
value: string;
- user: User;
+ user: User | null;
}
interface Role {
@@ -122,10 +122,9 @@ const UserSearchModal: React.FC<UserSearchModalProps> = ({
};
const handleSelect = (option: UserOption | null): void => {
- if (option === null) return;
- const selectedUser = option.user;
- form.setValue("user_email", selectedUser.user_email);
- form.setValue("user_id", selectedUser.user_id);
+ if (option?.user == null) return;
+ form.setValue("user_email", option.user.user_email);
+ form.setValue("user_id", option.user.user_id);
};
const handleSubmit = async (values: FormValues): Promise<void> => {
@@ -150,7 +149,7 @@ const UserSearchModal: React.FC<UserSearchModalProps> = ({
const optionsFor = (fieldName: "user_email" | "user_id", value: string | undefined): UserOption[] => {
const visible = selectedField === fieldName ? userOptions : [];
if (value == null || value === "" || visible.some((option) => option.value === value)) return visible;
- return [{ label: value, value, user: { user_id: "", user_email: "" } }, ...visible];
+ return [{ label: value, value, user: null }, ...visible];
};
const renderUserSearch = (