import type { PropsWithChildren } from 'react' import { Badge, StatusIcon, Tooltip, TooltipContent, TooltipTrigger } from 'ui' import { ActionName, ActionStatus, type ActionRunStep } from '@/data/actions/action-runs-query' export interface ActionStatusBadgeProps { name: ActionName status: ActionStatus } const UNHEALTHY_STATUES: ActionStatus[] = ['DEAD', 'REMOVING'] const WAITING_STATUSES: ActionStatus[] = ['CREATED', 'RESTARTING', 'RUNNING'] export const STATUS_TO_LABEL: Record = { CREATED: 'pending', DEAD: 'failed', EXITED: 'succeeded', PAUSED: 'skipped', REMOVING: 'failed', RESTARTING: 'restarting', RUNNING: 'running', } const NAME_TO_LABEL: Record = { clone: 'Cloning repo', pull: 'Pulling data', health: 'Health check', configure: 'Configurations', migrate: 'Migrations', seed: 'Data seeding', deploy: 'Functions deployment', } export const ActionStatusBadgeCondensed = ({ children, status, details, }: PropsWithChildren<{ status: ActionStatus details: Array }>) => { if (status === 'EXITED') { return null } const isUnhealthy = UNHEALTHY_STATUES.includes(status) return ( {isUnhealthy && } {children} Additional {STATUS_TO_LABEL[status]} steps:
    {details.map((step) => (
  • {NAME_TO_LABEL[step.name]}
  • ))}
) } export const ActionStatusBadge = ({ name, status }: ActionStatusBadgeProps) => { if (status === 'EXITED') { return null } const isUnhealthy = UNHEALTHY_STATUES.includes(status) const isWaiting = WAITING_STATUSES.includes(status) return ( {(isUnhealthy || isWaiting) && ( )} {NAME_TO_LABEL[name]}: {STATUS_TO_LABEL[status]} ) }