Skip to content

Commit 529ffcc

Browse files
committed
fixes for pagination logic
1 parent 415b4e9 commit 529ffcc

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/components/__tests__/Dashboard.test.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ describe("Dashboard", () => {
324324
await waitFor(() => {
325325
expect(
326326
within(screen.getByTestId("alerts-table")).getAllByRole("row"),
327-
).toHaveLength(15);
327+
).toHaveLength(16);
328328
});
329329
});
330330

@@ -338,7 +338,7 @@ describe("Dashboard", () => {
338338

339339
expect(
340340
within(screen.getByTestId("alerts-table")).getAllByRole("row").length,
341-
).toBeLessThan(15);
341+
).toBeLessThan(16);
342342
});
343343

344344
// on the last page, we cannot go further
@@ -357,7 +357,7 @@ describe("Dashboard", () => {
357357

358358
expect(
359359
within(screen.getByTestId("alerts-table")).getAllByRole("row").length,
360-
).toEqual(15);
360+
).toEqual(16);
361361
});
362362
});
363363
});

src/hooks/useClientSidePagination.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ export function useClientSidePagination<T>(
44
pageSize: number,
55
) {
66
const pageStart = page * pageSize;
7-
const pageEnd = page * pageSize + pageSize - 1;
7+
const pageEnd = page * pageSize + pageSize;
88

99
const dataView = data.slice(pageStart, pageEnd);
1010

1111
const hasPreviousPage = page > 0;
12-
const hasNextPage = pageEnd + 1 < data.length;
12+
const hasNextPage = pageEnd < data.length;
1313

1414
return { pageStart, pageEnd, dataView, hasPreviousPage, hasNextPage };
1515
}

0 commit comments

Comments
 (0)