| gio | 5f2f100 | 2025-03-20 18:38:48 +0400 | [diff] [blame] | 1 | import { useNodes } from "@xyflow/react"; |
| 2 | import { AppNode, nodeLabel, ServiceNode } from "./lib/state"; |
| 3 | import { useMemo } from "react"; |
| 4 | import { Table, TableBody, TableCaption, TableCell, TableHead, TableHeader, TableRow } from "./components/ui/table"; |
| 5 | |
| 6 | function ingress(nodes: AppNode[]) { |
| 7 | const nm = new Map(nodes.map((n) => [n.id, n])); |
| 8 | return nodes.filter((n) => n.type === "gateway-https").map((i) => { |
| 9 | console.log(i.data); |
| 10 | if (!i.data || !i.data.network || !i.data.subdomain) { |
| 11 | return null; |
| 12 | } |
| 13 | if (!i.data.https || !i.data.https.serviceId || !i.data.https.portId) { |
| 14 | return null; |
| 15 | } |
| 16 | console.log("1231"); |
| 17 | const svc = nm.get(i.data.https.serviceId)! as ServiceNode; |
| 18 | const port = svc.data.ports.find((p) => p.id === i.data.https!.portId)!; |
| 19 | console.log({svc, port}); |
| 20 | return { |
| 21 | id: `${i.id} - ${port.id}`, |
| 22 | service: svc, |
| 23 | port: port, |
| 24 | endpoint: `https://${i.data.subdomain}.${i.data.network}`, |
| 25 | }; |
| 26 | }).filter((i) => i != null); |
| 27 | } |
| 28 | |
| 29 | export function Deployment() { |
| 30 | const nodes = useNodes<AppNode>(); |
| 31 | const ing = useMemo(() => ingress(nodes), [nodes]); |
| 32 | return ( |
| 33 | <> |
| 34 | <Table> |
| 35 | <TableCaption>HTTPS Gateways</TableCaption> |
| 36 | <TableHeader> |
| 37 | <TableRow> |
| 38 | <TableHead>Service</TableHead> |
| 39 | <TableHead>Port</TableHead> |
| 40 | <TableHead>Endpoint</TableHead> |
| 41 | </TableRow> |
| 42 | </TableHeader> |
| 43 | <TableBody> |
| 44 | {ing.map((i) => ( |
| 45 | <TableRow> |
| 46 | <TableCell>{nodeLabel(i.service)}</TableCell> |
| 47 | <TableCell>{i.port.name}</TableCell> |
| 48 | <TableCell><a href={i.endpoint} target="_blank">{i.endpoint}</a></TableCell> |
| 49 | </TableRow> |
| 50 | ))} |
| 51 | </TableBody> |
| 52 | </Table> |
| 53 | </> |
| 54 | ); |
| 55 | } |