| gio | 3d0bf03 | 2025-06-05 06:57:26 +0000 | [diff] [blame] | 1 | import React, { useMemo } from "react"; |
| gio | 5fa6696 | 2025-06-13 09:30:40 +0000 | [diff] [blame] | 2 | import { useStateStore, AppNode, NodeType } from "@/lib/state"; |
| gio | 3d0bf03 | 2025-06-05 06:57:26 +0000 | [diff] [blame] | 3 | import { NodeDetails } from "./components/node-details"; |
| 4 | import { Actions } from "./components/actions"; |
| 5 | import { Canvas } from "./components/canvas"; |
| gio | 5fa6696 | 2025-06-13 09:30:40 +0000 | [diff] [blame] | 6 | import { Separator } from "./components/ui/separator"; |
| 7 | |
| 8 | const sections: { title: string; nodes: NodeType[] }[] = [ |
| 9 | { |
| 10 | title: "Services", |
| 11 | nodes: ["app"], |
| 12 | }, |
| 13 | { |
| 14 | title: "Databases", |
| 15 | nodes: ["postgresql", "mongodb"], |
| 16 | }, |
| 17 | { |
| 18 | title: "File systems", |
| 19 | nodes: ["volume"], |
| 20 | }, |
| 21 | ]; |
| gio | da12043 | 2025-06-02 09:42:26 +0000 | [diff] [blame] | 22 | |
| 23 | export function Overview(): React.ReactNode { |
| gio | 3d0bf03 | 2025-06-05 06:57:26 +0000 | [diff] [blame] | 24 | const store = useStateStore(); |
| gio | 3fb133d | 2025-06-13 07:20:24 +0000 | [diff] [blame] | 25 | const nodes = useMemo(() => { |
| gio | 5fa6696 | 2025-06-13 09:30:40 +0000 | [diff] [blame] | 26 | return store.nodes.filter((n) => n.type !== "network" && n.type !== "github" && n.type !== undefined); |
| gio | 3fb133d | 2025-06-13 07:20:24 +0000 | [diff] [blame] | 27 | }, [store.nodes]); |
| gio | 5fa6696 | 2025-06-13 09:30:40 +0000 | [diff] [blame] | 28 | const groupedNodes = useMemo(() => { |
| 29 | return sections |
| 30 | .map((s) => ({ |
| 31 | title: s.title, |
| 32 | nodes: nodes.filter((n) => s.nodes.includes(n.type)), |
| 33 | })) |
| 34 | .filter((s) => s.nodes.length > 0); |
| 35 | }, [nodes]); |
| gio | 3d0bf03 | 2025-06-05 06:57:26 +0000 | [diff] [blame] | 36 | const isDeployMode = useMemo(() => store.mode === "deploy", [store.mode]); |
| gio | da12043 | 2025-06-02 09:42:26 +0000 | [diff] [blame] | 37 | return ( |
| gio | 3d0bf03 | 2025-06-05 06:57:26 +0000 | [diff] [blame] | 38 | <div className="h-full w-full overflow-auto bg-white p-2"> |
| 39 | <div className="w-full flex flex-row justify-end"> |
| 40 | <Actions /> |
| 41 | <Canvas className="hidden" /> |
| gio | da12043 | 2025-06-02 09:42:26 +0000 | [diff] [blame] | 42 | </div> |
| gio | 5fa6696 | 2025-06-13 09:30:40 +0000 | [diff] [blame] | 43 | <div className="flex flex-col gap-4 pt-2"> |
| 44 | {groupedNodes.map((s, index) => ( |
| 45 | <> |
| 46 | {index > 0 && <Separator />} |
| 47 | <Section key={s.title} title={s.title} nodes={s.nodes} isDeployMode={isDeployMode} /> |
| 48 | </> |
| 49 | ))} |
| 50 | </div> |
| 51 | </div> |
| 52 | ); |
| 53 | } |
| 54 | |
| 55 | function Section({ |
| 56 | title, |
| 57 | nodes, |
| 58 | isDeployMode, |
| 59 | }: { |
| 60 | title: string; |
| 61 | nodes: AppNode[]; |
| 62 | isDeployMode: boolean; |
| 63 | }): React.ReactNode { |
| 64 | if (nodes.length === 0) return null; |
| 65 | return ( |
| 66 | <div className="w-full"> |
| 67 | <h2 className="text-lg font-semibold mb-2">{title}</h2> |
| 68 | <div className="flex flex-wrap gap-4 pl-4"> |
| 69 | {nodes.map((n) => ( |
| 70 | <NodeDetails |
| 71 | key={n.id} |
| 72 | node={n} |
| 73 | disabled={isDeployMode} |
| 74 | showName={true} |
| gio | e7734b2 | 2025-06-13 10:12:04 +0000 | [diff] [blame] | 75 | isOverview={true} |
| gio | 5fa6696 | 2025-06-13 09:30:40 +0000 | [diff] [blame] | 76 | className="min-w-[500px] rounded-lg border-gray-200 border-2 p-2" |
| 77 | /> |
| 78 | ))} |
| gio | da12043 | 2025-06-02 09:42:26 +0000 | [diff] [blame] | 79 | </div> |
| gio | 3d0bf03 | 2025-06-05 06:57:26 +0000 | [diff] [blame] | 80 | </div> |
| gio | da12043 | 2025-06-02 09:42:26 +0000 | [diff] [blame] | 81 | ); |
| 82 | } |