diff --git a/app/(app)/insights/components/agent-throughput.tsx b/app/(app)/insights/components/agent-throughput.tsx new file mode 100644 index 0000000..820e64f --- /dev/null +++ b/app/(app)/insights/components/agent-throughput.tsx @@ -0,0 +1,133 @@ +'use client' + +import { useRouter, usePathname, useSearchParams } from 'next/navigation' +import { useTransition } from 'react' +import { + BarChart, + Bar, + XAxis, + YAxis, + Tooltip, + ResponsiveContainer, +} from 'recharts' +import { + Select, + SelectContent, + SelectItem, + SelectTrigger, + SelectValue, +} from '@/components/ui/select' +import type { JobsPerDayResult } from '@/lib/insights/agent-throughput' +import { JOB_STATUS_COLORS } from '@/lib/chart-colors' + +interface Props { + data: JobsPerDayResult + productList: { id: string; name: string }[] + currentProductId?: string +} + +function formatDuration(seconds: number | null): string { + if (seconds === null) return '—' + const m = Math.floor(seconds / 60) + const s = seconds % 60 + return m > 0 ? `${m}m ${s}s` : `${s}s` +} + +const STACKED_STATUSES = ['queued', 'claimed', 'running', 'done', 'failed', 'cancelled'] as const + +export function AgentThroughputCard({ data, productList, currentProductId }: Props) { + const router = useRouter() + const pathname = usePathname() + const searchParams = useSearchParams() + const [isPending, startTransition] = useTransition() + + const { perDay, kpi } = data + + const isEmpty = perDay.every( + d => d.done + d.failed + d.queued + d.claimed + d.running + d.cancelled === 0, + ) + + function handleProductChange(value: string | null) { + if (value === null) return + startTransition(() => { + const params = new URLSearchParams(searchParams.toString()) + if (value === '__all__') { + params.delete('product') + } else { + params.set('product', value) + } + router.replace(`${pathname}?${params.toString()}`) + }) + } + + return ( +
+ Geen agent-activiteit in de laatste 2 weken +
+ ) : ( +