Skip to content

Commit

Permalink
implement page slicing
Browse files Browse the repository at this point in the history
  • Loading branch information
kantord committed Jan 17, 2025
1 parent 706d6eb commit ea7f374
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
14 changes: 14 additions & 0 deletions src/components/__tests__/Dashboard.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -348,4 +348,18 @@ describe("Dashboard", () => {
await userEvent.click(screen.getByRole("button", { name: /previous/i }));
expect(screen.getByRole("button", { name: /previous/i })).toBeDisabled();
});

it("displays the correct rows when using pagination", async () => {
mockManyAlerts();

render(<Dashboard />);

await waitFor(async () => {
await userEvent.click(screen.getByRole("button", { name: /next/i }));

expect(
within(screen.getByTestId("alerts-table")).getAllByRole("row").length,
).toBeLessThan(15);
});
});
});
8 changes: 6 additions & 2 deletions src/hooks/useAlertsData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,12 @@ export const useAlertsData = ({ ...args } = {}) => {
});
};

const PAGE_SIZE = 15;

export const useFilteredAlerts = () => {
const { isMaliciousFilterActive, search } = useAlertSearch();
const { isMaliciousFilterActive, search, page } = useAlertSearch();

const page_start = page * PAGE_SIZE;

return useAlertsData({
select: (
Expand Down Expand Up @@ -71,7 +75,7 @@ export const useFilteredAlerts = () => {
(alert.trigger_type as TriggerType) === "codegate-context-retriever"
);
})
.slice(0, 14),
.slice(page_start, page_start + PAGE_SIZE - 1),
});
};

Expand Down

0 comments on commit ea7f374

Please sign in to comment.