Fix a bug where the first node wouldn't be added correctly (#1213)

This commit is contained in:
Shuchang Zheng
2024-11-18 08:28:08 -08:00
committed by GitHub
parent 3d6c1dd60c
commit 37fd1ffa99
2 changed files with 10 additions and 7 deletions

View File

@@ -317,7 +317,7 @@ function FlowRenderer({
newNodes.push(node); newNodes.push(node);
if (previous) { if (previous) {
const newEdge = { const newEdge = {
id: `edge-${previous}-${id}`, id: nanoid(),
type: "edgeWithAddButton", type: "edgeWithAddButton",
source: previous, source: previous,
target: id, target: id,
@@ -329,7 +329,7 @@ function FlowRenderer({
} }
if (next) { if (next) {
const newEdge = { const newEdge = {
id: `edge-${id}-${next}`, id: nanoid(),
type: connectingEdgeType, type: connectingEdgeType,
source: id, source: id,
target: next, target: next,

View File

@@ -376,7 +376,10 @@ function getElements(blocks: Array<WorkflowBlock>): {
const nodes: Array<AppNode> = []; const nodes: Array<AppNode> = [];
const edges: Array<Edge> = []; const edges: Array<Edge> = [];
data.forEach((d) => { const startNodeId = nanoid();
nodes.push(startNode(startNodeId));
data.forEach((d, index) => {
const node = convertToNode( const node = convertToNode(
{ {
id: d.id, id: d.id,
@@ -388,6 +391,9 @@ function getElements(blocks: Array<WorkflowBlock>): {
if (d.previous) { if (d.previous) {
edges.push(edgeWithAddButton(d.previous, d.id)); edges.push(edgeWithAddButton(d.previous, d.id));
} }
if (index === 0) {
edges.push(edgeWithAddButton(startNodeId, d.id));
}
}); });
const loopBlocks = data.filter((d) => d.block.block_type === "for_loop"); const loopBlocks = data.filter((d) => d.block.block_type === "for_loop");
@@ -411,18 +417,15 @@ function getElements(blocks: Array<WorkflowBlock>): {
} }
}); });
const startNodeId = nanoid();
const adderNodeId = nanoid(); const adderNodeId = nanoid();
if (nodes.length === 0) { if (data.length === 0) {
nodes.push(startNode(startNodeId));
nodes.push(nodeAdderNode(adderNodeId)); nodes.push(nodeAdderNode(adderNodeId));
edges.push(defaultEdge(startNodeId, adderNodeId)); edges.push(defaultEdge(startNodeId, adderNodeId));
} else { } else {
const firstNode = data.find( const firstNode = data.find(
(d) => d.previous === null && d.parentId === null, (d) => d.previous === null && d.parentId === null,
); );
nodes.push(startNode(startNodeId));
edges.push(edgeWithAddButton(startNodeId, firstNode!.id)); edges.push(edgeWithAddButton(startNodeId, firstNode!.id));
const lastNode = data.find((d) => d.next === null && d.parentId === null)!; const lastNode = data.find((d) => d.next === null && d.parentId === null)!;
edges.push(defaultEdge(lastNode.id, adderNodeId)); edges.push(defaultEdge(lastNode.id, adderNodeId));