|
2 | 2 |
|
3 | 3 | import { |
4 | 4 | Background, |
5 | | - type Connection, |
6 | | - type Edge, |
7 | 5 | ReactFlow, |
8 | 6 | useEdgesState, |
9 | 7 | useNodesState, |
@@ -66,76 +64,73 @@ const CustomizableStack = () => { |
66 | 64 | }, |
67 | 65 | })), |
68 | 66 | ); |
69 | | - |
70 | | - const sourceNodes = nodes.filter( |
71 | | - (n) => n.data.isActive && !n.data.isStatic, |
72 | | - ); |
73 | | - const targetNode = nodes.find((n) => n.id === techId); |
74 | | - |
75 | | - if (!targetNode) return; |
76 | | - |
77 | 67 | setEdges((eds) => |
78 | | - eds.filter( |
79 | | - (edge) => |
80 | | - !nodes.some( |
81 | | - (n) => |
82 | | - n.data.category === category && |
83 | | - (edge.source === n.id || edge.target === n.id), |
84 | | - ), |
85 | | - ), |
| 68 | + eds.filter((edge) => { |
| 69 | + const targetNode = nodes.find((n) => n.id === edge.target); |
| 70 | + const sourceNode = nodes.find((n) => n.id === edge.source); |
| 71 | + return !( |
| 72 | + targetNode?.data.category === category || |
| 73 | + sourceNode?.data.category === category |
| 74 | + ); |
| 75 | + }), |
86 | 76 | ); |
87 | 77 |
|
88 | | - setEdges((eds) => [ |
89 | | - ...eds, |
90 | | - ...sourceNodes.map((source) => ({ |
91 | | - id: `${source.id}-${techId}`, |
92 | | - source: source.id, |
93 | | - target: techId, |
94 | | - animated: true, |
95 | | - })), |
96 | | - ]); |
| 78 | + if (category === "database") { |
| 79 | + const honoNode = nodes.find((n) => n.id === "hono"); |
| 80 | + const ormNode = nodes.find( |
| 81 | + (n) => n.data.category === "orm" && n.data.isActive, |
| 82 | + ); |
| 83 | + |
| 84 | + if (honoNode && ormNode) { |
| 85 | + setEdges((eds) => [ |
| 86 | + ...eds, |
| 87 | + { |
| 88 | + id: `hono-${techId}`, |
| 89 | + source: "hono", |
| 90 | + target: techId, |
| 91 | + animated: true, |
| 92 | + }, |
| 93 | + { |
| 94 | + id: `${techId}-${ormNode.id}`, |
| 95 | + source: techId, |
| 96 | + target: ormNode.id, |
| 97 | + animated: true, |
| 98 | + }, |
| 99 | + ]); |
| 100 | + } |
| 101 | + } else if (category === "auth") { |
| 102 | + setEdges((eds) => [ |
| 103 | + ...eds, |
| 104 | + { |
| 105 | + id: `hono-${techId}`, |
| 106 | + source: "hono", |
| 107 | + target: techId, |
| 108 | + animated: true, |
| 109 | + }, |
| 110 | + ]); |
| 111 | + } else if (category === "orm") { |
| 112 | + const dbNode = nodes.find( |
| 113 | + (n) => n.data.category === "database" && n.data.isActive, |
| 114 | + ); |
| 115 | + if (dbNode) { |
| 116 | + setEdges((eds) => [ |
| 117 | + ...eds, |
| 118 | + { |
| 119 | + id: `${dbNode.id}-${techId}`, |
| 120 | + source: dbNode.id, |
| 121 | + target: techId, |
| 122 | + animated: true, |
| 123 | + }, |
| 124 | + ]); |
| 125 | + } |
| 126 | + } |
97 | 127 | }, |
98 | 128 | [nodes, setNodes, setEdges], |
99 | 129 | ); |
100 | 130 |
|
101 | | - const onConnect = useCallback( |
102 | | - (connection: Connection) => { |
103 | | - const sourceNode = nodes.find((n) => n.id === connection.source); |
104 | | - const targetNode = nodes.find((n) => n.id === connection.target); |
105 | | - |
106 | | - if (!sourceNode || !targetNode) return; |
107 | | - |
108 | | - if (sourceNode.data.group === targetNode.data.group) { |
109 | | - return; |
110 | | - } |
111 | | - |
112 | | - const edgesToRemove = edges.filter((edge) => { |
113 | | - const edgeTarget = nodes.find((n) => n.id === edge.target); |
114 | | - return edgeTarget?.data.group === targetNode.data.group; |
115 | | - }); |
116 | | - |
117 | | - setEdges((eds) => { |
118 | | - const newEdges = eds.filter((edge) => !edgesToRemove.includes(edge)); |
119 | | - return [...newEdges, { ...(connection as Edge), animated: true }]; |
120 | | - }); |
121 | | - |
122 | | - setNodes((nds) => |
123 | | - nds.map((node) => ({ |
124 | | - ...node, |
125 | | - data: { |
126 | | - ...node.data, |
127 | | - isActive: |
128 | | - node.id === connection.source || node.id === connection.target |
129 | | - ? true |
130 | | - : node.data.group !== targetNode.data.group |
131 | | - ? node.data.isActive |
132 | | - : false, |
133 | | - }, |
134 | | - })), |
135 | | - ); |
136 | | - }, |
137 | | - [nodes, edges, setEdges, setNodes], |
138 | | - ); |
| 131 | + const onConnect = useCallback(() => { |
| 132 | + return; |
| 133 | + }, []); |
139 | 134 |
|
140 | 135 | const generateCommand = useCallback(() => { |
141 | 136 | const flags: string[] = ["-y"]; |
|
0 commit comments