import { useId, useState } from 'react' import { useTranslation } from 'react-i18next' import { Link } from '@tanstack/react-router' import { ChevronRightGlassIcon } from '@thesvg/ui-react' import { useDeployWhy } from '../queries/deployWhy' // Panel budget: verdict, exit, health, then the top clusters up to this many lines in all. const MAX_LINES = 5 /** DeployWhyPanel answers "why did this deploy fail" from the stored verdict, loaded on open. */ export function DeployWhyPanel({ appName, deployId, }: { appName: string deployId: string }) { const { t } = useTranslation('gitBuild') const [open, setOpen] = useState(false) const bodyId = useId() const { data, isPending, isError } = useDeployWhy(deployId, open) const lines: string[] = [] if (data) { lines.push(t(`why.verdict.${data.verdict}`, { defaultValue: data.verdict })) if (data.exit_code !== undefined) { lines.push(t('why.exit', { code: data.exit_code })) } if (data.health) { lines.push( t(data.health.success ? 'why.healthOk' : 'why.healthFailed', { target: data.health.target, }), ) } for (const tpl of data.new_templates) { lines.push(t('why.template', { count: tpl.count, sample: tpl.sample })) } } const shown = lines.slice(0, MAX_LINES) return (
) }