-
-
Notifications
You must be signed in to change notification settings - Fork 11.6k
refactor(ui): consolidate Add/Edit credential modals into one CredentialModal #32572
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ryan-crabbe-berri
merged 5 commits into
litellm_internal_staging
from
litellm_dedup_credential_modal
Jul 18, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7f4d014
refactor(ui): consolidate Add/Edit credential modals into one Credent…
ryan-crabbe-berri 3d2ca23
refactor(ui): derive credential name disabled state from mode, not data
ryan-crabbe-berri 7913a3a
Merge remote-tracking branch 'origin/litellm_internal_staging' into l…
ryan-crabbe-berri d1bb8db
refactor(ui): prefill credential form declaratively instead of via us…
ryan-crabbe-berri 71fffe1
Merge remote-tracking branch 'origin/litellm_internal_staging' into l…
ryan-crabbe-berri File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 0 additions & 108 deletions
108
ui/litellm-dashboard/src/components/model_add/AddCredentialModal.test.tsx
This file was deleted.
Oops, something went wrong.
140 changes: 140 additions & 0 deletions
140
ui/litellm-dashboard/src/components/model_add/CredentialModal.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,140 @@ | ||
| import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; | ||
| import { render, screen, waitFor } from "@testing-library/react"; | ||
| import { describe, expect, it, vi } from "vitest"; | ||
| import { Providers } from "../provider_info_helpers"; | ||
| import { CredentialItem } from "../networking"; | ||
| import CredentialModal from "./CredentialModal"; | ||
|
|
||
| vi.mock("../networking", async () => { | ||
| const actual = await vi.importActual("../networking"); | ||
| return { | ||
| ...actual, | ||
| getProviderCreateMetadata: vi.fn().mockResolvedValue([ | ||
| { | ||
| provider: "OpenAI", | ||
| provider_display_name: Providers.OpenAI, | ||
| litellm_provider: "openai", | ||
| default_model_placeholder: "gpt-3.5-turbo", | ||
| credential_fields: [ | ||
| { | ||
| key: "api_key", | ||
| label: "OpenAI API Key", | ||
| field_type: "password", | ||
| required: true, | ||
| }, | ||
| { | ||
| key: "api_base", | ||
| label: "API Base", | ||
| field_type: "text", | ||
| placeholder: "https://api.openai.com/v1", | ||
| }, | ||
| ], | ||
| }, | ||
| { | ||
| provider: "Anthropic", | ||
| provider_display_name: Providers.Anthropic, | ||
| litellm_provider: "anthropic", | ||
| default_model_placeholder: "claude-3-opus-20240229", | ||
| credential_fields: [ | ||
| { | ||
| key: "api_key", | ||
| label: "Anthropic API Key", | ||
| field_type: "password", | ||
| required: true, | ||
| }, | ||
| ], | ||
| }, | ||
| ]), | ||
| }; | ||
| }); | ||
|
|
||
| const createQueryClient = () => | ||
| new QueryClient({ | ||
| defaultOptions: { | ||
| queries: { | ||
| retry: false, | ||
| gcTime: 0, | ||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| const mockUploadProps = { | ||
| beforeUpload: vi.fn(), | ||
| onChange: vi.fn(), | ||
| }; | ||
|
|
||
| const mockCredential: CredentialItem = { | ||
| credential_name: "test-credential", | ||
| credential_values: { | ||
| api_key: "test-api-key", | ||
| api_base: "https://api.test.com", | ||
| }, | ||
| credential_info: { | ||
| custom_llm_provider: Providers.OpenAI, | ||
| }, | ||
| }; | ||
|
|
||
| const renderModal = (props: Partial<React.ComponentProps<typeof CredentialModal>> = {}) => | ||
| render( | ||
| <QueryClientProvider client={createQueryClient()}> | ||
| <CredentialModal | ||
| open={true} | ||
| mode="add" | ||
| onCancel={vi.fn()} | ||
| onSubmit={vi.fn()} | ||
| uploadProps={mockUploadProps} | ||
| {...props} | ||
| /> | ||
| </QueryClientProvider>, | ||
| ); | ||
|
|
||
| describe("CredentialModal", () => { | ||
| describe("add mode", () => { | ||
| it("renders the add title and an editable credential name", () => { | ||
| renderModal({ mode: "add" }); | ||
|
|
||
| expect(screen.getByText("Add New Credential")).toBeInTheDocument(); | ||
| expect(screen.getByText("Add Credential")).toBeInTheDocument(); | ||
| const nameInput = screen.getByLabelText("Credential Name:") as HTMLInputElement; | ||
| expect(nameInput.value).toBe(""); | ||
| expect(nameInput.disabled).toBe(false); | ||
| }); | ||
|
|
||
| it("shows provider-specific fields for the selected provider", async () => { | ||
| renderModal({ mode: "add" }); | ||
|
|
||
| await waitFor(() => { | ||
| expect(screen.getByLabelText("OpenAI API Key")).toBeInTheDocument(); | ||
| expect(screen.getByPlaceholderText("https://api.openai.com/v1")).toBeInTheDocument(); | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe("edit mode", () => { | ||
| it("renders the edit title and update button", () => { | ||
| renderModal({ mode: "edit", existingCredential: mockCredential }); | ||
|
|
||
| expect(screen.getByText("Edit Credential")).toBeInTheDocument(); | ||
| expect(screen.getByText("Update Credential")).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it("prefills the credential name and disables it", async () => { | ||
| renderModal({ mode: "edit", existingCredential: mockCredential }); | ||
|
|
||
| await waitFor(() => { | ||
| const nameInput = screen.getByLabelText("Credential Name:") as HTMLInputElement; | ||
| expect(nameInput.value).toBe("test-credential"); | ||
| expect(nameInput.disabled).toBe(true); | ||
| }); | ||
| }); | ||
|
|
||
| it("disables the name from the mode, not the credential's name value", () => { | ||
| renderModal({ | ||
| mode: "edit", | ||
| existingCredential: { ...mockCredential, credential_name: "" }, | ||
| }); | ||
|
|
||
| expect((screen.getByLabelText("Credential Name:") as HTMLInputElement).disabled).toBe(true); | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.