Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
339 changes: 249 additions & 90 deletions apps/web/src/app/(dashboard)/incidents/[id]/page.tsx

Large diffs are not rendered by default.

24 changes: 22 additions & 2 deletions apps/web/src/app/(dashboard)/incidents/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ import { apiGet } from '@/lib/api';
import { formatDateTime, formatScore } from '@/lib/format';
import { INCIDENT_SEVERITIES, INCIDENT_STATUSES, incidentQuery } from '@/lib/queries';
import { incidentListSchema } from '@/lib/schemas';
import { cn } from '@/lib/utils';

// Severity at a glance down the left edge, matching the severity badge colours.
const SEVERITY_ACCENT: Record<string, string> = {
high: 'border-l-danger',
medium: 'border-l-warning',
low: 'border-l-border',
};

export default async function IncidentsPage({
searchParams,
Expand Down Expand Up @@ -67,7 +75,7 @@ export default async function IncidentsPage({
</TableHeader>
<TableBody>
{incidents.map((incident) => (
<TableRow key={incident.id}>
<TableRow key={incident.id} className={cn('border-l-2', SEVERITY_ACCENT[incident.severity] ?? 'border-l-transparent')}>
<TableCell>
<Link href={`/incidents/${incident.id}`} className="font-medium hover:underline">
{incident.title}
Expand All @@ -80,7 +88,19 @@ export default async function IncidentsPage({
<StatusBadge status={incident.status} />
</TableCell>
<TableCell className="text-right tabular-nums">{incident.labCount}</TableCell>
<TableCell className="text-right tabular-nums">{formatScore(incident.correlationStrength)}</TableCell>
<TableCell>
<span className="flex items-center justify-end gap-2">
{incident.correlationStrength !== null && (
<span aria-hidden className="h-1.5 w-14 overflow-hidden rounded-full bg-muted">
<span
className="animate-grow-x block h-full rounded-full bg-info"
style={{ width: `${Math.round(incident.correlationStrength * 100)}%` }}
/>
</span>
)}
<span className="w-8 text-right tabular-nums">{formatScore(incident.correlationStrength)}</span>
</span>
</TableCell>
<TableCell className="whitespace-nowrap text-muted-foreground">{formatDateTime(incident.createdAt)}</TableCell>
</TableRow>
))}
Expand Down
73 changes: 73 additions & 0 deletions apps/web/src/app/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,76 @@
body {
@apply bg-background text-foreground antialiased;
}

/* Motion: entrances, the confidence gauge and evidence highlights. Plain CSS so
server components animate without client JavaScript. */
@keyframes rise {
from {
opacity: 0;
transform: translateY(6px);
}
}

@keyframes gauge-fill {
from {
stroke-dashoffset: var(--gauge-length);
}
}

@keyframes grow-x {
from {
transform: scaleX(0);
}
}

@keyframes flash {
0%,
40% {
background-color: var(--info-bg);
box-shadow: inset 3px 0 0 var(--info);
}
}

@keyframes ping-soft {
75%,
100% {
transform: scale(1.9);
opacity: 0;
}
}

.animate-rise {
animation: rise 420ms cubic-bezier(0.2, 0.7, 0.2, 1) both;
}

.animate-gauge {
animation: gauge-fill 1100ms cubic-bezier(0.2, 0.7, 0.2, 1) both;
}

.animate-grow-x {
transform-origin: left;
animation: grow-x 700ms cubic-bezier(0.2, 0.7, 0.2, 1) both;
}

.animate-ping-soft {
animation: ping-soft 1.6s cubic-bezier(0, 0, 0.2, 1) infinite;
}

/* A cited evidence link jumps to its event, which flashes so the eye lands on it. */
.evidence-row {
scroll-margin-top: 6rem;
}

.evidence-row:target {
animation: flash 1.8s ease-out;
}

@media (prefers-reduced-motion: reduce) {
.animate-rise,
.animate-gauge,
.animate-grow-x,
.animate-ping-soft,
.evidence-row:target {
animation: none;
}
}
5 changes: 4 additions & 1 deletion apps/web/src/components/dashboard/bar-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ export function BarList({ items, colourFor }: { items: [string, number][]; colou
<span className="font-medium tabular-nums">{count}</span>
</div>
<div className="h-2 rounded-full bg-muted">
<div className="h-2 rounded-full" style={{ width: `${(count / max) * 100}%`, background: colourFor(key) }} />
<div
className="animate-grow-x h-2 rounded-full"
style={{ width: `${(count / max) * 100}%`, background: colourFor(key) }}
/>
</div>
</li>
))}
Expand Down
27 changes: 27 additions & 0 deletions apps/web/src/components/dashboard/count-up.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
'use client';

// Counts a headline number up from zero once, on mount. The server renders the
// final value, so it reads correctly before hydration, without JavaScript and
// for screen readers; reduced motion skips the animation entirely.

import { useEffect, useState } from 'react';

const DURATION_MS = 900;

export function CountUp({ value }: { value: number }) {
const [shown, setShown] = useState(value);
useEffect(() => {
if (value === 0 || window.matchMedia('(prefers-reduced-motion: reduce)').matches) return;
let frame = 0;
const start = performance.now();
const tick = (now: number) => {
const progress = Math.min(1, (now - start) / DURATION_MS);
// Ease out: fast at first, settling onto the real number.
setShown(Math.round(value * (1 - (1 - progress) ** 3)));
if (progress < 1) frame = requestAnimationFrame(tick);
};
frame = requestAnimationFrame(tick);
return () => cancelAnimationFrame(frame);
}, [value]);
return <span aria-label={String(value)}>{shown}</span>;
}
47 changes: 37 additions & 10 deletions apps/web/src/components/dashboard/failure-timeline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
// no values in between. Data arrives as props from the server; the browser
// never calls the API.

import { useState } from 'react';
import { Bar, BarChart, CartesianGrid, ResponsiveContainer, Tooltip, XAxis, YAxis } from 'recharts';
import { bucketLabel, colourFor } from '@/lib/charts';
import { humanise } from '@/lib/format';
import { cn } from '@/lib/utils';
import type { FailureSeries } from '@/lib/schemas';

type TooltipEntry = { dataKey?: unknown; value?: unknown; color?: string };
Expand All @@ -31,6 +33,17 @@ function TimelineTooltip({ active, payload, label }: { active?: boolean; payload

export function FailureTimeline({ series }: { series: FailureSeries }) {
const categories = Object.keys(series.totals).filter((category) => (series.totals[category] ?? 0) > 0);
// Categories the operator switched off in the legend, to isolate one signal.
const [hidden, setHidden] = useState<ReadonlySet<string>>(new Set());
const visible = categories.filter((category) => !hidden.has(category));
const toggle = (category: string) =>
setHidden((current) => {
const next = new Set(current);
if (next.has(category)) next.delete(category);
// Never hide the last one: an empty chart reads as "no failures".
else if (visible.length > 1) next.add(category);
return next;
});
const data = series.buckets.map((bucket) => ({
label: bucketLabel(bucket.start, series.bucketMs ?? 60_000),
...bucket.counts,
Expand All @@ -44,26 +57,40 @@ export function FailureTimeline({ series }: { series: FailureSeries }) {
<XAxis dataKey="label" tickLine={false} axisLine={false} fontSize={11} stroke="var(--muted-foreground)" minTickGap={24} />
<YAxis allowDecimals={false} tickLine={false} axisLine={false} fontSize={11} stroke="var(--muted-foreground)" />
<Tooltip content={<TimelineTooltip />} cursor={{ fill: 'var(--muted)' }} />
{categories.map((category, index) => (
{visible.map((category, index) => (
<Bar
key={category}
dataKey={category}
stackId="failures"
fill={colourFor(category)}
radius={index === categories.length - 1 ? [3, 3, 0, 0] : 0}
isAnimationActive={false}
radius={index === visible.length - 1 ? [3, 3, 0, 0] : 0}
animationDuration={700}
animationEasing="ease-out"
/>
))}
</BarChart>
</ResponsiveContainer>
</div>
<ul className="flex flex-wrap gap-x-4 gap-y-1 text-xs text-muted-foreground">
{categories.map((category) => (
<li key={category} className="flex items-center gap-1.5">
<span className="size-2 rounded-full" style={{ background: colourFor(category) }} />
{humanise(category)}
</li>
))}
<ul className="flex flex-wrap gap-2 text-xs">
{categories.map((category) => {
const on = !hidden.has(category);
return (
<li key={category}>
<button
type="button"
aria-pressed={on}
onClick={() => toggle(category)}
className={cn(
'flex items-center gap-1.5 rounded-full border px-2.5 py-1 transition-colors hover:bg-muted',
on ? 'text-foreground' : 'text-muted-foreground line-through opacity-60',
)}
>
<span className="size-2 rounded-full" style={{ background: colourFor(category) }} />
{humanise(category)}
</button>
</li>
);
})}
</ul>
</div>
);
Expand Down
7 changes: 5 additions & 2 deletions apps/web/src/components/dashboard/kpi-tile.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { LucideIcon } from 'lucide-react';
import type { ReactNode } from 'react';
import { cn } from '@/lib/utils';
import { CountUp } from './count-up';

const TONES = {
neutral: 'bg-muted text-muted-foreground',
Expand All @@ -25,14 +26,16 @@ export function KpiTile({
tone?: keyof typeof TONES;
}) {
return (
<div className="rounded-xl border bg-card px-4 py-3.5 shadow-sm">
<div className="animate-rise rounded-xl border bg-card px-4 py-3.5 shadow-sm transition-shadow hover:shadow-md">
<div className="flex items-start justify-between gap-2">
<p className="text-xs font-medium text-muted-foreground">{label}</p>
<span className={cn('rounded-md p-1.5', TONES[tone])}>
<Icon className="size-3.5" />
</span>
</div>
<p className="mt-1 text-2xl font-bold tracking-tight tabular-nums">{value}</p>
<p className="mt-1 text-2xl font-bold tracking-tight tabular-nums">
{typeof value === 'number' ? <CountUp value={value} /> : value}
</p>
<p className="mt-0.5 text-xs text-muted-foreground">{caption}</p>
</div>
);
Expand Down
32 changes: 29 additions & 3 deletions apps/web/src/components/dashboard/labs-donut.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
'use client';

import { useState } from 'react';
import { Cell, Pie, PieChart, ResponsiveContainer, Tooltip } from 'recharts';
import { cn } from '@/lib/utils';

// Lab states take the status palette, not the category one: a failed lab is
// the same red here as on every badge.
Expand All @@ -17,14 +19,33 @@ export function LabsDonut({ counts }: { counts: Record<string, number> }) {
.filter(([, value]) => value > 0)
.map(([state, value]) => ({ state, value }));
const total = data.reduce((sum, entry) => sum + entry.value, 0);
// Hovering a slice or its legend row brings that state forward.
const [focus, setFocus] = useState<string | null>(null);
const dimmed = (state: string) => focus !== null && focus !== state;
return (
<div className="flex items-center gap-6">
<div className="relative size-40 shrink-0">
<ResponsiveContainer width="100%" height="100%">
<PieChart>
<Pie data={data} dataKey="value" nameKey="state" innerRadius="68%" outerRadius="100%" strokeWidth={0} isAnimationActive={false}>
<Pie
data={data}
dataKey="value"
nameKey="state"
innerRadius="68%"
outerRadius="100%"
strokeWidth={0}
paddingAngle={data.length > 1 ? 2 : 0}
animationDuration={800}
onMouseEnter={(_, index) => setFocus(data[index]?.state ?? null)}
onMouseLeave={() => setFocus(null)}
>
{data.map((entry) => (
<Cell key={entry.state} fill={STATE_COLOURS[entry.state] ?? 'var(--muted-foreground)'} />
<Cell
key={entry.state}
fill={STATE_COLOURS[entry.state] ?? 'var(--muted-foreground)'}
opacity={dimmed(entry.state) ? 0.3 : 1}
className="transition-opacity"
/>
))}
</Pie>
<Tooltip
Expand All @@ -40,7 +61,12 @@ export function LabsDonut({ counts }: { counts: Record<string, number> }) {
</div>
<ul className="space-y-1.5 text-sm">
{data.map((entry) => (
<li key={entry.state} className="flex items-center gap-2">
<li
key={entry.state}
onMouseEnter={() => setFocus(entry.state)}
onMouseLeave={() => setFocus(null)}
className={cn('flex cursor-default items-center gap-2 transition-opacity', dimmed(entry.state) && 'opacity-40')}
>
<span className="size-2.5 rounded-full" style={{ background: STATE_COLOURS[entry.state] }} />
<span className="text-muted-foreground">{entry.state}</span>
<span className="ml-auto pl-4 font-medium tabular-nums">{entry.value}</span>
Expand Down
47 changes: 47 additions & 0 deletions apps/web/src/components/incident/confidence-gauge.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// The model's own confidence as a ring that fills on load. It is the model's
// estimate, not a measured probability, so the label says so.

import type { CSSProperties } from 'react';
import { formatConfidence } from '@/lib/format';
import { cn } from '@/lib/utils';

const RADIUS = 34;
const LENGTH = 2 * Math.PI * RADIUS;

function tone(confidence: number): string {
if (confidence >= 0.75) return 'text-success';
if (confidence >= 0.5) return 'text-warning';
return 'text-danger';
}

export function ConfidenceGauge({ confidence }: { confidence: number | null }) {
const value = confidence ?? 0;
return (
<div className="flex items-center gap-4">
<svg viewBox="0 0 80 80" className="size-20 shrink-0 -rotate-90" aria-hidden>
<circle cx="40" cy="40" r={RADIUS} fill="none" strokeWidth="7" className="stroke-muted" />
{confidence !== null && (
<circle
cx="40"
cy="40"
r={RADIUS}
fill="none"
strokeWidth="7"
strokeLinecap="round"
stroke="currentColor"
className={cn('animate-gauge', tone(value))}
strokeDasharray={LENGTH}
strokeDashoffset={LENGTH * (1 - value)}
style={{ '--gauge-length': LENGTH } as CSSProperties}
/>
)}
</svg>
<div>
<p className="text-2xl font-semibold tracking-tight tabular-nums">
{confidence === null ? '—' : `${Math.round(value * 100)}%`}
</p>
<p className="text-xs text-muted-foreground">Confidence: {formatConfidence(confidence)}</p>
</div>
</div>
);
}
Loading
Loading