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