fix(ui): keep the key edit team filter in sync with the organization field

This commit is contained in:
mateo-berri 2026-09-03 03:04:33 -07:00
parent e8d827a191
commit ce8179b2c0
2 changed files with 35 additions and 3 deletions

View file

@ -1468,6 +1468,40 @@ describe("KeyEditView", () => {
expect(screen.queryByRole("option", { name: /Beta/ })).not.toBeInTheDocument();
});
it("should re-scope teams when the edited key switches to another organization", async () => {
const sharedProps = {
teams: [
{ team_id: "team-a", team_alias: "Alpha", organization_id: "org-1" },
{ team_id: "team-b", team_alias: "Beta", organization_id: "org-2" },
],
onCancel: () => {},
onSubmit: async () => {},
accessToken: "",
userID: "",
userRole: "Admin",
premiumUser: false,
};
const { rerender } = renderWithProviders(
<KeyEditView keyData={{ ...MOCK_KEY_DATA, organization_id: null, org_id: "org-1" }} {...sharedProps} />,
);
await waitFor(() => {
expect(screen.getByLabelText("Organization")).toHaveValue("Engineering");
});
rerender(<KeyEditView keyData={{ ...MOCK_KEY_DATA, organization_id: null, org_id: "org-2" }} {...sharedProps} />);
await waitFor(() => {
expect(screen.getByLabelText("Organization")).toHaveValue("Sales");
});
await userEvent.click(screen.getByLabelText("Team ID"));
expect(await screen.findByRole("option", { name: /Beta/ })).toBeInTheDocument();
expect(screen.queryByRole("option", { name: /Alpha/ })).not.toBeInTheDocument();
});
it("should initialize organization from keyData", async () => {
const keyWithOrg = {
...MOCK_KEY_DATA,

View file

@ -28,7 +28,6 @@ import { routerSettingsEditorValue, routerSettingsUpdate } from "../common_compo
import { estimateTooltips, withNormalizedEstimates } from "./estimatedOutputTokens";
import {
currentValuePlaceholder,
keyOrganizationId,
keyTypeFromRoutes,
modelSentinelOptions,
parseAllowedRoutes,
@ -106,7 +105,6 @@ export function KeyEditView({
? mapInternalToDisplayNames(keyData.metadata.litellm_disabled_callbacks)
: [],
);
const [selectedOrganizationId, setSelectedOrganizationId] = useState<string | null>(keyOrganizationId(keyData));
const [autoRotationEnabled, setAutoRotationEnabled] = useState<boolean>(keyData.auto_rotate || false);
const [rotationInterval, setRotationInterval] = useState<string>(keyData.rotation_interval || "");
const [neverExpire, setNeverExpire] = useState<boolean>(!keyData.expires);
@ -135,6 +133,7 @@ export function KeyEditView({
return project?.project_alias ? `${project.project_alias} (${keyData.project_id})` : keyData.project_id;
})();
const selectedOrganizationId = form.watch("organization_id") ?? null;
const allowedRoutesValue = form.watch("allowed_routes");
const selectedModels = (form.watch("models") as string[] | undefined) ?? [];
const allowedRoutes = parseAllowedRoutes(allowedRoutesValue);
@ -306,7 +305,6 @@ export function KeyEditView({
const handleOrganizationChange = (setField: (value: string | undefined) => void, orgId: string | undefined) => {
setField(orgId);
setSelectedOrganizationId(orgId || null);
form.setValue("team_id", undefined);
};