{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "deployments-04",
  "description": "The latest runs of each pipeline as a strip of results, with the pass rate and median duration.",
  "registryDependencies": [
    "card",
    "https://www.dashboardblocks.com/r/radix/block-state.json",
    "https://www.dashboardblocks.com/r/radix/deployments.json",
    "https://www.dashboardblocks.com/r/radix/format.json",
    "https://www.dashboardblocks.com/r/radix/status-label.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/deployments/deployments-04.tsx",
      "content": "'use client'\n\nimport {\n  BlockReady,\n  BlockStateProvider,\n  BlockStateRows,\n  type BlockStateProps,\n  getBlockState,\n} from '@/registry/components/dashboardblocks/block-state'\nimport {\n  DeployHistory,\n  type DeployStatus,\n  deployStatusConfig,\n  formatDuration,\n} from '@/registry/components/dashboardblocks/deployments'\nimport {\n  StatusLabel,\n  type StatusTone,\n} from '@/registry/components/dashboardblocks/status-label'\nimport { formatPercent } from '@/registry/lib/dashboardblocks/format'\n\nimport { Card, CardContent } from '@/components/ui/card'\n\nimport { cn } from '@/lib/utils'\n\ninterface Pipeline {\n  /** Median seconds per run. */\n  medianDuration: number\n  name: string\n  /** Oldest first. */\n  runs: DeployStatus[]\n}\n\ninterface Deployments4Props extends BlockStateProps {\n  /** Defaults to a sentence naming the pipeline that fails most. */\n  description?: string\n  /** Leave out, or pass none, to show the empty state. */\n  pipelines?: Pipeline[]\n  title: string\n}\n\nconst pattern = (runs: string) =>\n  runs\n    .split('')\n    .map(\n      (run) =>\n        ({ f: 'failed', q: 'queued', r: 'running', s: 'success' })[run] as DeployStatus,\n    )\n\nconst exampleProps: Deployments4Props = {\n  pipelines: [\n    {\n      medianDuration: 412,\n      name: 'main',\n      runs: pattern('sssssfsssssssssssssfssssssssss'),\n    },\n    {\n      medianDuration: 1_386,\n      name: 'release',\n      runs: pattern('sssssssssssssssssssssssssssssr'),\n    },\n    {\n      medianDuration: 2_904,\n      name: 'nightly e2e',\n      runs: pattern('ssfssffsssfsssssffssssfsssfsss'),\n    },\n    {\n      medianDuration: 228,\n      name: 'docs',\n      runs: pattern('ssssssssssssssssssssssssssssss'),\n    },\n  ],\n  title: 'Build health',\n}\n\nconst LEGEND: DeployStatus[] = ['success', 'failed', 'running']\n\nconst HEALTHY_RATE = 0.95\n\nconst passRate = (runs: DeployStatus[]) => {\n  const finished = runs.filter((run) => run === 'success' || run === 'failed')\n  const passed = finished.filter((run) => run === 'success').length\n  return {\n    failed: finished.length - passed,\n    finished: finished.length,\n    passed,\n    rate: finished.length > 0 ? passed / finished.length : 0,\n  }\n}\n\nconst rateTone = (rate: number): StatusTone =>\n  rate >= HEALTHY_RATE ? 'good' : rate >= 0.8 ? 'warning' : 'bad'\n\nconst summarize = (pipelines: Pipeline[]) => {\n  if (pipelines.length === 0) return 'No pipelines yet.'\n  const healthy = pipelines.filter(\n    (pipeline) => passRate(pipeline.runs).rate >= HEALTHY_RATE,\n  ).length\n  return `${healthy} of ${pipelines.length} pipelines pass ${formatPercent(HEALTHY_RATE)} of runs.`\n}\n\nconst Deployments4 = (props: Deployments4Props) => {\n  const { pipelines = [], errorMessage, status, title } = props\n  const { description = summarize(pipelines) } = props\n\n  return (\n    <Card>\n      <CardContent>\n        <BlockStateProvider\n          errorMessage={errorMessage}\n          state={getBlockState(status, pipelines)}\n        >\n          <section className='@container flex flex-col gap-4'>\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            <div className='border-t'>\n              <BlockStateRows rows={4} />\n              <ul className='flex flex-col empty:hidden'>\n                {!status &&\n                  pipelines.map((pipeline) => {\n                    const { failed, finished, passed, rate } = passRate(pipeline.runs)\n                    return (\n                      <li\n                        key={pipeline.name}\n                        className='flex flex-col gap-2 border-b py-3'\n                      >\n                        <div className='flex items-baseline justify-between gap-3'>\n                          <span className='truncate font-mono text-sm font-medium'>\n                            {pipeline.name}\n                          </span>\n                          <span className='flex shrink-0 items-baseline gap-4 text-xs tabular-nums'>\n                            <StatusLabel variant='text' tone={rateTone(rate)}>\n                              {formatPercent(rate, {\n                                maximumFractionDigits: 0,\n                              })}{' '}\n                              passed\n                            </StatusLabel>\n                            <span className='text-muted-foreground w-24 text-right'>\n                              {formatDuration(pipeline.medianDuration)} median\n                            </span>\n                          </span>\n                        </div>\n                        <DeployHistory\n                          runs={pipeline.runs.map((status, index) => ({\n                            id: `${pipeline.name}-${index}`,\n                            status,\n                          }))}\n                        />\n                        <span className='sr-only'>\n                          {`${passed} of ${finished} finished runs passed, ${failed} failed${pipeline.runs.some((run) => run === 'running') ? ', one is running' : ''}.`}\n                        </span>\n                      </li>\n                    )\n                  })}\n              </ul>\n            </div>\n            {pipelines.length > 0 && !status && (\n              <ul\n                aria-hidden\n                className='text-muted-foreground flex flex-wrap gap-x-4 gap-y-1 text-xs'\n              >\n                {LEGEND.map((status) => (\n                  <li key={status} className='flex items-center gap-1.5'>\n                    <span\n                      className={cn(\n                        'size-2.5 rounded-[2px]',\n                        deployStatusConfig[status].cell,\n                      )}\n                    />\n                    {status === 'success' ? 'Passed' : deployStatusConfig[status].label}\n                  </li>\n                ))}\n                <li className='ml-auto'>Oldest on the left</li>\n              </ul>\n            )}\n          </section>\n        </BlockStateProvider>\n      </CardContent>\n    </Card>\n  )\n}\n\nexport {\n  Deployments4,\n  exampleProps as deployments4ExampleProps,\n  type Deployments4Props,\n  type Pipeline,\n}\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/deployments/deployments-04.tsx"
    }
  ],
  "meta": {
    "shows": "The latest runs of each pipeline as a strip of results, with the pass rate and median duration.",
    "size": "half",
    "usedWith": [
      "deployments-01",
      "deployments-03"
    ],
    "component": "Deployments4",
    "props": "{ description?: string; pipelines?: { medianDuration: number; name: string; runs: (\"success\" | \"failed\" | \"running\" | \"queued\" | \"rolled-back\")[] }[]; title: string; errorMessage?: string; status?: \"loading\" | \"error\" }"
  },
  "type": "registry:component"
}
