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
fix(ui): reset page and sort correctly in Team virtual keys table
Yuneng Jiang3e1383f529b7
diff --git a/ui/litellm-dashboard/eslint-metrics.json b/ui/litellm-dashboard/eslint-metrics.jsonindex 036af5bc789..0900584f5ce 100644--- a/ui/litellm-dashboard/eslint-metrics.json+++ b/ui/litellm-dashboard/eslint-metrics.json@@ -1,7 +1,7 @@{"@typescript-eslint/no-explicit-any": 1980,"complexity": 128,- "local/no-large-inline-object-arg": 511,+ "local/no-large-inline-object-arg": 509,"local/no-long-condition-chain": 233,"max-depth": 59,"no-console": 15diff --git a/ui/litellm-dashboard/src/components/team/TeamVirtualKeysTable.test.tsx b/ui/litellm-dashboard/src/components/team/TeamVirtualKeysTable.test.tsxindex 9eb0282580b..fd81aaaad99 100644--- a/ui/litellm-dashboard/src/components/team/TeamVirtualKeysTable.test.tsx+++ b/ui/litellm-dashboard/src/components/team/TeamVirtualKeysTable.test.tsx@@ -236,6 +236,59 @@ describe("TeamVirtualKeysTable", () => {);});+ it("resets to the first page when the sort changes", async () => {+ const user = userEvent.setup();+ mockUseKeys.mockImplementation(+ (page: number) =>+ ({+ data: {+ keys: [createMockKey({ token: `sk-p${page}`, key_alias: `page${page}_key` })],+ total_count: 100,+ current_page: page,+ total_pages: 2,+ },+ isPending: false,+ isFetching: false,+ refetch: vi.fn(),+ }) as unknown as ReturnType<typeof useKeys>,+ );++ renderWithProviders(<TeamVirtualKeysTable {...defaultProps} />);++ await user.click(await screen.findByTestId("pagination-next"));+ await waitFor(() => expect(mockUseKeys).toHaveBeenLastCalledWith(2, 50, expect.anything()));++ await user.click(screen.getByTestId("sort-header-created_at"));+ await waitFor(() => expect(mockUseKeys).toHaveBeenLastCalledWith(1, 50, expect.anything()));+ });++ it("resets the sort order to the default when filters are reset", async () => {+ const user = userEvent.setup();+ const result = {+ data: { keys: [createMockKey()], total_count: 1, current_page: 1, total_pages: 1 },+ isPending: false,+ isFetching: false,+ refetch: vi.fn(),+ } as unknown as ReturnType<typeof useKeys>;+ mockUseKeys.mockReturnValue(result);++ renderWithProviders(<TeamVirtualKeysTable {...defaultProps} />);++ await user.click(await screen.findByTestId("sort-header-created_at"));+ await waitFor(() =>+ expect(mockUseKeys).toHaveBeenLastCalledWith(1, 50, expect.objectContaining({ sortOrder: "asc" })),+ );++ await user.click(screen.getByRole("button", { name: "Reset Filters" }));+ await waitFor(() =>+ expect(mockUseKeys).toHaveBeenLastCalledWith(+ 1,+ 50,+ expect.objectContaining({ sortBy: "created_at", sortOrder: "desc" }),+ ),+ );+ });+it("should show Loading keys when isPending", async () => {mockUseKeys.mockReturnValue({data: undefined,diff --git a/ui/litellm-dashboard/src/components/team/TeamVirtualKeysTable.tsx b/ui/litellm-dashboard/src/components/team/TeamVirtualKeysTable.tsxindex 778b82a8fc5..73f524e13f8 100644--- a/ui/litellm-dashboard/src/components/team/TeamVirtualKeysTable.tsx+++ b/ui/litellm-dashboard/src/components/team/TeamVirtualKeysTable.tsx@@ -27,10 +27,12 @@ interface TeamVirtualKeysTableProps {* TeamVirtualKeysTable – variant of VirtualKeysTable scoped to a single team.* Displays all virtual keys belonging to the team with same format and styling.*/+const DEFAULT_SORTING: SortingState = [{ id: "created_at", desc: true }];+export function TeamVirtualKeysTable({ teamId, teamAlias, organization }: TeamVirtualKeysTableProps) {const { accessToken } = useAuthorized();const [selectedKey, setSelectedKey] = useState<KeyResponse | null>(null);- const [sorting, setSorting] = useState<SortingState>([{ id: "created_at", desc: true }]);+ const [sorting, setSorting] = useState<SortingState>(DEFAULT_SORTING);const [tablePagination, setTablePagination] = useState<PaginationState>({pageIndex: 0,pageSize: 50,@@ -39,8 +41,6 @@ export function TeamVirtualKeysTable({ teamId, teamAlias, organization }: TeamVi"Organization ID": "","Key Alias": "","User ID": "",- "Sort By": "created_at",- "Sort Order": "desc",});const sortBy = sorting.length > 0 ? sorting[0].id : "created_at";@@ -116,18 +116,14 @@ export function TeamVirtualKeysTable({ teamId, teamAlias, organization }: TeamVireturn () => window.removeEventListener("storage", handleStorageChange);}, [handleStorageChange]);- const handleFilterChange = useCallback((newFilters: Record<string, string>, skipDebounce = false) => {+ const handleFilterChange = useCallback((newFilters: Record<string, string>) => {setFilters((prev) => ({...prev,"Organization ID": newFilters["Organization ID"] ?? prev["Organization ID"],"Key Alias": newFilters["Key Alias"] ?? prev["Key Alias"],"User ID": newFilters["User ID"] ?? prev["User ID"],- "Sort By": newFilters["Sort By"] ?? prev["Sort By"] ?? "created_at",- "Sort Order": newFilters["Sort Order"] ?? prev["Sort Order"] ?? "desc",}));- if (!skipDebounce) {- setTablePagination((prev) => ({ ...prev, pageIndex: 0 }));- }+ setTablePagination((prev) => ({ ...prev, pageIndex: 0 }));}, []);const handleFilterReset = useCallback(() => {@@ -135,9 +131,8 @@ export function TeamVirtualKeysTable({ teamId, teamAlias, organization }: TeamVi"Organization ID": "","Key Alias": "","User ID": "",- "Sort By": "created_at",- "Sort Order": "desc",});+ setSorting(DEFAULT_SORTING);setTablePagination((prev) => ({ ...prev, pageIndex: 0 }));}, []);@@ -492,23 +487,10 @@ export function TeamVirtualKeysTable({ teamId, teamAlias, organization }: TeamVi[expandedAccordions],);- const handleSortingChange = useCallback(- (updaterOrValue: React.SetStateAction<SortingState>) => {- const newSorting = typeof updaterOrValue === "function" ? updaterOrValue(sorting) : updaterOrValue;- setSorting(newSorting);- if (newSorting?.length > 0) {- const sortState = newSorting[0];- handleFilterChange(- {- "Sort By": sortState.id,- "Sort Order": sortState.desc ? "desc" : "asc",- },- true,- );- }- },- [sorting, handleFilterChange],- );+ const handleSortingChange = useCallback((updaterOrValue: React.SetStateAction<SortingState>) => {+ setSorting(updaterOrValue);+ setTablePagination((prev) => ({ ...prev, pageIndex: 0 }));+ }, []);return (<div className="w-full h-full overflow-hidden">