The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
refactor(ui): migrate prompts list page to shadcn (#34289)
yuneng-jiangd7bde69b991e
diff --git a/ui/litellm-dashboard/eslint-suppressions.json b/ui/litellm-dashboard/eslint-suppressions.jsonindex d4826ba47b1..f8927becba0 100644--- a/ui/litellm-dashboard/eslint-suppressions.json+++ b/ui/litellm-dashboard/eslint-suppressions.json@@ -949,9 +949,6 @@"no-nested-ternary": {"count": 1},- "no-restricted-imports": {- "count": 1- },"react-hooks/set-state-in-effect": {"count": 1}diff --git a/ui/litellm-dashboard/src/app/(dashboard)/prompts/_components/index.test.tsx b/ui/litellm-dashboard/src/app/(dashboard)/prompts/_components/index.test.tsxindex 99c58e2b98f..d6a4aaea2e1 100644--- a/ui/litellm-dashboard/src/app/(dashboard)/prompts/_components/index.test.tsx+++ b/ui/litellm-dashboard/src/app/(dashboard)/prompts/_components/index.test.tsx@@ -1,7 +1,8 @@-import { render, screen } from "@testing-library/react";+import { render, screen, waitFor } from "@testing-library/react";+import userEvent, { PointerEventsCheckLevel } from "@testing-library/user-event";import { beforeEach, describe, expect, it, vi } from "vitest";-import { getPromptsList } from "@/components/networking";+import { deletePromptCall, getPromptsList } from "@/components/networking";import PromptsPanel from "./index";@@ -12,20 +13,39 @@ vi.mock("@/components/networking", () => ({vi.mock("./PromptTable", () => ({__esModule: true,- default: ({ isLoading }: { isLoading: boolean }) => (- <div data-testid="prompt-table">{isLoading ? "table-loading" : "table-loaded"}</div>+ default: ({+ isLoading,+ onDeleteClick,+ }: {+ isLoading: boolean;+ onDeleteClick: (id: string, name: string) => void;+ }) => (+ <div data-testid="prompt-table">+ {isLoading ? "table-loading" : "table-loaded"}+ <button type="button" onClick={() => onDeleteClick("prompt-1", "my-prompt")}>+ row-delete+ </button>+ </div>),}));-vi.mock("./prompt_info", () => ({ __esModule: true, default: () => null }));-vi.mock("./add_prompt_form", () => ({ __esModule: true, default: () => null }));-vi.mock("./prompt_editor_view", () => ({ __esModule: true, default: () => null }));+vi.mock("./prompt_info", () => ({ __esModule: true, default: () => <div>prompt-info-view</div> }));+vi.mock("./add_prompt_form", () => ({+ __esModule: true,+ default: ({ visible }: { visible: boolean }) => (visible ? <div>add-prompt-form</div> : null),+}));+vi.mock("./prompt_editor_view", () => ({ __esModule: true, default: () => <div>prompt-editor-view</div> }));const mockGetPromptsList = vi.mocked(getPromptsList);+const mockDeletePromptCall = vi.mocked(deletePromptCall);++const renderPanel = (userRole?: string) =>+ render(<PromptsPanel accessToken="sk-test" userRole={userRole ?? "Admin"} />);describe("PromptsPanel loading state", () => {beforeEach(() => {vi.clearAllMocks();+ mockGetPromptsList.mockResolvedValue({ prompts: [] } as never);});it("should resolve the loading state when accessToken is null instead of showing the skeleton forever", async () => {@@ -39,7 +59,7 @@ describe("PromptsPanel loading state", () => {mockGetPromptsList.mockReturnValue(new Promise((resolve) => {resolveFetch = resolve;- }),+ }) as never,);render(<PromptsPanel accessToken="sk-test" userRole="Admin" />);expect(screen.getByText("table-loading")).toBeInTheDocument();@@ -49,3 +69,134 @@ describe("PromptsPanel loading state", () => {expect(mockGetPromptsList).toHaveBeenCalledWith("sk-test", undefined);});});++describe("PromptsPanel toolbar", () => {+ beforeEach(() => {+ vi.clearAllMocks();+ mockGetPromptsList.mockResolvedValue({ prompts: [] } as never);+ });++ it("should offer both create actions to a proxy admin", async () => {+ renderPanel("Admin");++ expect(await screen.findByRole("button", { name: /add new prompt/i })).toBeEnabled();+ expect(screen.getByRole("button", { name: /upload \.prompt file/i })).toBeEnabled();+ });++ it("should hide both create actions from a read-only viewer", async () => {+ renderPanel("Admin Viewer");++ expect(await screen.findByText("table-loaded")).toBeInTheDocument();+ expect(screen.queryByRole("button", { name: /add new prompt/i })).not.toBeInTheDocument();+ expect(screen.queryByRole("button", { name: /upload \.prompt file/i })).not.toBeInTheDocument();+ });++ it("should open the editor view when the add action is used", async () => {+ const user = userEvent.setup();+ renderPanel("Admin");++ await user.click(await screen.findByRole("button", { name: /add new prompt/i }));++ expect(screen.getByText("prompt-editor-view")).toBeInTheDocument();+ expect(screen.queryByTestId("prompt-table")).not.toBeInTheDocument();+ });++ it("should open the upload form when the upload action is used", async () => {+ const user = userEvent.setup();+ renderPanel("Admin");++ expect(screen.queryByText("add-prompt-form")).not.toBeInTheDocument();+ await user.click(await screen.findByRole("button", { name: /upload \.prompt file/i }));++ expect(screen.getByText("add-prompt-form")).toBeInTheDocument();+ });++ it("should refetch scoped to the environment picked in the filter", async () => {+ const user = userEvent.setup();+ renderPanel("Admin");+ await screen.findByText("table-loaded");++ expect(screen.getByText("All Environments")).toBeInTheDocument();++ await user.click(screen.getByRole("combobox"));+ await user.click(await screen.findByText("Production"));++ await waitFor(() => expect(mockGetPromptsList).toHaveBeenLastCalledWith("sk-test", "production"));+ });++ it("should show the picked environment by label and clear back to the unfiltered list", async () => {+ // Base UI's exit animation never completes in jsdom, so the closing popup keeps+ // pointer-events: none and blocks the second open. The clicks still dispatch.+ const user = userEvent.setup({ pointerEventsCheck: PointerEventsCheckLevel.Never });+ renderPanel("Admin");+ await screen.findByText("table-loaded");++ await user.click(screen.getByRole("combobox"));+ await user.click(await screen.findByText("Production"));+ await waitFor(() => expect(screen.getByRole("combobox")).toHaveTextContent("Production"));++ await user.click(screen.getByRole("combobox"));+ await user.click(await screen.findByText("All Environments"));++ await waitFor(() => expect(screen.getByRole("combobox")).toHaveTextContent("All Environments"));+ await waitFor(() => expect(mockGetPromptsList).toHaveBeenLastCalledWith("sk-test", undefined));+ });+});++describe("PromptsPanel delete confirmation", () => {+ beforeEach(() => {+ vi.clearAllMocks();+ mockGetPromptsList.mockResolvedValue({ prompts: [] } as never);+ mockDeletePromptCall.mockResolvedValue(undefined as never);+ });++ it("should not delete until the confirmation is accepted", async () => {+ const user = userEvent.setup();+ renderPanel("Admin");++ await user.click(await screen.findByRole("button", { name: "row-delete" }));++ expect(await screen.findByText(/delete prompt: my-prompt/i)).toBeInTheDocument();+ expect(screen.getByText(/cannot be undone/i)).toBeInTheDocument();+ expect(mockDeletePromptCall).not.toHaveBeenCalled();++ await user.click(screen.getByRole("button", { name: /^delete$/i }));++ await waitFor(() => expect(mockDeletePromptCall).toHaveBeenCalledWith("sk-test", "prompt-1"));+ });++ it("should abandon the delete when the confirmation is dismissed", async () => {+ const user = userEvent.setup();+ renderPanel("Admin");++ await user.click(await screen.findByRole("button", { name: "row-delete" }));+ await screen.findByText(/delete prompt: my-prompt/i);++ await user.click(screen.getByRole("button", { name: /cancel/i }));++ await waitFor(() => expect(screen.queryByText(/delete prompt: my-prompt/i)).not.toBeInTheDocument());+ expect(mockDeletePromptCall).not.toHaveBeenCalled();+ });++ it("should keep the confirmation up while the delete request is still in flight", async () => {+ const user = userEvent.setup();+ let finishDelete: () => void = () => {};+ mockDeletePromptCall.mockReturnValue(+ new Promise<void>((resolve) => {+ finishDelete = () => resolve();+ }) as never,+ );+ renderPanel("Admin");++ await user.click(await screen.findByRole("button", { name: "row-delete" }));+ await screen.findByText(/delete prompt: my-prompt/i);+ await user.click(screen.getByRole("button", { name: /^delete$/i }));+ await waitFor(() => expect(mockDeletePromptCall).toHaveBeenCalledWith("sk-test", "prompt-1"));++ await user.keyboard("{Escape}");+ expect(screen.getByText(/delete prompt: my-prompt/i)).toBeInTheDocument();++ finishDelete();+ await waitFor(() => expect(screen.queryByText(/delete prompt: my-prompt/i)).not.toBeInTheDocument());+ });+});diff --git a/ui/litellm-dashboard/src/app/(dashboard)/prompts/_components/index.tsx b/ui/litellm-dashboard/src/app/(dashboard)/prompts/_components/index.tsxindex de461ebd86d..9bebabb8cf2 100644--- a/ui/litellm-dashboard/src/app/(dashboard)/prompts/_components/index.tsx+++ b/ui/litellm-dashboard/src/app/(dashboard)/prompts/_components/index.tsx@@ -1,7 +1,6 @@import React, { useState, useEffect } from "react";-import { Button } from "@tremor/react";-import { Modal, Select } from "antd";+import { Plus, Upload } from "lucide-react";import { getPromptsList, PromptSpec, ListPromptsResponse, deletePromptCall } from "@/components/networking";import PromptTable from "./PromptTable";import PromptInfoView from "./prompt_info";@@ -9,6 +8,28 @@ import AddPromptForm from "./add_prompt_form";import PromptEditorView from "./prompt_editor_view";import NotificationsManager from "@/components/molecules/notifications_manager";import { isAdminRole, isProxyAdminRole } from "@/utils/roles";+import { Button } from "@/components/ui/button";+import {+ AlertDialog,+ AlertDialogCancel,+ AlertDialogContent,+ AlertDialogDescription,+ AlertDialogFooter,+ AlertDialogHeader,+ AlertDialogTitle,+} from "@/components/ui/alert-dialog";+import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";++const ALL_ENVIRONMENTS_LABEL = "All Environments";++const ENVIRONMENT_OPTIONS = [+ { label: "Development", value: "development" },+ { label: "Staging", value: "staging" },+ { label: "Production", value: "production" },+];++// SelectValue falls back to the raw value unless the root can map it to a label.+const ENVIRONMENT_ITEMS = [{ label: ALL_ENVIRONMENTS_LABEL, value: null }, ...ENVIRONMENT_OPTIONS];interface PromptsProps {accessToken: string | null;@@ -141,26 +162,33 @@ const PromptsPanel: React.FC<PromptsProps> = ({ accessToken, userRole }) => {{canModify && (<><Button onClick={handleAddPrompt} disabled={!accessToken}>- + Add New Prompt+ <Plus />+ Add New Prompt</Button><Button onClick={handleAddPromptFromFile} disabled={!accessToken} variant="secondary">+ <Upload />Upload .prompt File</Button></>)}</div><Select- placeholder="All Environments"- allowClear- value={selectedEnvironment}- onChange={(value) => setSelectedEnvironment(value)}- style={{ width: 180 }}- options={[- { label: "Development", value: "development" },- { label: "Staging", value: "staging" },- { label: "Production", value: "production" },- ]}- />+ items={ENVIRONMENT_ITEMS}+ value={selectedEnvironment ?? null}+ onValueChange={(value) => setSelectedEnvironment((value as string | null) ?? undefined)}+ >+ <SelectTrigger className="w-[180px]">+ <SelectValue placeholder={ALL_ENVIRONMENTS_LABEL} />+ </SelectTrigger>+ <SelectContent>+ <SelectItem value={null}>{ALL_ENVIRONMENTS_LABEL}</SelectItem>+ {ENVIRONMENT_OPTIONS.map((option) => (+ <SelectItem key={option.value} value={option.value}>+ {option.label}+ </SelectItem>+ ))}+ </SelectContent>+ </Select></div><PromptTable@@ -182,18 +210,27 @@ const PromptsPanel: React.FC<PromptsProps> = ({ accessToken, userRole }) => {/>{promptToDelete && (- <Modal- title="Delete Prompt"- open={promptToDelete !== null}- onOk={handleDeleteConfirm}- onCancel={handleDeleteCancel}- confirmLoading={isDeleting}- okText="Delete"- okButtonProps={{ danger: true }}+ <AlertDialog+ open+ onOpenChange={(open) => {+ if (!open && !isDeleting) handleDeleteCancel();+ }}>- <p>Are you sure you want to delete prompt: {promptToDelete.name} ?</p>- <p>This action cannot be undone.</p>- </Modal>+ <AlertDialogContent>+ <AlertDialogHeader>+ <AlertDialogTitle>Delete Prompt</AlertDialogTitle>+ <AlertDialogDescription>+ Are you sure you want to delete prompt: {promptToDelete.name} ? This action cannot be undone.+ </AlertDialogDescription>+ </AlertDialogHeader>+ <AlertDialogFooter>+ <AlertDialogCancel disabled={isDeleting}>Cancel</AlertDialogCancel>+ <Button variant="destructive" onClick={handleDeleteConfirm} disabled={isDeleting}>+ Delete+ </Button>+ </AlertDialogFooter>+ </AlertDialogContent>+ </AlertDialog>)}</div>);