mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-29 18:48:11 +00:00
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:
@@ -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";
|
||||
|
||||
@@ -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);
|
||||
},
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user