mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-17 04:34:25 +00:00
fix(ui): trim credential_alias in CredentialModal so whitespace-only input clears the alias
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
parent
378c24b647
commit
f37317e28a
2 changed files with 33 additions and 1 deletions
|
|
@ -196,5 +196,33 @@ describe("CredentialModal", () => {
|
|||
await waitFor(() => expect(onSubmit).toHaveBeenCalled());
|
||||
expect(onSubmit.mock.calls[0][0].credential_alias).toBeNull();
|
||||
});
|
||||
|
||||
it("trims the alias before submitting in add mode", async () => {
|
||||
const user = userEvent.setup({ pointerEventsCheck: PointerEventsCheckLevel.Never });
|
||||
const onSubmit = vi.fn();
|
||||
renderModal({ mode: "add", onSubmit });
|
||||
|
||||
await fillRequiredAddFields(user);
|
||||
fireEvent.change(screen.getByLabelText("Alias:"), { target: { value: " Prod " } });
|
||||
fireEvent.click(screen.getByRole("button", { name: "Add Credential" }));
|
||||
|
||||
await waitFor(() => expect(onSubmit).toHaveBeenCalled());
|
||||
expect(onSubmit.mock.calls[0][0]).toMatchObject({ credential_name: "new-cred", credential_alias: "Prod" });
|
||||
});
|
||||
|
||||
it("submits credential_alias: null when the alias is whitespace-only in edit mode", async () => {
|
||||
const onSubmit = vi.fn();
|
||||
renderModal({
|
||||
mode: "edit",
|
||||
onSubmit,
|
||||
existingCredential: { ...mockCredential, credential_alias: "Prod OpenAI" },
|
||||
});
|
||||
|
||||
fireEvent.change(screen.getByLabelText("Alias:"), { target: { value: " " } });
|
||||
fireEvent.click(screen.getByRole("button", { name: "Update Credential" }));
|
||||
|
||||
await waitFor(() => expect(onSubmit).toHaveBeenCalled());
|
||||
expect(onSubmit.mock.calls[0][0].credential_alias).toBeNull();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -72,7 +72,11 @@ export default function CredentialModal({
|
|||
return;
|
||||
}
|
||||
const values = projectMountedValues(registry, form.getValues);
|
||||
const filteredValues = Object.entries(values).reduce((acc, [key, value]) => {
|
||||
const trimmedValues =
|
||||
typeof values.credential_alias === "string"
|
||||
? { ...values, credential_alias: values.credential_alias.trim() }
|
||||
: values;
|
||||
const filteredValues = Object.entries(trimmedValues).reduce((acc, [key, value]) => {
|
||||
if (value !== "" && value !== undefined && value !== null) {
|
||||
acc[key] = value;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue