diff --git a/ui/litellm-dashboard/eslint-suppressions.json b/ui/litellm-dashboard/eslint-suppressions.json index 51a7a196d0a..b9e64c88c8a 100644 --- a/ui/litellm-dashboard/eslint-suppressions.json +++ b/ui/litellm-dashboard/eslint-suppressions.json @@ -566,9 +566,6 @@ "src/app/(dashboard)/mcp-servers/_components/mcp_connect.tsx": { "local/filename-pascal-case": { "count": 1 - }, - "react-hooks/static-components": { - "count": 4 } }, "src/app/(dashboard)/mcp-servers/_components/mcp_connection_status.tsx": { @@ -622,9 +619,6 @@ }, "no-nested-ternary": { "count": 1 - }, - "react-hooks/set-state-in-effect": { - "count": 2 } }, "src/app/(dashboard)/mcp-servers/_components/mcp_tool_configuration.tsx": { @@ -636,9 +630,6 @@ "local/filename-pascal-case": { "count": 1 }, - "local/no-complex-jsx-arrow": { - "count": 1 - }, "no-nested-ternary": { "count": 1 }, diff --git a/ui/litellm-dashboard/src/app/(dashboard)/mcp-servers/_components/MCPSubmissionsTab.test.tsx b/ui/litellm-dashboard/src/app/(dashboard)/mcp-servers/_components/MCPSubmissionsTab.test.tsx new file mode 100644 index 00000000000..a0744af1601 --- /dev/null +++ b/ui/litellm-dashboard/src/app/(dashboard)/mcp-servers/_components/MCPSubmissionsTab.test.tsx @@ -0,0 +1,101 @@ +import { describe, it, expect, vi, beforeEach } from "vitest"; +import type { OnUrlUpdateFunction } from "nuqs/adapters/testing"; +import { MCPSubmissionsTab } from "./MCPSubmissionsTab"; +import { fetchMCPSubmissions } from "@/components/networking"; +import type { MCPServer, MCPSubmissionsSummary } from "@/components/mcp_tools/types"; +import { fireEvent, renderWithProviders, screen, waitFor } from "@/../tests/test-utils"; + +vi.mock("@/components/networking", () => ({ + fetchMCPSubmissions: vi.fn(), + approveMCPServer: vi.fn(), + rejectMCPServer: vi.fn(), + getGeneralSettingsCall: vi.fn().mockResolvedValue({ data: [] }), + updateConfigFieldSetting: vi.fn(), +})); + +const submission = (alias: string, approval_status: MCPServer["approval_status"]): MCPServer => ({ + server_id: `id-${alias}`, + alias, + url: `https://${alias}.example.com/mcp`, + approval_status, + created_at: "2024-01-01T00:00:00Z", + created_by: "user-1", + updated_at: "2024-01-01T00:00:00Z", + updated_by: "user-1", +}); + +const SUBMISSION_NAMES = ["github-pending", "github-live", "linear-pending"]; + +const shownSubmissions = () => + screen + .getAllByRole("heading", { level: 3 }) + .map((heading) => heading.textContent) + .filter((name) => name !== null && SUBMISSION_NAMES.includes(name)); + +const renderTab = (searchParams: string, onUrlUpdate?: OnUrlUpdateFunction) => + renderWithProviders(, { searchParams, onUrlUpdate }); + +const SUMMARY: MCPSubmissionsSummary = { + total: 3, + pending_review: 2, + active: 1, + rejected: 0, + items: [ + submission("github-pending", "pending_review"), + submission("github-live", "active"), + submission("linear-pending", "pending_review"), + ], +}; + +describe("MCPSubmissionsTab filter URL state", () => { + beforeEach(() => { + vi.mocked(fetchMCPSubmissions).mockResolvedValue(SUMMARY); + }); + + it("lists every submission without filters", async () => { + renderTab(""); + + await screen.findByRole("heading", { level: 3, name: "linear-pending" }); + expect(shownSubmissions()).toEqual(SUBMISSION_NAMES); + }); + + it("applies the search and status in the URL", async () => { + renderTab("?sub_search=github&sub_status=pending_review"); + + await screen.findByRole("heading", { level: 3, name: "github-pending" }); + expect(shownSubmissions()).toEqual(["github-pending"]); + expect(screen.getByPlaceholderText("Search MCP servers...")).toHaveValue("github"); + expect(screen.getByRole("combobox")).toHaveValue("pending_review"); + }); + + it("ignores an unknown status in the URL", async () => { + renderTab("?sub_status=archived"); + + await screen.findByRole("heading", { level: 3, name: "linear-pending" }); + expect(shownSubmissions()).toEqual(SUBMISSION_NAMES); + expect(screen.getByRole("combobox")).toHaveValue("all"); + }); + + it("writes the search and status the user picks", async () => { + const onUrlUpdate = vi.fn(); + renderTab("?tab=submitted", onUrlUpdate); + await screen.findByRole("heading", { level: 3, name: "linear-pending" }); + + fireEvent.change(screen.getByPlaceholderText("Search MCP servers..."), { target: { value: "pending" } }); + + await waitFor(() => expect(onUrlUpdate.mock.calls.at(-1)?.[0].searchParams.get("sub_search")).toBe("pending")); + expect(shownSubmissions()).toEqual(["github-pending", "linear-pending"]); + + fireEvent.change(screen.getByRole("combobox"), { target: { value: "active" } }); + + await waitFor(() => expect(onUrlUpdate.mock.calls.at(-1)?.[0].searchParams.get("sub_status")).toBe("active")); + expect(onUrlUpdate.mock.calls.at(-1)?.[0].searchParams.get("sub_search")).toBe("pending"); + expect(onUrlUpdate.mock.calls.at(-1)?.[0].searchParams.get("tab")).toBe("submitted"); + expect(screen.getByText("No MCP server submissions match your filters.")).toBeInTheDocument(); + + fireEvent.change(screen.getByRole("combobox"), { target: { value: "all" } }); + + await waitFor(() => expect(onUrlUpdate.mock.calls.at(-1)?.[0].searchParams.has("sub_status")).toBe(false)); + expect(shownSubmissions()).toEqual(["github-pending", "linear-pending"]); + }); +}); diff --git a/ui/litellm-dashboard/src/app/(dashboard)/mcp-servers/_components/MCPSubmissionsTab.tsx b/ui/litellm-dashboard/src/app/(dashboard)/mcp-servers/_components/MCPSubmissionsTab.tsx index 7062a6f0a5f..f000691df9b 100644 --- a/ui/litellm-dashboard/src/app/(dashboard)/mcp-servers/_components/MCPSubmissionsTab.tsx +++ b/ui/litellm-dashboard/src/app/(dashboard)/mcp-servers/_components/MCPSubmissionsTab.tsx @@ -1,6 +1,7 @@ "use client"; import React, { useState, useEffect, useCallback } from "react"; +import { parseAsString, parseAsStringLiteral, useQueryStates } from "nuqs"; import { SearchIcon, CheckIcon, @@ -24,6 +25,17 @@ import { toast } from "@/lib/toast"; type MCPStatus = "active" | "pending_review" | "rejected"; +const STATUS_FILTERS = ["all", "pending_review", "active", "rejected"] as const; +type StatusFilter = (typeof STATUS_FILTERS)[number]; + +const submissionFilterParsers = { + sub_search: parseAsString.withDefault(""), + sub_status: parseAsStringLiteral(STATUS_FILTERS).withDefault("all"), +}; + +const toStatusFilter = (value: string): StatusFilter | null => + STATUS_FILTERS.find((status) => status === value) ?? null; + const STATUS_CONFIG: Record = { active: { label: "Active", @@ -456,8 +468,8 @@ export function MCPSubmissionsTab({ accessToken }: MCPSubmissionsTabProps) { rejected: 0, items: [], }); - const [search, setSearch] = useState(""); - const [statusFilter, setStatusFilter] = useState<"all" | MCPStatus>("all"); + const [{ sub_search: search, sub_status: statusFilter }, setSubmissionFilters] = + useQueryStates(submissionFilterParsers); const [confirmAction, setConfirmAction] = useState<{ serverId: string; serverName: string; @@ -578,13 +590,13 @@ export function MCPSubmissionsTab({ accessToken }: MCPSubmissionsTabProps) { type="text" placeholder="Search MCP servers..." value={search} - onChange={(e) => setSearch(e.target.value)} + onChange={(e) => void setSubmissionFilters({ sub_search: e.target.value })} className="w-full pl-9 pr-4 py-2 border border-border rounded-md text-sm text-foreground placeholder:text-muted-foreground focus:outline-hidden focus:ring-1 focus:ring-ring focus:border-info" /> handleTeamChange(v ?? "all")} + onValueChange={(v: string | null) => setTeam(v)} > @@ -625,7 +504,7 @@ const MCPServers: React.FC = ({ accessToken, userRole, userID }) setSortKey((v ?? "created_desc") as SortKey)} - > +