Ir al contenido

Dashboard

Un proyecto de un vistazo: las cuatro cifras que importan y cómo se movieron, el tráfico y los errores del periodo elegido, de dónde vienen los errores, si cada servicio funciona, y lo que hizo el equipo.

import { StatGroup, LineChart, HorizontalBar, Health } from '@sypnia/ui/react'

En esta página
  1. En un computador
  2. En un celular
  3. Un proyecto nuevo
  4. Skeleton
  5. Cuando los gráficos no cargan
  6. Cuándo usarlo
  7. Para todos
  8. Props

En un computador

Cambia el periodo: cada cifra y cada gráfico lo siguen.

northwind-shop

Cómo va el proyecto.

Solicitudes880 mil+12% frente al periodo anterior
Errores0,82 %+0.2 pts frente al periodo anterior
Espera del 5 % más lento182ms−14 ms frente al periodo anterior
Almacenamiento8,2 GB+310 MB frente al periodo anterior
Solicitudes y errores
Cada día
  • Respondidas
  • Fallidas
050 mil100 mil150 mil11 nov12 nov13 nov14 nov15 nov16 nov17 nov
Ver como tabla
RespondidasFallidas
11 nov117 mil1,3 mil
12 nov107 mil1,2 mil
13 nov133 mil974
14 nov135 mil1,2 mil
15 nov120 mil974
16 nov140 mil719
17 nov128 mil889
De dónde vienen los errores
Solicitudes fallidas por ruta
  • POST /v1/checkout2957
  • GET /v1/products1586
  • POST /v1/refunds1370
  • GET /v1/orders/:id793
  • POST /v1/webhooks505
Ver como tabla
Name
POST /v1/checkout2957
GET /v1/products1586
POST /v1/refunds1370
GET /v1/orders/:id793
POST /v1/webhooks505

Servicios

APIFuncionaBase de datosLas consultas tardan el doble desde las 14:10Inicio de sesiónFuncionaArchivosFunciona
19 oct 202617 nov 2026

Lo que hizo el equipo

  1. AR

    Ana Ruiz desplegó la versión 1.42

  2. LO

    Luis Ortega creó la tabla refunds

  3. AR

    Ana Ruiz invitó a Kenji Mori

  4. MG

    Marta Gil cambió el plan a Pro

Código
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>
  );
}

En un celular

En un celular las cifras van de a dos y los gráficos ocupan el ancho.

Un proyecto nuevo

Aún sin tráfico: qué hacer primero, en vez de gráficos vacíos.

northwind-shop

Cómo va el proyecto.

Aún no hay tráfico

Las cifras aparecen aquí cuando tu app llame a la API. Conecta tu agente o instala el SDK, y envía la primera solicitud.

Skeleton

La página real: cada cifra conserva su nombre, con el valor y el cambio tan largos como los suyos; las gráficas dibujan su forma de primera carga, cada servicio su nombre con el estado aún desconocido, y la actividad sus últimos elementos.

northwind-shop

Cómo va el proyecto.

Solicitudes
Errores
Espera del 5 % más lento
Almacenamiento
Solicitudes y errores
Cada día
  • Respondidas
  • Fallidas
De dónde vienen los errores
Solicitudes fallidas por ruta

Servicios

APIBase de datosInicio de sesiónArchivos

Lo que hizo el equipo

Cuando los gráficos no cargan

Cada gráfico lo dice en su propio marco; el resto de la página se queda.

northwind-shop

Cómo va el proyecto.

Solicitudes880 mil+12% frente al periodo anterior
Errores0,82 %+0.2 pts frente al periodo anterior
Espera del 5 % más lento182ms−14 ms frente al periodo anterior
Almacenamiento8,2 GB+310 MB frente al periodo anterior
Solicitudes y errores
Cada día
  • Respondidas
  • Fallidas
De dónde vienen los errores
Solicitudes fallidas por ruta

Servicios

APIFuncionaBase de datosLas consultas tardan el doble desde las 14:10Inicio de sesiónFuncionaArchivosFunciona
19 oct 202617 nov 2026

Lo que hizo el equipo

  1. AR

    Ana Ruiz desplegó la versión 1.42

  2. LO

    Luis Ortega creó la tabla refunds

  3. AR

    Ana Ruiz invitó a Kenji Mori

  4. MG

    Marta Gil cambió el plan a Pro

Cuándo usarlo

Úsalo cuando

  • La página de inicio de un proyecto o una organización.
  • Cuatro cifras como mucho arriba, cada una con cómo se movió y si eso es bueno.

No lo uses cuando

  • Gráficos vacíos en un proyecto nuevo: di qué hacer primero.
  • Solo color para lo bueno y lo malo: las variaciones también lo dicen en palabras.

Para todos

  • Cada gráfico tiene título, subtítulo y una tabla de sus valores para los lectores de pantalla.
  • El periodo es un control segmentado; cambiarlo cambia todos los gráficos.
  • Los servicios dicen su estado en palabras: «Más lento de lo normal», no solo un color.

Props

LineChartTipoPor defecto
seriesobligatorio Series[]
titleobligatorio ReactNode
xobligatorio

The positions along the horizontal axis: dates, hours, names.

string[]
area

Fills under each line with a light wash: for a quantity that accumulates.

boolean
empty ReactNode
error ReactNode
formatValue

How 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
xLabel

The header of the first column of the table view: what `x` is.

string
HorizontalBarTipoPor defecto
itemsobligatorio { label: string; value: number; }[]
titleobligatorio ReactNode
empty ReactNode
error ReactNode
formatValue Fmt
height number
keepOrder boolean
label

The header of the first column of the table view.

string Name
loading boolean
loadingRows

On the first load (`loading` with no items): how many rows will come, drawn as rows of skeleton. Default 5.

number
subtitle ReactNode
HealthTipoPor defecto
stateobligatorio "up" | "degraded" | "down" | "unknown"
detail ReactNode
label ReactNode
  1. En un computador
  2. En un celular
  3. Un proyecto nuevo
  4. Skeleton
  5. Cuando los gráficos no cargan
  6. Cuándo usarlo
  7. Para todos
  8. Props

    Busca páginas, secciones y términos