From dcb789f3ed894f2ceee2eafa87ac7caf17344320 Mon Sep 17 00:00:00 2001 From: yuneng-jiang Date: Wed, 12 Aug 2026 12:42:21 -0700 Subject: [PATCH] refactor(ui): migrate policy impact popover to shadcn (#36653) * test(ui): characterize policy impact popover * refactor(ui): migrate policy impact popover to shadcn * test(ui): type policy impact mocks --- ui/litellm-dashboard/eslint-suppressions.json | 3 - .../_components/impact_popover.test.tsx | 153 +++++++++++------- .../policies/_components/impact_popover.tsx | 132 ++++++++------- 3 files changed, 170 insertions(+), 118 deletions(-) diff --git a/ui/litellm-dashboard/eslint-suppressions.json b/ui/litellm-dashboard/eslint-suppressions.json index 86da17e8f19..8a86305b4cb 100644 --- a/ui/litellm-dashboard/eslint-suppressions.json +++ b/ui/litellm-dashboard/eslint-suppressions.json @@ -1373,9 +1373,6 @@ }, "no-nested-ternary": { "count": 1 - }, - "no-restricted-imports": { - "count": 2 } }, "src/app/(dashboard)/policies/_components/impact_preview_alert.tsx": { diff --git a/ui/litellm-dashboard/src/app/(dashboard)/policies/_components/impact_popover.test.tsx b/ui/litellm-dashboard/src/app/(dashboard)/policies/_components/impact_popover.test.tsx index ecd26b24936..66f03577e20 100644 --- a/ui/litellm-dashboard/src/app/(dashboard)/policies/_components/impact_popover.test.tsx +++ b/ui/litellm-dashboard/src/app/(dashboard)/policies/_components/impact_popover.test.tsx @@ -1,7 +1,6 @@ import React from "react"; -import { screen, waitFor } from "@testing-library/react"; import userEvent from "@testing-library/user-event"; -import { renderWithProviders } from "@/../tests/test-utils"; +import { renderWithProviders, screen, waitFor } from "@/../tests/test-utils"; import { beforeEach, describe, expect, it, vi } from "vitest"; import * as networking from "@/components/networking"; import ImpactPopover from "./impact_popover"; @@ -9,6 +8,22 @@ import { PolicyAttachment } from "@/components/policies/types"; vi.mock("@/components/networking"); +interface LegacyIconProps extends React.ButtonHTMLAttributes { + icon: React.ComponentType; +} + +interface LegacyPopoverProps { + children: React.ReactElement>; + content: React.ReactNode; + onOpenChange?: (open: boolean) => void; + title?: React.ReactNode; +} + +interface LegacyTooltipProps { + children: React.ReactElement>; + title?: React.ReactNode; +} + vi.mock("@heroicons/react/outline", () => ({ EyeIcon: function EyeIcon() { return null; @@ -17,48 +32,42 @@ vi.mock("@heroicons/react/outline", () => ({ vi.mock("@tremor/react", async (importOriginal) => { const actual = await importOriginal(); - // Re-apply the global Button/Tooltip overrides from tests/setupTests.ts. A file-level - // vi.mock fully replaces the setup-level mock, so without this the real Tremor Button - // leaks through and its useTooltip(300) schedules a native setTimeout that can fire - // post-teardown -> "window is not defined". return { ...actual, - Icon: ({ icon: IconComp, onClick, className }: any) => - React.createElement( - "button", - { type: "button", onClick, className }, - IconComp?.displayName ?? IconComp?.name ?? "icon", - ), - Button: React.forwardRef(({ children, ...props }, ref) => - React.createElement("button", { ...props, ref }, children), - ), - Tooltip: ({ children }: { children?: React.ReactNode }) => React.createElement(React.Fragment, null, children), + Icon: React.forwardRef(({ icon: _icon, ...props }, ref) => ( + + } + /> + } + /> + View blast radius + + + + + Blast Radius + {loading ? ( +
+
+ ) : impact ? ( +
+ {impact.affected_keys_count === -1 ? ( +

Global scope — affects all keys and teams

+ ) : ( + <> +

+ {impact.affected_keys_count} key{impact.affected_keys_count !== 1 ? "s" : ""},{" "} + {impact.affected_teams_count} team{impact.affected_teams_count !== 1 ? "s" : ""}{" "} + affected +

+ {impact.sample_keys.length > 0 && ( +
+ Keys: + {impact.sample_keys.map((key: string) => ( + + {key} + + ))} +
+ )} + {impact.sample_teams.length > 0 && ( +
+ Teams: + {impact.sample_teams.map((team: string) => ( + + {team} + + ))} +
+ )} + {impact.affected_keys_count === 0 && impact.affected_teams_count === 0 && ( +

No keys or teams currently affected

+ )} + + )} +
+ ) : ( +

Click to load

+ )} +
); };