Skip to content

Commit 91c2340

Browse files
committed
feat(hooks): add condition edge label sync for switch nodes
Implement label synchronization for condition edges originating from switch nodes. The hook now automatically updates edge labels based on the connected condition's properties, similar to how it handles simple edges.
1 parent 6dcf008 commit 91c2340

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/lib/src/hooks/useEdgeLabelSync.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ export function useEdgeLabelSync(nodes, edges, updateEdges) {
99
let hasChanges = false;
1010
const updatedEdges = edges.map(edge => {
1111
const targetNode = nodes.find(node => node.id === edge.target);
12+
const sourceNode = nodes.find(node => node.id === edge.source);
1213

14+
// Handle simple edges (non-switch nodes)
1315
if (targetNode && edge.label && edge.label.startsWith('→')) {
1416
const expectedLabel = `→ ${targetNode.data?.name || targetNode.data?.label || 'next'}`;
1517

@@ -19,6 +21,30 @@ export function useEdgeLabelSync(nodes, edges, updateEdges) {
1921
}
2022
}
2123

24+
// Handle condition edges from switch nodes
25+
if (sourceNode && sourceNode.type === 'switch' && edge.sourceHandle && edge.sourceHandle.startsWith('condition-')) {
26+
const conditionIndex = parseInt(edge.sourceHandle.replace('condition-', ''));
27+
const conditions = sourceNode.data?.dataConditions || sourceNode.data?.eventConditions || [];
28+
const condition = conditions[conditionIndex];
29+
30+
// Determine expected label based on condition type
31+
let expectedLabel = '';
32+
if (condition) {
33+
if (sourceNode.data?.conditionType === 'event') {
34+
expectedLabel = condition.name || condition.eventRef || `event${conditionIndex + 1}`;
35+
} else {
36+
expectedLabel = condition.name || condition.condition || `condition${conditionIndex + 1}`;
37+
}
38+
} else {
39+
expectedLabel = `condition${conditionIndex + 1}`;
40+
}
41+
42+
if (edge.label !== expectedLabel) {
43+
hasChanges = true;
44+
return { ...edge, label: expectedLabel };
45+
}
46+
}
47+
2248
return edge;
2349
});
2450

0 commit comments

Comments
 (0)