mirror of
https://github.com/FranP-code/create-better-t-stack.git
synced 2025-10-12 23:52:15 +00:00
fix flow diagram nodes issues
This commit is contained in:
@@ -2,8 +2,6 @@
|
|||||||
|
|
||||||
import {
|
import {
|
||||||
Background,
|
Background,
|
||||||
type Connection,
|
|
||||||
type Edge,
|
|
||||||
ReactFlow,
|
ReactFlow,
|
||||||
useEdgesState,
|
useEdgesState,
|
||||||
useNodesState,
|
useNodesState,
|
||||||
@@ -66,76 +64,73 @@ const CustomizableStack = () => {
|
|||||||
},
|
},
|
||||||
})),
|
})),
|
||||||
);
|
);
|
||||||
|
|
||||||
const sourceNodes = nodes.filter(
|
|
||||||
(n) => n.data.isActive && !n.data.isStatic,
|
|
||||||
);
|
|
||||||
const targetNode = nodes.find((n) => n.id === techId);
|
|
||||||
|
|
||||||
if (!targetNode) return;
|
|
||||||
|
|
||||||
setEdges((eds) =>
|
setEdges((eds) =>
|
||||||
eds.filter(
|
eds.filter((edge) => {
|
||||||
(edge) =>
|
const targetNode = nodes.find((n) => n.id === edge.target);
|
||||||
!nodes.some(
|
const sourceNode = nodes.find((n) => n.id === edge.source);
|
||||||
(n) =>
|
return !(
|
||||||
n.data.category === category &&
|
targetNode?.data.category === category ||
|
||||||
(edge.source === n.id || edge.target === n.id),
|
sourceNode?.data.category === category
|
||||||
),
|
);
|
||||||
),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
setEdges((eds) => [
|
if (category === "database") {
|
||||||
...eds,
|
const honoNode = nodes.find((n) => n.id === "hono");
|
||||||
...sourceNodes.map((source) => ({
|
const ormNode = nodes.find(
|
||||||
id: `${source.id}-${techId}`,
|
(n) => n.data.category === "orm" && n.data.isActive,
|
||||||
source: source.id,
|
);
|
||||||
target: techId,
|
|
||||||
animated: true,
|
if (honoNode && ormNode) {
|
||||||
})),
|
setEdges((eds) => [
|
||||||
]);
|
...eds,
|
||||||
|
{
|
||||||
|
id: `hono-${techId}`,
|
||||||
|
source: "hono",
|
||||||
|
target: techId,
|
||||||
|
animated: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: `${techId}-${ormNode.id}`,
|
||||||
|
source: techId,
|
||||||
|
target: ormNode.id,
|
||||||
|
animated: true,
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
} else if (category === "auth") {
|
||||||
|
setEdges((eds) => [
|
||||||
|
...eds,
|
||||||
|
{
|
||||||
|
id: `hono-${techId}`,
|
||||||
|
source: "hono",
|
||||||
|
target: techId,
|
||||||
|
animated: true,
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
} else if (category === "orm") {
|
||||||
|
const dbNode = nodes.find(
|
||||||
|
(n) => n.data.category === "database" && n.data.isActive,
|
||||||
|
);
|
||||||
|
if (dbNode) {
|
||||||
|
setEdges((eds) => [
|
||||||
|
...eds,
|
||||||
|
{
|
||||||
|
id: `${dbNode.id}-${techId}`,
|
||||||
|
source: dbNode.id,
|
||||||
|
target: techId,
|
||||||
|
animated: true,
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
[nodes, setNodes, setEdges],
|
[nodes, setNodes, setEdges],
|
||||||
);
|
);
|
||||||
|
|
||||||
const onConnect = useCallback(
|
const onConnect = useCallback(() => {
|
||||||
(connection: Connection) => {
|
return;
|
||||||
const sourceNode = nodes.find((n) => n.id === connection.source);
|
}, []);
|
||||||
const targetNode = nodes.find((n) => n.id === connection.target);
|
|
||||||
|
|
||||||
if (!sourceNode || !targetNode) return;
|
|
||||||
|
|
||||||
if (sourceNode.data.group === targetNode.data.group) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const edgesToRemove = edges.filter((edge) => {
|
|
||||||
const edgeTarget = nodes.find((n) => n.id === edge.target);
|
|
||||||
return edgeTarget?.data.group === targetNode.data.group;
|
|
||||||
});
|
|
||||||
|
|
||||||
setEdges((eds) => {
|
|
||||||
const newEdges = eds.filter((edge) => !edgesToRemove.includes(edge));
|
|
||||||
return [...newEdges, { ...(connection as Edge), animated: true }];
|
|
||||||
});
|
|
||||||
|
|
||||||
setNodes((nds) =>
|
|
||||||
nds.map((node) => ({
|
|
||||||
...node,
|
|
||||||
data: {
|
|
||||||
...node.data,
|
|
||||||
isActive:
|
|
||||||
node.id === connection.source || node.id === connection.target
|
|
||||||
? true
|
|
||||||
: node.data.group !== targetNode.data.group
|
|
||||||
? node.data.isActive
|
|
||||||
: false,
|
|
||||||
},
|
|
||||||
})),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
[nodes, edges, setEdges, setNodes],
|
|
||||||
);
|
|
||||||
|
|
||||||
const generateCommand = useCallback(() => {
|
const generateCommand = useCallback(() => {
|
||||||
const flags: string[] = ["-y"];
|
const flags: string[] = ["-y"];
|
||||||
|
|||||||
@@ -94,7 +94,7 @@ export const technologies = [
|
|||||||
description: "TypeScript ORM",
|
description: "TypeScript ORM",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "libSQL",
|
name: "Sqlite",
|
||||||
category: "backend",
|
category: "backend",
|
||||||
angle: -30,
|
angle: -30,
|
||||||
icon: Boxes,
|
icon: Boxes,
|
||||||
@@ -171,11 +171,11 @@ export const initialNodes: TechNode[] = [
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: "libsql",
|
id: "sqlite",
|
||||||
type: "techNode",
|
type: "techNode",
|
||||||
position: { x: 544, y: 532 },
|
position: { x: 544, y: 532 },
|
||||||
data: {
|
data: {
|
||||||
label: "libSQL",
|
label: "Sqlite",
|
||||||
category: "database",
|
category: "database",
|
||||||
description: "SQLite-compatible database",
|
description: "SQLite-compatible database",
|
||||||
isDefault: true,
|
isDefault: true,
|
||||||
|
|||||||
Reference in New Issue
Block a user