{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "deployments-03",
  "description": "The four DORA delivery metrics, each with its performance band and the change on the previous period.",
  "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/details.json",
    "https://www.dashboardblocks.com/r/radix/format.json",
    "https://www.dashboardblocks.com/r/radix/stat-group.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/deployments/deployments-03.tsx",
      "content": "'use client'\n\nimport {\n  BlockReady,\n  BlockStateProvider,\n  type BlockStateProps,\n  getBlockState,\n} from '@/registry/components/dashboardblocks/block-state'\nimport {\n  DoraLabel,\n  type DoraInput,\n  getDoraLevels,\n} from '@/registry/components/dashboardblocks/deployments'\nimport { Details } from '@/registry/components/dashboardblocks/details'\nimport {\n  Stat,\n  StatChange,\n  StatGroup,\n  StatLabel,\n  type StatMetric,\n  StatValue,\n} from '@/registry/components/dashboardblocks/stat-group'\nimport { formatNumber, formatPercent } from '@/registry/lib/dashboardblocks/format'\n\nimport { Card, CardContent } from '@/components/ui/card'\n\ninterface Deployments3Props extends BlockStateProps {\n  /** Follows the previous value in each change, such as `the 30 days before`. */\n  comparison?: string\n  /** Leave out to show the empty state. */\n  current?: DoraInput\n  /** Defaults to a sentence counting the elite metrics and naming any that got worse. */\n  description?: string\n  previous?: DoraInput\n  title: string\n}\n\nconst exampleProps: Deployments3Props = {\n  comparison: 'the 30 days before',\n  current: {\n    changeFailureRate: 0.08,\n    deploysPerDay: 3.4,\n    leadTimeHours: 19,\n    restoreHours: 2.5,\n  },\n  previous: {\n    changeFailureRate: 0.11,\n    deploysPerDay: 2.6,\n    leadTimeHours: 27,\n    restoreHours: 1.8,\n  },\n  title: 'Delivery performance',\n}\n\nfunction formatHours(hours: number) {\n  if (hours < 1) return `${formatNumber(hours * 60, { maximumFractionDigits: 0 })} min`\n  if (hours < 48)\n    return `${formatNumber(hours, { maximumFractionDigits: hours < 10 ? 1 : 0 })} h`\n  return `${formatNumber(hours / 24)} days`\n}\n\nconst formatFrequency = (perDay: number) =>\n  perDay >= 1 ? `${formatNumber(perDay)} a day` : `${formatNumber(perDay * 7)} a week`\n\ninterface DoraMetric {\n  goodDirection: 'up' | 'down'\n  hint: string\n  key: keyof DoraInput\n  label: string\n  toStat: (value: number) => Pick<StatMetric, 'changeType' | 'formatter' | 'value'>\n}\n\nconst METRICS: DoraMetric[] = [\n  {\n    goodDirection: 'up',\n    hint: 'How often you ship to production',\n    key: 'deploysPerDay',\n    label: 'Deployment frequency',\n    toStat: (value) => ({ formatter: formatFrequency, value }),\n  },\n  {\n    goodDirection: 'down',\n    hint: 'From commit to production',\n    key: 'leadTimeHours',\n    label: 'Lead time for changes',\n    toStat: (value) => ({ formatter: formatHours, value }),\n  },\n  {\n    goodDirection: 'down',\n    hint: 'Deploys that caused a failure',\n    key: 'changeFailureRate',\n    label: 'Change failure rate',\n    toStat: (value) => ({\n      changeType: 'points',\n      formatter: (percent) => formatPercent(percent / 100),\n      value: value * 100,\n    }),\n  },\n  {\n    goodDirection: 'down',\n    hint: 'To restore service after a failure',\n    key: 'restoreHours',\n    label: 'Time to restore',\n    toStat: (value) => ({ formatter: formatHours, value }),\n  },\n]\n\nconst summarize = (current: DoraInput, previous: DoraInput | undefined) => {\n  const levels = getDoraLevels(current)\n  const elite = METRICS.filter((metric) => levels[metric.key] === 'elite').length\n  const worse = previous\n    ? METRICS.filter((metric) => {\n        const change = current[metric.key] - previous[metric.key]\n        return metric.goodDirection === 'up' ? change < 0 : change > 0\n      })\n    : []\n  const lead = `Elite on ${elite} of the ${METRICS.length} DORA metrics.`\n  if (worse.length === 0) return lead\n  const names = worse.map((metric) => metric.label.toLowerCase()).join(' and ')\n  return `${lead} ${names.charAt(0).toUpperCase()}${names.slice(1)} got worse.`\n}\n\nconst Deployments3 = (props: Deployments3Props) => {\n  const {\n    comparison = 'the period before',\n    current,\n    previous,\n    errorMessage,\n    status,\n    title,\n  } = props\n  const { description = current ? summarize(current, previous) : undefined } = props\n  const levels = current ? getDoraLevels(current) : undefined\n\n  return (\n    <Card>\n      <CardContent>\n        <BlockStateProvider\n          errorMessage={errorMessage}\n          state={getBlockState(status, current)}\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            <StatGroup className='grid-cols-1 @md:grid-cols-2 @3xl:grid-cols-4'>\n              {METRICS.map((metric) => {\n                const stat: ReturnType<DoraMetric['toStat']> = current\n                  ? metric.toStat(current[metric.key])\n                  : { value: 0 }\n                const before = previous?.[metric.key]\n                return (\n                  <Stat key={metric.key}>\n                    <StatLabel>{metric.label}</StatLabel>\n                    <StatValue className='text-3xl @2xl:text-4xl'>\n                      {stat.formatter?.(stat.value)}\n                    </StatValue>\n                    <StatChange\n                      comparison={comparison}\n                      metric={{\n                        ...stat,\n                        goodDirection: metric.goodDirection,\n                        key: metric.key,\n                        label: metric.label,\n                        previous:\n                          before === undefined ? undefined : metric.toStat(before).value,\n                      }}\n                    />\n                    <dd className='text-muted-foreground text-xs'>\n                      <BlockReady className='text-xs'>\n                        {levels && (\n                          <Details>\n                            <DoraLabel\n                              className='text-xs'\n                              level={levels[metric.key]}\n                              variant='text'\n                            />\n                            {metric.hint}\n                          </Details>\n                        )}\n                      </BlockReady>\n                    </dd>\n                  </Stat>\n                )\n              })}\n            </StatGroup>\n          </section>\n        </BlockStateProvider>\n      </CardContent>\n    </Card>\n  )\n}\n\nexport { Deployments3, exampleProps as deployments3ExampleProps, type Deployments3Props }\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/deployments/deployments-03.tsx"
    }
  ],
  "meta": {
    "shows": "The four DORA delivery metrics, each with its performance band and the change on the previous period.",
    "size": "full",
    "usedWith": [
      "deployments-01",
      "deployments-04",
      "chart-panel-01"
    ],
    "component": "Deployments3",
    "props": "{ comparison?: string; current?: { changeFailureRate: number; deploysPerDay: number; leadTimeHours: number; restoreHours: number }; description?: string; previous?: { changeFailureRate: number; deploysPerDay: number; leadTimeHours: number; restoreHours: number }; title: string; errorMessage?: string; status?: \"loading\" | \"error\" }"
  },
  "type": "registry:component"
}
