|
| 1 | +import { AlertCircle, HardDrive, Network } from "lucide-react"; |
| 2 | +import { Badge } from "@/components/ui/badge"; |
| 3 | +import { TableCell, TableRow } from "@/components/ui/table"; |
| 4 | +import { |
| 5 | + Tooltip, |
| 6 | + TooltipContent, |
| 7 | + TooltipProvider, |
| 8 | + TooltipTrigger, |
| 9 | +} from "@/components/ui/tooltip"; |
| 10 | +import type { ContainerInfo, ContainerStat } from "./types"; |
| 11 | +import { formatCpu, formatIOValue, formatMemUsage } from "./utils"; |
| 12 | + |
| 13 | +interface ContainerRowProps { |
| 14 | + container: ContainerInfo; |
| 15 | + stat: ContainerStat | undefined; |
| 16 | +} |
| 17 | + |
| 18 | +export const ContainerRow = ({ container, stat }: ContainerRowProps) => { |
| 19 | + const isRunning = container.CurrentState.startsWith("Running"); |
| 20 | + const hasError = container.Error && container.Error.trim() !== ""; |
| 21 | + |
| 22 | + const stateBadge = ( |
| 23 | + <Badge |
| 24 | + variant={hasError ? "destructive" : isRunning ? "default" : "destructive"} |
| 25 | + > |
| 26 | + {container.CurrentState} |
| 27 | + </Badge> |
| 28 | + ); |
| 29 | + |
| 30 | + return ( |
| 31 | + <TableRow> |
| 32 | + <TableCell> |
| 33 | + <div className="flex flex-col gap-1"> |
| 34 | + <span className="font-medium text-sm">{container.Name}</span> |
| 35 | + <span className="text-xs text-muted-foreground truncate max-w-[230px]"> |
| 36 | + {container.Image} |
| 37 | + </span> |
| 38 | + </div> |
| 39 | + </TableCell> |
| 40 | + <TableCell> |
| 41 | + {hasError ? ( |
| 42 | + <TooltipProvider> |
| 43 | + <Tooltip> |
| 44 | + <TooltipTrigger asChild> |
| 45 | + <span className="inline-flex items-center gap-1.5 cursor-help"> |
| 46 | + {stateBadge} |
| 47 | + <AlertCircle className="h-3.5 w-3.5 text-destructive" /> |
| 48 | + </span> |
| 49 | + </TooltipTrigger> |
| 50 | + <TooltipContent side="top" className="max-w-xs"> |
| 51 | + <p className="text-xs font-medium">Error:</p> |
| 52 | + <p className="text-xs">{container.Error}</p> |
| 53 | + </TooltipContent> |
| 54 | + </Tooltip> |
| 55 | + </TooltipProvider> |
| 56 | + ) : ( |
| 57 | + stateBadge |
| 58 | + )} |
| 59 | + </TableCell> |
| 60 | + <TableCell className="text-right"> |
| 61 | + {stat ? ( |
| 62 | + <span className="text-sm font-medium">{formatCpu(stat.CPUPerc)}</span> |
| 63 | + ) : ( |
| 64 | + <span className="text-xs text-muted-foreground">--</span> |
| 65 | + )} |
| 66 | + </TableCell> |
| 67 | + <TableCell className="text-right"> |
| 68 | + {stat ? ( |
| 69 | + <span className="text-sm font-medium"> |
| 70 | + {formatMemUsage(stat.MemUsage)} |
| 71 | + </span> |
| 72 | + ) : ( |
| 73 | + <span className="text-xs text-muted-foreground">--</span> |
| 74 | + )} |
| 75 | + </TableCell> |
| 76 | + <TableCell className="text-right"> |
| 77 | + {stat ? ( |
| 78 | + <div className="flex items-center justify-end gap-1.5"> |
| 79 | + <HardDrive className="h-3 w-3 text-muted-foreground" /> |
| 80 | + <span className="text-sm">{formatIOValue(stat.BlockIO)}</span> |
| 81 | + </div> |
| 82 | + ) : ( |
| 83 | + <span className="text-xs text-muted-foreground">--</span> |
| 84 | + )} |
| 85 | + </TableCell> |
| 86 | + <TableCell className="text-right"> |
| 87 | + {stat ? ( |
| 88 | + <div className="flex items-center justify-end gap-1.5"> |
| 89 | + <Network className="h-3 w-3 text-muted-foreground" /> |
| 90 | + <span className="text-sm">{formatIOValue(stat.NetIO)}</span> |
| 91 | + </div> |
| 92 | + ) : ( |
| 93 | + <span className="text-xs text-muted-foreground">--</span> |
| 94 | + )} |
| 95 | + </TableCell> |
| 96 | + </TableRow> |
| 97 | + ); |
| 98 | +}; |
0 commit comments