From ad2795fc8e06cee2d3537039e2ddaa3c6d054f04 Mon Sep 17 00:00:00 2001 From: Sai Asish Y Date: Fri, 13 Nov 2026 03:26:28 -0800 Subject: [PATCH] fix(web): return the audit log pagination to the first page when the sort changes Signed-off-by: Sai Asish Y --- .../SortableHeader/SortableHeader.tsx | 12 ++++- .../_app/admin/audit/__tests__/logs.test.tsx | 8 ++++ apps/web/src/routes/_app/admin/audit/logs.tsx | 45 +++++++++++++------ 3 files changed, 50 insertions(+), 15 deletions(-) diff --git a/apps/web/src/components/SortableHeader/SortableHeader.tsx b/apps/web/src/components/SortableHeader/SortableHeader.tsx index ed2763b01..7e6b7052a 100644 --- a/apps/web/src/components/SortableHeader/SortableHeader.tsx +++ b/apps/web/src/components/SortableHeader/SortableHeader.tsx @@ -10,6 +10,11 @@ type SortableHeaderProps = { * mounts with no sorting state of its own, so the column reads as unsorted however it is ordered. */ sortOrder?: 'asc' | 'desc'; + /** + * Passed by a table in server mode, which does not return its page index to the first page when + * the sort changes, so the page controls would keep counting from the page the user left. + */ + table?: TanstackTable.Table; }; const SORT_ICONS = { asc: ChevronUpIcon, desc: ChevronDownIcon }; @@ -18,14 +23,17 @@ const SORT_ICONS = { asc: ChevronUpIcon, desc: ChevronDownIcon }; * A clickable column label. `DataTableHead` renders whatever the column supplies, so the sort * affordance lives here rather than coming from the table. */ -export const SortableHeader = ({ column, label, sortOrder }: SortableHeaderProps) => { +export const SortableHeader = ({ column, label, sortOrder, table }: SortableHeaderProps) => { const sorted = sortOrder ?? column.getIsSorted(); const Icon = sorted ? SORT_ICONS[sorted] : ChevronsUpDownIcon; return (