|
| 1 | +import { useState } from "react"; |
| 2 | +import { Clock, Rocket, Search } from "lucide-react"; |
| 3 | +import { Link, useParams } from "react-router"; |
| 4 | + |
| 5 | +import { Badge } from "~/components/ui/badge"; |
| 6 | +import { |
| 7 | + Breadcrumb, |
| 8 | + BreadcrumbItem, |
| 9 | + BreadcrumbList, |
| 10 | + BreadcrumbPage, |
| 11 | + BreadcrumbSeparator, |
| 12 | +} from "~/components/ui/breadcrumb"; |
| 13 | +import { Button } from "~/components/ui/button"; |
| 14 | +import { Input } from "~/components/ui/input"; |
| 15 | +import { Separator } from "~/components/ui/separator"; |
| 16 | +import { SidebarTrigger } from "~/components/ui/sidebar"; |
| 17 | +import { |
| 18 | + Table, |
| 19 | + TableBody, |
| 20 | + TableCell, |
| 21 | + TableHead, |
| 22 | + TableHeader, |
| 23 | + TableRow, |
| 24 | +} from "~/components/ui/table"; |
| 25 | +import { |
| 26 | + getVersionStatusColor, |
| 27 | + getVersionStatusIcon, |
| 28 | +} from "./_components/helpers"; |
| 29 | +import { mockDeploymentDetail } from "./_components/mockData"; |
| 30 | + |
| 31 | +export function meta() { |
| 32 | + return [ |
| 33 | + { title: "Versions - Deployment Details - Ctrlplane" }, |
| 34 | + { name: "description", content: "View all deployment versions" }, |
| 35 | + ]; |
| 36 | +} |
| 37 | + |
| 38 | +export default function DeploymentVersions() { |
| 39 | + const _deploymentId = useParams().deploymentId; |
| 40 | + |
| 41 | + // In a real app, fetch deployment data based on deploymentId |
| 42 | + const deployment = mockDeploymentDetail; |
| 43 | + // Calculate stats for each version |
| 44 | + const versionsWithStats = deployment.versions.map((version) => { |
| 45 | + const currentReleaseTargets = deployment.releaseTargets.filter( |
| 46 | + (rt) => rt.version.currentId === version.id, |
| 47 | + ); |
| 48 | + const desiredReleaseTargets = deployment.releaseTargets.filter( |
| 49 | + (rt) => rt.version.desiredId === version.id, |
| 50 | + ); |
| 51 | + const blockedReleaseTargets = deployment.releaseTargets.filter((rt) => |
| 52 | + rt.version.blockedVersions?.some((bv) => bv.versionId === version.id), |
| 53 | + ); |
| 54 | + |
| 55 | + const currentEnvironments = new Set( |
| 56 | + currentReleaseTargets.map((rt) => rt.environment.name), |
| 57 | + ); |
| 58 | + const desiredEnvironments = new Set( |
| 59 | + desiredReleaseTargets.map((rt) => rt.environment.name), |
| 60 | + ); |
| 61 | + |
| 62 | + return { |
| 63 | + ...version, |
| 64 | + currentCount: currentReleaseTargets.length, |
| 65 | + desiredCount: desiredReleaseTargets.length, |
| 66 | + blockedCount: blockedReleaseTargets.length, |
| 67 | + currentEnvironments: Array.from(currentEnvironments), |
| 68 | + desiredEnvironments: Array.from(desiredEnvironments), |
| 69 | + }; |
| 70 | + }); |
| 71 | + |
| 72 | + const [searchQuery, setSearchQuery] = useState(""); |
| 73 | + return ( |
| 74 | + <> |
| 75 | + <header className="flex h-16 shrink-0 items-center justify-between gap-2 border-b pr-4"> |
| 76 | + <div className="flex items-center gap-2 px-4"> |
| 77 | + <SidebarTrigger className="-ml-1" /> |
| 78 | + <Separator |
| 79 | + orientation="vertical" |
| 80 | + className="mr-2 data-[orientation=vertical]:h-4" |
| 81 | + /> |
| 82 | + <Breadcrumb> |
| 83 | + <BreadcrumbList> |
| 84 | + <BreadcrumbItem> |
| 85 | + <BreadcrumbItem> |
| 86 | + <Link to={`/deployments`}>Deployments</Link> |
| 87 | + </BreadcrumbItem> |
| 88 | + <BreadcrumbSeparator /> |
| 89 | + <BreadcrumbItem> |
| 90 | + <Link to={`/deployments/${deployment.id}`}> |
| 91 | + {deployment.name} |
| 92 | + </Link> |
| 93 | + </BreadcrumbItem> |
| 94 | + <BreadcrumbSeparator /> |
| 95 | + <BreadcrumbPage>Versions</BreadcrumbPage> |
| 96 | + </BreadcrumbItem> |
| 97 | + </BreadcrumbList> |
| 98 | + </Breadcrumb> |
| 99 | + </div> |
| 100 | + |
| 101 | + <div className="flex min-w-[350px] items-center gap-4"> |
| 102 | + <div className="relative flex-1"> |
| 103 | + <Search className="absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground" /> |
| 104 | + <Input |
| 105 | + placeholder="Search resources..." |
| 106 | + value={searchQuery} |
| 107 | + onChange={(e) => setSearchQuery(e.target.value)} |
| 108 | + className="pl-10" |
| 109 | + /> |
| 110 | + </div> |
| 111 | + </div> |
| 112 | + </header> |
| 113 | + |
| 114 | + <Table> |
| 115 | + <TableHeader> |
| 116 | + <TableRow> |
| 117 | + <TableHead>Version</TableHead> |
| 118 | + <TableHead>Status</TableHead> |
| 119 | + <TableHead>Message</TableHead> |
| 120 | + <TableHead>Current</TableHead> |
| 121 | + <TableHead>Desired</TableHead> |
| 122 | + <TableHead>Blocked</TableHead> |
| 123 | + <TableHead>Created</TableHead> |
| 124 | + <TableHead>Actions</TableHead> |
| 125 | + </TableRow> |
| 126 | + </TableHeader> |
| 127 | + <TableBody> |
| 128 | + {versionsWithStats.map((version) => ( |
| 129 | + <TableRow key={version.id}> |
| 130 | + {/* Version Tag */} |
| 131 | + <TableCell className="font-mono font-semibold"> |
| 132 | + {version.tag} |
| 133 | + </TableCell> |
| 134 | + |
| 135 | + {/* Status */} |
| 136 | + <TableCell> |
| 137 | + <Badge className={getVersionStatusColor(version.status)}> |
| 138 | + {getVersionStatusIcon(version.status)} |
| 139 | + <span className="ml-1 capitalize">{version.status}</span> |
| 140 | + </Badge> |
| 141 | + </TableCell> |
| 142 | + |
| 143 | + {/* Message */} |
| 144 | + <TableCell className="max-w-md"> |
| 145 | + <span className="line-clamp-1 text-sm text-muted-foreground"> |
| 146 | + {version.message ?? "-"} |
| 147 | + </span> |
| 148 | + </TableCell> |
| 149 | + |
| 150 | + {/* Current Deployments */} |
| 151 | + <TableCell> |
| 152 | + <div className="space-y-1"> |
| 153 | + <div className="font-medium">{version.currentCount}</div> |
| 154 | + {version.currentEnvironments.length > 0 && ( |
| 155 | + <div className="flex flex-wrap gap-1"> |
| 156 | + {version.currentEnvironments.map((env) => ( |
| 157 | + <Badge |
| 158 | + key={env} |
| 159 | + variant="outline" |
| 160 | + className="px-1 py-0 text-xs" |
| 161 | + > |
| 162 | + {env} |
| 163 | + </Badge> |
| 164 | + ))} |
| 165 | + </div> |
| 166 | + )} |
| 167 | + </div> |
| 168 | + </TableCell> |
| 169 | + |
| 170 | + {/* Desired Deployments */} |
| 171 | + <TableCell> |
| 172 | + <div className="space-y-1"> |
| 173 | + <div className="font-medium text-blue-600"> |
| 174 | + {version.desiredCount} |
| 175 | + </div> |
| 176 | + {version.desiredEnvironments.length > 0 && ( |
| 177 | + <div className="flex flex-wrap gap-1"> |
| 178 | + {version.desiredEnvironments.map((env) => ( |
| 179 | + <Badge |
| 180 | + key={env} |
| 181 | + variant="outline" |
| 182 | + className="border-blue-500/30 bg-blue-500/5 px-1 py-0 text-xs text-blue-600" |
| 183 | + > |
| 184 | + {env} |
| 185 | + </Badge> |
| 186 | + ))} |
| 187 | + </div> |
| 188 | + )} |
| 189 | + </div> |
| 190 | + </TableCell> |
| 191 | + |
| 192 | + {/* Blocked */} |
| 193 | + <TableCell> |
| 194 | + {version.blockedCount > 0 && ( |
| 195 | + <Badge className="border-amber-500/20 bg-amber-500/10 text-amber-600"> |
| 196 | + {version.blockedCount} |
| 197 | + </Badge> |
| 198 | + )} |
| 199 | + </TableCell> |
| 200 | + |
| 201 | + {/* Created */} |
| 202 | + <TableCell> |
| 203 | + <div className="flex items-center gap-1 text-sm text-muted-foreground"> |
| 204 | + <Clock className="h-3 w-3" /> |
| 205 | + {version.createdAt} |
| 206 | + </div> |
| 207 | + </TableCell> |
| 208 | + |
| 209 | + {/* Actions */} |
| 210 | + <TableCell> |
| 211 | + <div className="flex gap-2"> |
| 212 | + <Link |
| 213 | + to={`/deployments/${deployment.id}?version=${version.id}`} |
| 214 | + > |
| 215 | + <Button variant="ghost" size="sm"> |
| 216 | + View |
| 217 | + </Button> |
| 218 | + </Link> |
| 219 | + {version.desiredCount < deployment.releaseTargets.length && ( |
| 220 | + <Button size="sm" variant="outline"> |
| 221 | + <Rocket className="mr-1 h-4 w-4" /> |
| 222 | + Deploy |
| 223 | + </Button> |
| 224 | + )} |
| 225 | + </div> |
| 226 | + </TableCell> |
| 227 | + </TableRow> |
| 228 | + ))} |
| 229 | + </TableBody> |
| 230 | + </Table> |
| 231 | + </> |
| 232 | + ); |
| 233 | +} |
0 commit comments