|
| 1 | +import { PROTECTED_URLS } from '@/configs/urls' |
| 2 | +import { SandboxInfo } from '@/types/api' |
| 3 | +import { Label } from '@/ui/primitives/label' |
| 4 | +import { ChevronLeftIcon, Dot } from 'lucide-react' |
| 5 | +import Link from 'next/link' |
| 6 | +import RanFor from './ran-for' |
| 7 | +import Status from './status' |
| 8 | +import Resource from './resource' |
| 9 | +import CreatedAt from './created_at' |
| 10 | + |
| 11 | +interface SandboxDetailsHeaderProps { |
| 12 | + teamIdOrSlug: string |
| 13 | + sandboxInfo: SandboxInfo |
| 14 | +} |
| 15 | + |
| 16 | +export default function SandboxDetailsHeader({ |
| 17 | + teamIdOrSlug, |
| 18 | + sandboxInfo, |
| 19 | +}: SandboxDetailsHeaderProps) { |
| 20 | + const headerItems = { |
| 21 | + state: { |
| 22 | + label: 'status', |
| 23 | + value: <Status state={sandboxInfo.state} />, |
| 24 | + }, |
| 25 | + templateID: { |
| 26 | + label: 'template id', |
| 27 | + value: sandboxInfo.templateID?.toString(), |
| 28 | + }, |
| 29 | + startedAt: { |
| 30 | + label: 'created at', |
| 31 | + value: <CreatedAt startedAt={sandboxInfo.startedAt} />, |
| 32 | + }, |
| 33 | + endAt: { |
| 34 | + label: sandboxInfo.state === 'running' ? 'running since' : 'ran for', |
| 35 | + value: ( |
| 36 | + <RanFor |
| 37 | + state={sandboxInfo.state} |
| 38 | + startedAt={sandboxInfo.startedAt} |
| 39 | + endAt={sandboxInfo.endAt} |
| 40 | + /> |
| 41 | + ), |
| 42 | + }, |
| 43 | + memoryMB: { |
| 44 | + label: 'mem', |
| 45 | + value: <Resource type="mem" value={sandboxInfo.memoryMB?.toString()} />, |
| 46 | + }, |
| 47 | + cpuCount: { |
| 48 | + label: 'cpu', |
| 49 | + value: <Resource type="cpu" value={sandboxInfo.cpuCount?.toString()} />, |
| 50 | + }, |
| 51 | + } |
| 52 | + |
| 53 | + return ( |
| 54 | + <header className="flex w-full flex-col gap-16 p-8"> |
| 55 | + <div className="flex flex-col gap-1"> |
| 56 | + <Link |
| 57 | + href={PROTECTED_URLS.SANDBOXES(teamIdOrSlug)} |
| 58 | + className="text-fg-300 hover:text-fg flex items-center gap-1.5 transition-colors" |
| 59 | + prefetch |
| 60 | + shallow |
| 61 | + > |
| 62 | + <ChevronLeftIcon className="size-5" /> |
| 63 | + Sandboxes |
| 64 | + </Link> |
| 65 | + <h1 className="text-fg-500 text-2xl font-bold"> |
| 66 | + <span className="text-fg">{sandboxInfo.sandboxID}</span>'S DETAILS |
| 67 | + </h1> |
| 68 | + </div> |
| 69 | + <div className="flex flex-wrap items-center gap-7"> |
| 70 | + {Object.entries(headerItems).map(([key, { label, value }]) => ( |
| 71 | + <HeaderItem key={key} label={label} value={value} /> |
| 72 | + ))} |
| 73 | + </div> |
| 74 | + </header> |
| 75 | + ) |
| 76 | +} |
| 77 | + |
| 78 | +interface HeaderItemProps { |
| 79 | + label: string |
| 80 | + value: string | React.ReactNode |
| 81 | +} |
| 82 | + |
| 83 | +function HeaderItem({ label, value }: HeaderItemProps) { |
| 84 | + return ( |
| 85 | + <div className="flex flex-col gap-2"> |
| 86 | + <Label className="text-fg-500 text-xs uppercase">{label}</Label> |
| 87 | + {typeof value === 'string' ? <p className="text-sm">{value}</p> : value} |
| 88 | + </div> |
| 89 | + ) |
| 90 | +} |
0 commit comments