"use client"; import { useMemo } from "react"; import { DashboardLayout } from "@/components/dashboard/DashboardLayout"; import { Card, CardContent, CardDescription, CardTitle, } from "@/components/ui/card"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import { Plus, Play, Pause, Square, RotateCcw } from "lucide-react"; import { getDeployments, removeDeployment, toggleDeployment, } from "@/lib/dockship/deploy"; import { getApps } from "@/lib/dockship/application"; import { cn } from "@/lib/utils"; import DeployAppDialog from "@/components/dialogs/DeployApp"; import { useAsync, useAsyncInterval } from "@/hooks/use-async"; import RemoveDialog from "@/components/dialogs/Remove"; import { Application } from "@/lib/types"; const statusDot = { running: "bg-chart-2", pending: "bg-chart-1", stopped: "bg-slate-400 dark:bg-slate-600", } as const; export default function DeploymentsPage() { const { value: apps } = useAsyncInterval("apps", [], getApps, 5000); const { value: deployments, loading } = useAsync( "deployments", [], getDeployments, [apps], ); const appByContainer = useMemo(() => { const map = new Map(); for (const app of apps) { for (const container of app.deployments) { map.set(container, app); } } return map; }, [apps]); const changeDeploymentStatus = async ( deployId: string, action: "start" | "stop", ) => { console.log(`Toggling deployment ${deployId} with action ${action}`); await toggleDeployment(deployId, action); }; const remove = async (deployId: string) => { console.log(`Removing deployment ${deployId}`); await removeDeployment(deployId); }; return ( {/* Header */}
{loading ? "Loading…" : `${deployments.length} deployment${deployments.length > 0 && "s"}`}
{deployments.map((dep) => { return (
{dep.name} @{" "} {appByContainer.get(dep.container)?.name ?? "Unknown app"} {dep.ports.map(([to, from]) => ( {from} → {to} ))}

{dep.image}

({ containerPort: from.toString(), hostPort: to.toString(), protocol: "tcp", }))} nodeId={dep.nodeId} > remove(dep.container)} />
); })}
); }