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
This commit is contained in:
ryan-crabbe-berri 2026-09-04 12:47:37 -07:00
parent 7fde31fe08
commit 3bdc5ecd0e
2 changed files with 24 additions and 3 deletions

View file

@ -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(<PerUserUsage {...defaultProps} />);
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(<PerUserUsage {...defaultProps} />);

View file

@ -62,9 +62,6 @@ const PerUserUsage: React.FC<PerUserUsageProps> = ({ 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));