Dashboard
A project at a glance: the four numbers that matter with how they moved, traffic and errors over the chosen time, where the errors come from, whether every service is up, and what the team did.
import { StatGroup, LineChart, HorizontalBar, Health } from '@sypnia/ui/react'
On a desktop
Change the time range: every number and chart follows.
northwind-shop
How the project is doing.
- Answered
- Failed
View as table
| Answered | Failed | |
|---|---|---|
| Nov 11 | 117K | 1.3K |
| Nov 12 | 107K | 1.2K |
| Nov 13 | 133K | 974 |
| Nov 14 | 135K | 1.2K |
| Nov 15 | 120K | 974 |
| Nov 16 | 140K | 719 |
| Nov 17 | 128K | 889 |
View as table
| Name | |
|---|---|
| POST /v1/checkout | 2,957 |
| GET /v1/products | 1,586 |
| POST /v1/refunds | 1,370 |
| GET /v1/orders/:id | 793 |
| POST /v1/webhooks | 505 |
Services
What the team did
- AR
Ana Ruiz deployed version 1.42
- LO
Luis Ortega created the table refunds
- AR
Ana Ruiz invited Kenji Mori
- MG
Marta Gil changed the plan to Pro
Code
import { useMemo, useState } from 'react';
import {
ActivityFeed, Button, Columns, EmptyState, Health, HorizontalBar, LineChart, Page, PageHeader, Panel, SegmentedControl, SkeletonWords, Stack,
Stat, StatGroup, UptimeBar, UptimeBarSkeleton, useSypnia,
} from '@sypnia/ui/react';
// A project at a glance: the four numbers that matter with how they moved, traffic and errors over the chosen
// time, where the errors come from, whether every service is up, and what the team did. A new project with no traffic
// says what to do first instead of showing empty charts.
type Range = '24h' | '7d' | '30d';
const en = {
title: 'northwind-shop', lead: 'How the project is doing.', range: 'Time range', ranges: { '24h': '24 hours', '7d': '7 days', '30d': '30 days' },
requests: 'Requests', errors: 'Errors', p95: 'Slowest 5% wait', storage: 'Storage', vsBefore: 'vs. the period before',
traffic: 'Requests and errors', trafficSub: (r: string) => `Every ${r === '24h' ? 'hour' : 'day'}`, ok: 'Answered', failed: 'Failed',
byRoute: 'Where the errors come from', byRouteSub: 'Failed requests by route', services: 'Services', uptime: 'The last 30 days', team: 'What the team did',
api: 'API', db: 'Database', auth: 'Sign-in', storageSvc: 'Files', up: 'Working', slow: 'Slower than usual', slowDetail: 'Queries take twice as long since 14:10',
newTitle: 'No traffic yet', newBody: 'Numbers show here once your app calls the API. Connect your agent or install the SDK, and send the first request.', connect: 'Connect your agent', docs: 'Read the quick start',
chartFail: 'These numbers could not be loaded. Try again in a minute.',
acts: [['deployed', 'version 1.42'], ['created the table', 'refunds'], ['invited', 'Kenji Mori'], ['changed the plan to', 'Pro']],
};
const es: typeof en = {
title: 'northwind-shop', lead: 'Cómo va el proyecto.', range: 'Periodo', ranges: { '24h': '24 horas', '7d': '7 días', '30d': '30 días' },
requests: 'Solicitudes', errors: 'Errores', p95: 'Espera del 5 % más lento', storage: 'Almacenamiento', vsBefore: 'frente al periodo anterior',
traffic: 'Solicitudes y errores', trafficSub: (r: string) => `Cada ${r === '24h' ? 'hora' : 'día'}`, ok: 'Respondidas', failed: 'Fallidas',
byRoute: 'De dónde vienen los errores', byRouteSub: 'Solicitudes fallidas por ruta', services: 'Servicios', uptime: 'Los últimos 30 días', team: 'Lo que hizo el equipo',
api: 'API', db: 'Base de datos', auth: 'Inicio de sesión', storageSvc: 'Archivos', up: 'Funciona', slow: 'Más lento de lo normal', slowDetail: 'Las consultas tardan el doble desde las 14:10',
newTitle: 'Aún no hay tráfico', newBody: 'Las cifras aparecen aquí cuando tu app llame a la API. Conecta tu agente o instala el SDK, y envía la primera solicitud.', connect: 'Conecta tu agente', docs: 'Leer el inicio rápido',
chartFail: 'No se pudieron cargar estas cifras. Intenta de nuevo en un minuto.',
acts: [['desplegó', 'la versión 1.42'], ['creó la tabla', 'refunds'], ['invitó a', 'Kenji Mori'], ['cambió el plan a', 'Pro']],
};
const now = Date.UTC(2026, 10, 17, 15);
// Relative times («2 hours ago») are counted from the moment the page is drawn, so the server and the browser
// write the same words; dates that are shown as dates stay fixed.
const ago = (ms: number) => Date.now() - ms; // the words match; only the machine-readable dateTime differs by a moment
const wave = (n: number, base: number, amp: number, seed: number) => Array.from({ length: n }, (_, i) => Math.round(base + amp * Math.sin((i + seed) / 3.2) + amp * 0.4 * Math.sin((i * 7 + seed) / 1.7)));
export default function Dashboard({ state = 'ready' }: { state?: 'ready' | 'loading' | 'new' | 'error' }) {
const { locale, format } = useSypnia();
const c = locale.startsWith('es') ? es : en;
const [range, setRange] = useState<Range>('7d');
const n = range === '24h' ? 24 : range === '7d' ? 7 : 30;
const x = useMemo(() => Array.from({ length: n }, (_, i) => {
const d = new Date(now - (n - 1 - i) * (range === '24h' ? 3600e3 : 86400e3));
return range === '24h' ? `${String(d.getUTCHours()).padStart(2, '0')}:00` : format.date(d).replace(/,? \d{4}$/, '');
}), [n, range, format]);
const scale = range === '24h' ? 1 : 24;
const ok = wave(n, 4200 * scale, 1300 * scale, 1), bad = wave(n, 30 * scale, 18 * scale, 4).map((v) => Math.max(0, v));
const loading = state === 'loading', empty = state === 'new', error = state === 'error' ? c.chartFail : undefined;
const header = <PageHeader title={c.title} lead={c.lead} actions={<SegmentedControl label={c.range} value={range} onChange={setRange} options={(['24h', '7d', '30d'] as const).map((r) => ({ value: r, label: c.ranges[r] }))} />} />;
if (empty) {
return (
<Page wide>
{header}
<Panel><EmptyState icon="chart-line" title={c.newTitle} actions={<><Button variant="primary" icon="agent" href="#connect-agent">{c.connect}</Button><Button icon="book" href="#docs">{c.docs}</Button></>}>{c.newBody}</EmptyState></Panel>
</Page>
);
}
const total = ok.reduce((a, b) => a + b, 0), fails = bad.reduce((a, b) => a + b, 0);
return (
<Page wide>
{header}
<StatGroup>
<Stat loading={loading} label={c.requests} value={format.number(total, { notation: 'compact' })} delta={`+12% ${c.vsBefore}`} trend="good" />
<Stat loading={loading} label={c.errors} value={format.percent(fails / total, 2)} delta={`+0.2 pts ${c.vsBefore}`} trend="bad" />
<Stat loading={loading} label={c.p95} value="182" unit="ms" delta={`−14 ms ${c.vsBefore}`} trend="good" />
<Stat loading={loading} label={c.storage} value={format.bytes(8.2 * 1024 ** 3)} delta={`+310 MB ${c.vsBefore}`} trend="flat" />
</StatGroup>
<LineChart title={c.traffic} subtitle={c.trafficSub(range)} x={x} loading={loading} error={error} area
series={[{ id: 'ok', label: c.ok, data: loading ? [] : ok }, { id: 'failed', label: c.failed, data: loading ? [] : bad }]} formatValue={(v) => format.number(v, { notation: 'compact' })} />
<Columns cols={2} stack>
<HorizontalBar title={c.byRoute} subtitle={c.byRouteSub} loading={loading} error={error} items={loading ? [] : [
{ label: 'POST /v1/checkout', value: Math.round(fails * 0.41) }, { label: 'GET /v1/products', value: Math.round(fails * 0.22) },
{ label: 'POST /v1/refunds', value: Math.round(fails * 0.19) }, { label: 'GET /v1/orders/:id', value: Math.round(fails * 0.11) }, { label: 'POST /v1/webhooks', value: Math.round(fails * 0.07) },
]} formatValue={(v) => format.number(v)} />
<Panel title={c.services}>
<Stack gap={4}>
{/* While loading, each service keeps its name; its state is unknown and its detail is a bar as long as the last one. */}
<Health state={loading ? 'unknown' : 'up'} label={c.api} detail={loading ? <SkeletonWords>{c.up}</SkeletonWords> : c.up} />
<Health state={loading ? 'unknown' : 'degraded'} label={c.db} detail={loading ? <SkeletonWords>{c.slowDetail}</SkeletonWords> : c.slowDetail} />
<Health state={loading ? 'unknown' : 'up'} label={c.auth} detail={loading ? <SkeletonWords>{c.up}</SkeletonWords> : c.up} />
<Health state={loading ? 'unknown' : 'up'} label={c.storageSvc} detail={loading ? <SkeletonWords>{c.up}</SkeletonWords> : c.up} />
{loading ? <UptimeBarSkeleton periods={30} /> : <UptimeBar label={c.uptime} from={format.date(new Date(now - 29 * 86400e3))} to={format.date(new Date(now))} periods={Array.from({ length: 30 }, (_, i) => ({ label: format.date(new Date(now - (29 - i) * 86400e3)), state: i === 11 ? 'degraded' : i === 29 ? 'degraded' : 'up' }))} />}
</Stack>
</Panel>
</Columns>
<Panel title={c.team}>
<ActivityFeed label={c.team} loading={loading} items={c.acts.map(([action, target], i) => ({ id: i, actor: { name: ['Ana Ruiz', 'Luis Ortega', 'Ana Ruiz', 'Marta Gil'][i] }, action, target, time: ago((i * 7 + 2) * 3600e3) }))} />
</Panel>
</Page>
);
} On a phone
On a phone the numbers sit two by two and the charts take the width.
A new project
No traffic yet: what to do first, instead of empty charts.
northwind-shop
How the project is doing.
No traffic yet
Skeleton
The real page: each number keeps its name, with value and change as long as theirs; the charts draw their first-load shapes, each service its name with its state unknown, and the activity its last items.
northwind-shop
How the project is doing.
- Answered
- Failed
Services
What the team did
When the charts cannot load
Each chart says so in its own frame; the rest of the page stays.
northwind-shop
How the project is doing.
- Answered
- Failed
These numbers could not be loaded. Try again in a minute.
These numbers could not be loaded. Try again in a minute.
Services
What the team did
- AR
Ana Ruiz deployed version 1.42
- LO
Luis Ortega created the table refunds
- AR
Ana Ruiz invited Kenji Mori
- MG
Marta Gil changed the plan to Pro
When to use it
Use it when
- The home of a project or an organization.
- Four numbers at most at the top, each with how it moved and whether that is good.
Do not use it when
- Empty charts for a new project: say what to do first.
- Colour alone for good and bad: the deltas say it in words too.
For everyone
- Every chart has a title, a subtitle and a table of its values for screen readers.
- The time range is a segmented control; changing it changes every chart.
- Services say their state in words: «Slower than usual», not only a colour.
Props
| LineChart | Type | Default |
|---|---|---|
seriesrequired | Series[] | |
titlerequired | ReactNode | |
xrequiredThe positions along the horizontal axis: dates, hours, names. | string[] | |
areaFills under each line with a light wash: for a quantity that accumulates. | boolean | |
empty | ReactNode | |
error | ReactNode | |
formatValueHow a value is written in ticks, tooltip and table. Defaults to a compact number in the person's language. | ((v: number) => string) | |
height | number | |
loading | boolean | |
subtitle | ReactNode | |
xLabelThe header of the first column of the table view: what `x` is. | string |
| HorizontalBar | Type | Default |
|---|---|---|
itemsrequired | { label: string; value: number; }[] | |
titlerequired | ReactNode | |
empty | ReactNode | |
error | ReactNode | |
formatValue | Fmt | |
height | number | |
keepOrder | boolean | |
labelThe header of the first column of the table view. | string | Name |
loading | boolean | |
loadingRowsOn the first load (`loading` with no items): how many rows will come, drawn as rows of skeleton. Default 5. | number | |
subtitle | ReactNode |
| Health | Type | Default |
|---|---|---|
staterequired | "up" | "degraded" | "down" | "unknown" | |
detail | ReactNode | |
label | ReactNode |