shoc-frontend-new/src/app/(protected)/dashboard/_components/dispatcher-tables-section.tsx
Codex Review Integration 7679c28682 refactor(dashboard): extract dispatcher tables into a section component
Move the two paged dispatcher cards and their paging view-model derivation out
of DashboardPage into DispatcherTablesSection (a fragment, so both cards remain
direct children of the dashboard grid). This keeps DashboardPage under the
project complexity threshold after the pager additions, with no change to the
rendered layout or behaviour.
2026-09-17 00:46:39 -03:00

60 lines
2.1 KiB
TypeScript

import type { UseQueryResult } from "@tanstack/react-query";
import {
DISPATCHER_PAGE_SIZE,
type DispatcherPage,
} from "@/domain/dashboard/types/dashboard-dispatcher-page";
import type { DashboardRangeKey } from "@/domain/dashboard/types/dashboard-range";
import type { DispatcherPerformanceRow } from "@/domain/dashboard/types/dashboard-performance";
import type { DispatcherWorkloadRow } from "@/domain/dashboard/types/dashboard-workload";
import { DispatcherPerformanceCard } from "./dispatcher-performance-card";
import { DispatcherWorkloadCard } from "./dispatcher-workload-card";
interface DispatcherTablesSectionProps {
range: DashboardRangeKey;
workload: UseQueryResult<DispatcherPage<DispatcherWorkloadRow>, Error>;
performance: UseQueryResult<DispatcherPage<DispatcherPerformanceRow>, Error>;
workloadPage: number;
performancePage: number;
onWorkloadPageChange: (page: number) => void;
onPerformancePageChange: (page: number) => void;
}
/**
* The two paged dispatcher tables. Kept as a fragment so both cards stay direct
* children of the dashboard grid, and so the paging view-model derivation lives
* here rather than inflating the page component.
*/
export function DispatcherTablesSection({
range,
workload,
performance,
workloadPage,
performancePage,
onWorkloadPageChange,
onPerformancePageChange,
}: DispatcherTablesSectionProps) {
return (
<>
<DispatcherWorkloadCard
rows={workload.data?.items ?? []}
range={range}
page={workloadPage}
pageSize={workload.data?.pageSize ?? DISPATCHER_PAGE_SIZE}
totalDispatchers={workload.data?.totalDispatchers ?? 0}
onPageChange={onWorkloadPageChange}
isLoading={workload.isLoading}
error={workload.error}
/>
<DispatcherPerformanceCard
rows={performance.data?.items ?? []}
range={range}
page={performancePage}
pageSize={performance.data?.pageSize ?? DISPATCHER_PAGE_SIZE}
totalDispatchers={performance.data?.totalDispatchers ?? 0}
onPageChange={onPerformancePageChange}
isLoading={performance.isLoading}
error={performance.error}
/>
</>
);
}