From 2223084ce64d19d307a1645fc6109725a69285d4 Mon Sep 17 00:00:00 2001 From: mateo-berri <277851410+mateo-berri@users.noreply.github.com> Date: Thu, 3 Sep 2026 03:15:47 -0700 Subject: [PATCH] fix(ui): drop the leftover organization setter calls in the key edit team handler The previous commit derived the organization from the form and removed the useState behind it, but handleTeamChange still called the deleted setter, so the dashboard build failed to type check and picking a team with an organization threw at runtime. The form.setValue calls next to them already carry the organization, so the setter calls only had to go. Adds a test that picks a team with an organization and asserts the form adopts and submits it. --- .../templates/key_edit_view.test.tsx | 37 +++++++++++++++++++ .../components/templates/key_edit_view.tsx | 2 - 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/ui/litellm-dashboard/src/components/templates/key_edit_view.test.tsx b/ui/litellm-dashboard/src/components/templates/key_edit_view.test.tsx index feb777f32a9..8c3ae003e81 100644 --- a/ui/litellm-dashboard/src/components/templates/key_edit_view.test.tsx +++ b/ui/litellm-dashboard/src/components/templates/key_edit_view.test.tsx @@ -1502,6 +1502,43 @@ describe("KeyEditView", () => { expect(screen.queryByRole("option", { name: /Alpha/ })).not.toBeInTheDocument(); }); + it("should adopt the organization of a team picked in the form", async () => { + const onSubmitMock = vi.fn().mockResolvedValue(undefined); + + renderWithProviders( + {}} + onSubmit={onSubmitMock} + accessToken="" + userID="" + userRole="Admin" + premiumUser={false} + />, + ); + + await screen.findByRole("button", { name: /save changes/i }); + expect(screen.getByLabelText("Organization")).toHaveValue(""); + + await userEvent.click(screen.getByLabelText("Team ID")); + await userEvent.click(await screen.findByRole("option", { name: /Beta/ })); + + await waitFor(() => { + expect(screen.getByLabelText("Organization")).toHaveValue("Sales"); + }); + + await userEvent.click(screen.getByRole("button", { name: /save changes/i })); + + await waitFor(() => { + expect(onSubmitMock).toHaveBeenCalled(); + }); + expect(onSubmitMock.mock.calls[0][0].organization_id).toBe("org-2"); + }); + it("should initialize organization from keyData", async () => { const keyWithOrg = { ...MOCK_KEY_DATA, diff --git a/ui/litellm-dashboard/src/components/templates/key_edit_view.tsx b/ui/litellm-dashboard/src/components/templates/key_edit_view.tsx index 3242aee49bc..1a01375fca4 100644 --- a/ui/litellm-dashboard/src/components/templates/key_edit_view.tsx +++ b/ui/litellm-dashboard/src/components/templates/key_edit_view.tsx @@ -312,10 +312,8 @@ export function KeyEditView({ setField(teamId); const selectedTeam = teams?.find((t) => t.team_id === teamId) || null; if (selectedTeam?.organization_id) { - setSelectedOrganizationId(selectedTeam.organization_id); form.setValue("organization_id", selectedTeam.organization_id); } else if (!teamId) { - setSelectedOrganizationId(null); form.setValue("organization_id", undefined); } };