"use client"; import { DashboardLayout } from "@/components/dashboard/DashboardLayout"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import { MoreVertical, Play, Square, Trash2, Container, } from "lucide-react"; import { useEffect, useState } from "react"; import { Docker } from "@/lib/types"; import { getDocker } from "@/core/docker"; import { getNodes } from "@/core/node"; import { ContainerInfo } from "dockerode"; type ContainerSummary = { id: string; name: string; image: string; node: string; status: "running" | "stopped"; uptime: string; cpu: string; memory: string; }; function summarizeContainer( container: ContainerInfo, nodeName: string ): ContainerSummary { // 1. Shorten the long container ID const shortId = container.Id.slice(0, 12); // 2. Clean the name const name = container.Names[0]?.replace(/^\//, "") ?? "unknown"; // 3. Normalize status const status = container.State === "running" ? "running" : "stopped"; // 4. Compute uptime from Status string (if available) const uptime = container.Status?.replace(/^Up\s*/, "") ?? "unknown"; // 5. Placeholder for CPU and memory const cpu = "4%"; const memory = "64MB / 128MB"; return { id: shortId, name, image: container.Image, node: nodeName, status, uptime, cpu, memory, }; } export default function ContainersPage() { const [containers, setContainers] = useState([]); useEffect(() => { const fetchNodes = async () => { const nodes = await getNodes(); const dockerNodes = await getDocker(nodes); setContainers( nodes.flatMap((node, i) => dockerNodes[i].containers.map((c) => summarizeContainer(c, node.name)) ) ); }; fetchNodes(); }, []); return ( {/* Stats */}
{containers.length} containers {containers.filter((c) => c.status === "running").length} running
{/* ================= DESKTOP TABLE ================= */}
{[ "Container", "Image", "Node", "Status", "Uptime", "CPU", "Memory", "Actions", ].map((h) => ( ))} {containers.map((container) => ( ))}
{h}
{container.name}
{container.id}
{container.image} {container.node} {/* {container.status} */} {container.uptime} {container.cpu} {container.memory}
{container.status === "running" ? ( ) : ( )}
{/* ================= MOBILE CARDS ================= */}
{containers.map((container) => (
{/* Header */}
{container.name}
{/* {container.status} */}
{container.id}
{container.image}
Node
{container.node}
Uptime
{container.uptime}
CPU
{container.cpu}
Memory
{container.memory}
{container.status === "running" ? ( ) : ( )}
))}
); }