Spaces:
Running
Running
Commit ·
a23ac42
1
Parent(s): 82b190a
Refactor active signal propagation to be branch-aware on subgoals so signal flows if downstream is pending
Browse files
src/features/canvas/hooks/useCanvasLogic.js
CHANGED
|
@@ -935,6 +935,29 @@ export const useCanvasLogic = (projectId, user) => {
|
|
| 935 |
const activeNodeIds = new Set();
|
| 936 |
const activeEdgeIds = new Set();
|
| 937 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 938 |
const queue = [];
|
| 939 |
|
| 940 |
nodes.forEach(node => {
|
|
@@ -960,8 +983,8 @@ export const useCanvasLogic = (projectId, user) => {
|
|
| 960 |
if (node.type === 'sketch') {
|
| 961 |
if (edge.sourceHandle && edge.sourceHandle.startsWith('subgoals-source')) {
|
| 962 |
const targetNode = nodes.find(n => n.id === edge.target);
|
| 963 |
-
const
|
| 964 |
-
shouldPropagate = !
|
| 965 |
} else {
|
| 966 |
shouldPropagate = node.data.status === 'Done';
|
| 967 |
}
|
|
@@ -1014,29 +1037,6 @@ export const useCanvasLogic = (projectId, user) => {
|
|
| 1014 |
};
|
| 1015 |
}));
|
| 1016 |
|
| 1017 |
-
// Helper to check if a node itself and all its downstream tree is completed
|
| 1018 |
-
const isNodeAndTreeCompleted = (nodeId, ndsList) => {
|
| 1019 |
-
const queue = [nodeId];
|
| 1020 |
-
const visited = new Set(queue);
|
| 1021 |
-
|
| 1022 |
-
while (queue.length > 0) {
|
| 1023 |
-
const currentId = queue.shift();
|
| 1024 |
-
const currentNode = ndsList.find(node => node.id === currentId);
|
| 1025 |
-
if (!currentNode || currentNode.data.status !== 'Done') {
|
| 1026 |
-
return false;
|
| 1027 |
-
}
|
| 1028 |
-
|
| 1029 |
-
const outEdges = edges.filter(e => e.source === currentId);
|
| 1030 |
-
outEdges.forEach(edge => {
|
| 1031 |
-
if (!visited.has(edge.target)) {
|
| 1032 |
-
visited.add(edge.target);
|
| 1033 |
-
queue.push(edge.target);
|
| 1034 |
-
}
|
| 1035 |
-
});
|
| 1036 |
-
}
|
| 1037 |
-
return true;
|
| 1038 |
-
};
|
| 1039 |
-
|
| 1040 |
setNodes(nds => nds.map(n => {
|
| 1041 |
const isReached = activeNodeIds.has(n.id);
|
| 1042 |
const isNextStep = isReached && n.data.status !== 'Done';
|
|
|
|
| 935 |
const activeNodeIds = new Set();
|
| 936 |
const activeEdgeIds = new Set();
|
| 937 |
|
| 938 |
+
// Helper to check if a node itself and all its downstream tree is completed
|
| 939 |
+
const isNodeAndTreeCompleted = (nodeId, ndsList) => {
|
| 940 |
+
const queue = [nodeId];
|
| 941 |
+
const visited = new Set(queue);
|
| 942 |
+
|
| 943 |
+
while (queue.length > 0) {
|
| 944 |
+
const currentId = queue.shift();
|
| 945 |
+
const currentNode = ndsList.find(node => node.id === currentId);
|
| 946 |
+
if (!currentNode || currentNode.data.status !== 'Done') {
|
| 947 |
+
return false;
|
| 948 |
+
}
|
| 949 |
+
|
| 950 |
+
const outEdges = edges.filter(e => e.source === currentId);
|
| 951 |
+
outEdges.forEach(edge => {
|
| 952 |
+
if (!visited.has(edge.target)) {
|
| 953 |
+
visited.add(edge.target);
|
| 954 |
+
queue.push(edge.target);
|
| 955 |
+
}
|
| 956 |
+
});
|
| 957 |
+
}
|
| 958 |
+
return true;
|
| 959 |
+
};
|
| 960 |
+
|
| 961 |
const queue = [];
|
| 962 |
|
| 963 |
nodes.forEach(node => {
|
|
|
|
| 983 |
if (node.type === 'sketch') {
|
| 984 |
if (edge.sourceHandle && edge.sourceHandle.startsWith('subgoals-source')) {
|
| 985 |
const targetNode = nodes.find(n => n.id === edge.target);
|
| 986 |
+
const isBranchDone = targetNode && isNodeAndTreeCompleted(targetNode.id, nodes);
|
| 987 |
+
shouldPropagate = !isBranchDone;
|
| 988 |
} else {
|
| 989 |
shouldPropagate = node.data.status === 'Done';
|
| 990 |
}
|
|
|
|
| 1037 |
};
|
| 1038 |
}));
|
| 1039 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1040 |
setNodes(nds => nds.map(n => {
|
| 1041 |
const isReached = activeNodeIds.has(n.id);
|
| 1042 |
const isNextStep = isReached && n.data.status !== 'Done';
|