Scrum4Me/app/(app)/insights/components/agent-throughput.tsx
Janpeter Visser d750676f5e
PBI-56 + ST-1275: PLAN_READY → GRILLING re-grill + SKIPPED status rendering (#147)
* fix(ST-1272): allow PLAN_READY → GRILLING re-grill transition

actions/ideas.ts already lists PLAN_READY in GRILL_TRIGGERABLE_FROM,
but lib/idea-status.ts ALLOWED_TRANSITIONS was missing the
PLAN_READY → GRILLING edge. As a result, clicking Grill on a PLAN_READY
idea returned 422 "Status-transitie ongeldig" while the UI button was
enabled. Mirrors the existing PLANNED → GRILLING re-grill behaviour.

- lib/idea-status.ts: PLAN_READY allows GRILLING in addition to
  PLANNING/PLANNED
- __tests__/lib/idea-status.test.ts: explicit assert for
  PLAN_READY → GRILLING and PLAN_READY added to the regrill loop
  covering every GRILL_TRIGGERABLE_FROM status

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(ST-1275): render SKIPPED job status in chart-colors and insights

Closing the gap left when ClaudeJobStatus.SKIPPED was added to the schema:
the badge map and case-mapper already covered it, but the chart palette,
the per-day insights aggregator and the stacked-bar chart did not. SKIPPED
jobs (e.g. cmovkur8 manually flipped during the no-op-exit hotfix) now
render with a muted style consistent with cancelled.

- lib/chart-colors.ts: JOB_STATUS_COLORS gains a 'skipped' entry
  (var(--muted-foreground), same intensity as cancelled — neither rood/orange)
- lib/insights/agent-throughput.ts: DayCount + STATUSES + perDay zero-fill
  now include 'skipped'; the SQL terminal_7d filter already counted SKIPPED
- app/(app)/insights/components/agent-throughput.tsx: STACKED_STATUSES and
  the empty-state guard include 'skipped'
- __tests__: chart-colors keys list, job-status round-trip ('all 7 statuses')
  and the insights non-zero filter all account for SKIPPED

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-07 17:36:44 +02:00

133 lines
4 KiB
TypeScript

'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', 'skipped'] 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 + d.skipped === 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 (
<div className="space-y-4">
{/* KPI strip + product filter */}
<div className="flex items-start justify-between gap-4 flex-wrap">
<div className="flex gap-6">
<div>
<div className="text-2xl font-semibold text-foreground">{kpi.todayCount}</div>
<div className="text-xs text-muted-foreground">Jobs vandaag</div>
</div>
<div>
<div className="text-2xl font-semibold text-foreground">
{kpi.successRate7d === 0 ? '—' : `${Math.round(kpi.successRate7d * 100)}%`}
</div>
<div className="text-xs text-muted-foreground">Success-rate (7d)</div>
</div>
<div>
<div className="text-2xl font-semibold text-foreground">
{formatDuration(kpi.avgDurationSeconds7d)}
</div>
<div className="text-xs text-muted-foreground">Avg duration (7d)</div>
</div>
</div>
{productList.length > 0 && (
<Select
value={currentProductId ?? '__all__'}
onValueChange={handleProductChange}
>
<SelectTrigger className="w-44" disabled={isPending}>
<SelectValue />
</SelectTrigger>
<SelectContent>
<SelectItem value="__all__">Alle producten</SelectItem>
{productList.map(p => (
<SelectItem key={p.id} value={p.id}>{p.name}</SelectItem>
))}
</SelectContent>
</Select>
)}
</div>
{/* Chart */}
{isEmpty ? (
<p className="text-sm text-muted-foreground py-4 text-center">
Geen agent-activiteit in de laatste 2 weken
</p>
) : (
<ResponsiveContainer width="100%" height={240}>
<BarChart data={perDay}>
<XAxis
dataKey="day"
tick={{ fontSize: 11 }}
tickFormatter={v => (v as string).slice(5)}
/>
<YAxis allowDecimals={false} tick={{ fontSize: 11 }} />
<Tooltip />
{STACKED_STATUSES.map(status => (
<Bar
key={status}
dataKey={status}
stackId="status"
fill={JOB_STATUS_COLORS[status]}
name={status}
/>
))}
</BarChart>
</ResponsiveContainer>
)}
</div>
)
}