feat(filter-bar): migrate 3 more fleet pages, extract footer adapter

- ruleEngineFooterProps.ts: toRuleEngineFooterProps() — the
  useFilters-to-RuleEngineListFooter pagination adapter had already been
  hand-written twice (TrucksOnSitePage, CompliancePage) with the same
  pageSize-drop risk useFilters itself just had fixed; extracted before a
  third copy could drift.
- CompliancePage, FuelPurchasePage, IncidentsPage: ListControls ->
  FilterBar + applyClientFilters, same mechanical pattern as the
  warehouse pages (search + one date range, endpoints take no params at
  all per the inventory sweep — confirmed correct bucket, not assumed).
This commit is contained in:
Nathnael
2026-08-14 14:13:11 +00:00
parent fa32fa6a96
commit e5e75b4166
6 changed files with 122 additions and 73 deletions

View File

@@ -3,6 +3,7 @@ export * from "./url";
export * from "./dates";
export * from "./format";
export * from "./clientFilter";
export * from "./ruleEngineFooterProps";
export * from "./useFilters";
export * from "./useSavedViews";
export { FilterBar } from "./FilterBar";

View File

@@ -0,0 +1,32 @@
import type { OnChangeFn, PaginationState } from "@edr/ui-common";
import type { UseFilters } from "./useFilters";
/**
* Adapts `useFilters`'s URL-backed page/pageSize to `RuleEngineListFooter`'s
* prop shape, for the client-bridge pages that render a plain `<Table>` +
* that footer instead of `<DataTable>` (which has `tableProps()` for this).
* Routes page-index vs page-size changes to the right setter — the same
* pageSize-gets-silently-dropped bug `tableProps()` had before it was fixed.
*/
export function toRuleEngineFooterProps(
controls: Pick<UseFilters, "page" | "pageSize" | "setPage" | "setPageSize">,
totalCount: number,
): {
pagination: PaginationState;
pageCount: number;
totalCount: number;
onPaginationChange: OnChangeFn<PaginationState>;
} {
const { page, pageSize, setPage, setPageSize } = controls;
return {
pagination: { pageIndex: page - 1, pageSize },
pageCount: Math.max(1, Math.ceil(totalCount / pageSize)),
totalCount,
onPaginationChange: (updater) => {
const current = { pageIndex: page - 1, pageSize };
const next = typeof updater === "function" ? updater(current) : updater;
if (next.pageSize !== pageSize) setPageSize(next.pageSize);
else if (next.pageIndex !== current.pageIndex) setPage(next.pageIndex + 1);
},
};
}