| gio | 3d0bf03 | 2025-06-05 06:57:26 +0000 | [diff] [blame] | 1 | import React, { useMemo } from "react"; |
| gio | 74c6f75 | 2025-07-05 04:10:58 +0000 | [diff] [blame] | 2 | import { useStateStore, useLeadAgent } 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"; |
| gio | 74c6f75 | 2025-07-05 04:10:58 +0000 | [diff] [blame] | 7 | import { ResizableHandle, ResizablePanel, ResizablePanelGroup } from "./components/ui/resizable"; |
| 8 | import { AppNode, NodeType } from "config"; |
| gio | 5fa6696 | 2025-06-13 09:30:40 +0000 | [diff] [blame] | 9 | |
| 10 | const sections: { title: string; nodes: NodeType[] }[] = [ |
| 11 | { |
| 12 | title: "Services", |
| 13 | nodes: ["app"], |
| 14 | }, |
| 15 | { |
| 16 | title: "Databases", |
| 17 | nodes: ["postgresql", "mongodb"], |
| 18 | }, |
| 19 | { |
| 20 | title: "File systems", |
| 21 | nodes: ["volume"], |
| 22 | }, |
| 23 | ]; |
| gio | da12043 | 2025-06-02 09:42:26 +0000 | [diff] [blame] | 24 | |
| 25 | export function Overview(): React.ReactNode { |
| gio | 74c6f75 | 2025-07-05 04:10:58 +0000 | [diff] [blame] | 26 | const leadAgent = useLeadAgent(); |
| 27 | if (leadAgent) { |
| 28 | return ( |
| 29 | <ResizablePanelGroup direction="horizontal" className="w-full h-full"> |
| 30 | <ResizablePanel defaultSize={25}> |
| 31 | <iframe |
| 32 | key={leadAgent.name} |
| 33 | src={`${leadAgent.address}?m`} |
| 34 | title={leadAgent.agentName} |
| 35 | className="w-full h-full" |
| 36 | /> |
| 37 | </ResizablePanel> |
| 38 | <ResizableHandle withHandle /> |
| 39 | <ResizablePanel defaultSize={75} className="!overflow-y-auto !overflow-x-hidden"> |
| 40 | <OverviewImpl /> |
| 41 | </ResizablePanel> |
| 42 | </ResizablePanelGroup> |
| 43 | ); |
| 44 | } else { |
| 45 | return <OverviewImpl />; |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | function OverviewImpl(): React.ReactNode { |
| gio | 3d0bf03 | 2025-06-05 06:57:26 +0000 | [diff] [blame] | 50 | const store = useStateStore(); |
| gio | 3fb133d | 2025-06-13 07:20:24 +0000 | [diff] [blame] | 51 | const nodes = useMemo(() => { |
| gio | 5fa6696 | 2025-06-13 09:30:40 +0000 | [diff] [blame] | 52 | 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] | 53 | }, [store.nodes]); |
| gio | 5fa6696 | 2025-06-13 09:30:40 +0000 | [diff] [blame] | 54 | const groupedNodes = useMemo(() => { |
| 55 | return sections |
| 56 | .map((s) => ({ |
| 57 | title: s.title, |
| 58 | nodes: nodes.filter((n) => s.nodes.includes(n.type)), |
| 59 | })) |
| 60 | .filter((s) => s.nodes.length > 0); |
| 61 | }, [nodes]); |
| gio | 3d0bf03 | 2025-06-05 06:57:26 +0000 | [diff] [blame] | 62 | const isDeployMode = useMemo(() => store.mode === "deploy", [store.mode]); |
| gio | da12043 | 2025-06-02 09:42:26 +0000 | [diff] [blame] | 63 | return ( |
| gio | 3d0bf03 | 2025-06-05 06:57:26 +0000 | [diff] [blame] | 64 | <div className="h-full w-full overflow-auto bg-white p-2"> |
| 65 | <div className="w-full flex flex-row justify-end"> |
| gio | 1037ee2 | 2025-06-26 09:25:43 +0000 | [diff] [blame] | 66 | <Actions isOverview={true} /> |
| gio | 3d0bf03 | 2025-06-05 06:57:26 +0000 | [diff] [blame] | 67 | <Canvas className="hidden" /> |
| gio | da12043 | 2025-06-02 09:42:26 +0000 | [diff] [blame] | 68 | </div> |
| gio | 5fa6696 | 2025-06-13 09:30:40 +0000 | [diff] [blame] | 69 | <div className="flex flex-col gap-4 pt-2"> |
| 70 | {groupedNodes.map((s, index) => ( |
| 71 | <> |
| 72 | {index > 0 && <Separator />} |
| 73 | <Section key={s.title} title={s.title} nodes={s.nodes} isDeployMode={isDeployMode} /> |
| 74 | </> |
| 75 | ))} |
| 76 | </div> |
| 77 | </div> |
| 78 | ); |
| 79 | } |
| 80 | |
| 81 | function Section({ |
| 82 | title, |
| 83 | nodes, |
| 84 | isDeployMode, |
| 85 | }: { |
| 86 | title: string; |
| 87 | nodes: AppNode[]; |
| 88 | isDeployMode: boolean; |
| 89 | }): React.ReactNode { |
| 90 | if (nodes.length === 0) return null; |
| 91 | return ( |
| 92 | <div className="w-full"> |
| 93 | <h2 className="text-lg font-semibold mb-2">{title}</h2> |
| 94 | <div className="flex flex-wrap gap-4 pl-4"> |
| 95 | {nodes.map((n) => ( |
| 96 | <NodeDetails |
| 97 | key={n.id} |
| 98 | node={n} |
| 99 | disabled={isDeployMode} |
| 100 | showName={true} |
| gio | e7734b2 | 2025-06-13 10:12:04 +0000 | [diff] [blame] | 101 | isOverview={true} |
| gio | 5fa6696 | 2025-06-13 09:30:40 +0000 | [diff] [blame] | 102 | className="min-w-[500px] rounded-lg border-gray-200 border-2 p-2" |
| 103 | /> |
| 104 | ))} |
| gio | da12043 | 2025-06-02 09:42:26 +0000 | [diff] [blame] | 105 | </div> |
| gio | 3d0bf03 | 2025-06-05 06:57:26 +0000 | [diff] [blame] | 106 | </div> |
| gio | da12043 | 2025-06-02 09:42:26 +0000 | [diff] [blame] | 107 | ); |
| 108 | } |