{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "status-04",
  "description": "Regions, each with its status, p95 latency bar and error rate.",
  "registryDependencies": [
    "card",
    "https://www.dashboardblocks.com/r/radix/block-state.json",
    "https://www.dashboardblocks.com/r/radix/format.json",
    "https://www.dashboardblocks.com/r/radix/status.json",
    "https://www.dashboardblocks.com/r/radix/table.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/status/status-04.tsx",
      "content": "'use client'\n\nimport {\n  BlockReady,\n  BlockStateProvider,\n  type BlockStateProps,\n  getBlockState,\n} from '@/registry/components/dashboardblocks/block-state'\nimport {\n  StatusIndicator,\n  type StatusLevel,\n  getWorstStatus,\n  statusConfig,\n} from '@/registry/components/dashboardblocks/status'\nimport {\n  DataTable,\n  DataTableBar,\n  DataTableBody,\n  DataTableCell,\n  DataTableHead,\n  DataTableHeader,\n  DataTableRow,\n  DataTableRowHead,\n  DataTableStateRows,\n} from '@/registry/components/dashboardblocks/table'\nimport { formatNumber, formatPercent } from '@/registry/lib/dashboardblocks/format'\n\nimport { Card, CardContent } from '@/components/ui/card'\n\ninterface Region {\n  code: string\n  /** Share of requests that failed, as a percentage. */\n  errorRate: number\n  /** p95, in milliseconds. */\n  latency: number\n  name: string\n  status: StatusLevel\n}\n\ninterface Status4Props extends BlockStateProps {\n  /** Defaults to a sentence counting the healthy regions and naming the worst. */\n  description?: string\n  /** Leave out, or pass none, to show the empty state. */\n  regions?: Region[]\n  title: string\n}\n\nconst exampleProps: Status4Props = {\n  regions: [\n    {\n      code: 'us-east-1',\n      errorRate: 0.02,\n      latency: 48,\n      name: 'N. Virginia',\n      status: 'operational',\n    },\n    {\n      code: 'us-west-2',\n      errorRate: 0.03,\n      latency: 61,\n      name: 'Oregon',\n      status: 'operational',\n    },\n    {\n      code: 'eu-west-1',\n      errorRate: 0.41,\n      latency: 212,\n      name: 'Ireland',\n      status: 'degraded',\n    },\n    {\n      code: 'eu-central-1',\n      errorRate: 0.01,\n      latency: 57,\n      name: 'Frankfurt',\n      status: 'operational',\n    },\n    {\n      code: 'ap-south-1',\n      errorRate: 4.8,\n      latency: 890,\n      name: 'Mumbai',\n      status: 'partial',\n    },\n    {\n      code: 'ap-northeast-1',\n      errorRate: 0.02,\n      latency: 73,\n      name: 'Tokyo',\n      status: 'operational',\n    },\n  ],\n  title: 'Region health',\n}\n\nconst formatErrors = (percent: number) =>\n  formatPercent(percent / 100, { maximumFractionDigits: 2 })\n\nconst summarize = (regions: Region[]) => {\n  const healthy = regions.filter((region) => region.status === 'operational').length\n  const count = `${healthy} of ${regions.length} regions healthy.`\n  const worstStatus = getWorstStatus(regions.map((region) => region.status))\n  const worst = regions\n    .filter((region) => region.status === worstStatus)\n    .sort((a, b) => b.errorRate - a.errorRate)[0]\n  if (!worst || worstStatus === 'operational') return count\n  return `${count} ${worst.name} ${statusConfig[worst.status].phrase}, with ${formatErrors(worst.errorRate)} of requests failing.`\n}\n\nconst Status4 = (props: Status4Props) => {\n  const { regions = [], errorMessage, status, title } = props\n  const { description = summarize(regions) } = props\n  const state = getBlockState(status, regions)\n  const slowest = Math.max(...regions.map((region) => region.latency), 0)\n\n  return (\n    <Card>\n      <CardContent>\n        <BlockStateProvider errorMessage={errorMessage} state={state}>\n          <section className='@container/data-table flex flex-col gap-3'>\n            <header className='flex flex-col gap-0.5'>\n              <h2 className='font-semibold tracking-tight'>{title}</h2>\n              <BlockReady className='text-sm'>\n                <p className='text-muted-foreground text-sm'>{description}</p>\n              </BlockReady>\n            </header>\n            <DataTable caption={title} className='border-t'>\n              <DataTableHeader>\n                <DataTableRow>\n                  <DataTableHead>Region</DataTableHead>\n                  <DataTableHead>Status</DataTableHead>\n                  <DataTableHead>p95 latency</DataTableHead>\n                  <DataTableHead align='end'>Errors</DataTableHead>\n                </DataTableRow>\n              </DataTableHeader>\n              <DataTableBody>\n                <DataTableStateRows colSpan={4} rows={5} />\n                {!state &&\n                  regions.map((region) => (\n                    <DataTableRow key={region.code}>\n                      <DataTableRowHead primary>\n                        <span className='block'>{region.name}</span>\n                        <span className='text-muted-foreground block font-mono text-xs font-normal'>\n                          {region.code}\n                        </span>\n                      </DataTableRowHead>\n                      <DataTableCell>\n                        <StatusIndicator status={region.status} />\n                      </DataTableCell>\n                      <DataTableCell className='w-2/5'>\n                        <span className='flex w-full items-center gap-3'>\n                          <DataTableBar\n                            className='flex-1'\n                            color={\n                              region.status === 'operational'\n                                ? undefined\n                                : statusConfig[region.status].color\n                            }\n                            max={slowest}\n                            value={region.latency}\n                          />\n                          <span className='w-14 shrink-0 text-end tabular-nums'>\n                            {region.latency > 0\n                              ? `${formatNumber(region.latency)} ms`\n                              : '—'}\n                          </span>\n                        </span>\n                      </DataTableCell>\n                      <DataTableCell align='end'>\n                        {formatErrors(region.errorRate)}\n                      </DataTableCell>\n                    </DataTableRow>\n                  ))}\n              </DataTableBody>\n            </DataTable>\n          </section>\n        </BlockStateProvider>\n      </CardContent>\n    </Card>\n  )\n}\n\nexport { Status4, exampleProps as status4ExampleProps, type Status4Props }\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/status/status-04.tsx"
    }
  ],
  "meta": {
    "shows": "Regions, each with its status, p95 latency bar and error rate.",
    "size": "half",
    "usedWith": [
      "status-01",
      "status-02",
      "alerts-01"
    ],
    "component": "Status4",
    "props": "{ description?: string; regions?: { code: string; errorRate: number; latency: number; name: string; status: \"operational\" | \"degraded\" | \"partial\" | \"major\" | \"maintenance\" | \"unknown\" }[]; title: string; errorMessage?: string; status?: \"loading\" | \"error\" }"
  },
  "type": "registry:component"
}
