From 3bdc5ecd0e2775ff7f79a7166f16f5e7cb746371 Mon Sep 17 00:00:00 2001 From: ryan-crabbe-berri Date: Fri, 4 Sep 2026 12:47:37 -0700 Subject: [PATCH] refactor(ui): drop the per-user usage page clamp now handled by the shared DataTable The shared DataTable clamps a server-mode page index whenever rowCount no longer reaches it (#39776), including the empty-dataset case this table's own clamp skipped because it required total_pages > 0. Remove the local clamp and cover the empty case through the component so the wiring into the shared behavior is what the tests prove --- .../src/components/per_user_usage.test.tsx | 24 +++++++++++++++++++ .../src/components/per_user_usage.tsx | 3 --- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/ui/litellm-dashboard/src/components/per_user_usage.test.tsx b/ui/litellm-dashboard/src/components/per_user_usage.test.tsx index d5c2216dfd5..30b3059b7d2 100644 --- a/ui/litellm-dashboard/src/components/per_user_usage.test.tsx +++ b/ui/litellm-dashboard/src/components/per_user_usage.test.tsx @@ -178,6 +178,30 @@ describe("PerUserUsage", () => { expect(screen.getByTestId("pagination-next")).toBeDisabled(); }); + it("goes back to the first page when the data disappears under the current page", async () => { + const user = userEvent.setup(); + render(); + await screen.findByText("user-1"); + await user.click(screen.getByTestId("pagination-next")); + await screen.findByText("user-51"); + + serveUsers(0); + await user.click(screen.getByTestId("pagination-next")); + + await waitFor(() => { + expect(lastCall()).toEqual(["test-token", 1, 50, undefined]); + }); + expect(mockPerUserAnalyticsCall.mock.calls.slice(-2)).toEqual([ + ["test-token", 3, 50, undefined], + ["test-token", 1, 50, undefined], + ]); + expect(screen.getByText("No per-user usage data")).toBeInTheDocument(); + expect(screen.getByTestId("pagination-range")).toHaveTextContent("No results"); + expect(screen.getByText("Page 1 of 1")).toBeInTheDocument(); + expect(screen.getByTestId("pagination-first")).toBeDisabled(); + expect(screen.getByTestId("pagination-prev")).toBeDisabled(); + }); + it("refetches with the selected page size and goes back to the first page", async () => { const user = userEvent.setup(); render(); diff --git a/ui/litellm-dashboard/src/components/per_user_usage.tsx b/ui/litellm-dashboard/src/components/per_user_usage.tsx index 57b1a926ec0..f600cd6c45d 100644 --- a/ui/litellm-dashboard/src/components/per_user_usage.tsx +++ b/ui/litellm-dashboard/src/components/per_user_usage.tsx @@ -62,9 +62,6 @@ const PerUserUsage: React.FC = ({ accessToken, selectedTags, .then((response) => { if (stale) return; setPerUserData(response); - if (response.total_pages > 0 && pagination.pageIndex >= response.total_pages) { - setPagination({ ...pagination, pageIndex: response.total_pages - 1 }); - } }) .catch((error) => console.error("Failed to fetch per-user data:", error));