Spaces:
Running
Running
Commit ·
2f6e9e4
1
Parent(s): f684f65
feat(canvas): require downstream tree completion for subgoals
Browse files
src/features/canvas/hooks/useCanvasLogic.js
CHANGED
|
@@ -666,6 +666,29 @@ export const useCanvasLogic = (projectId, user) => {
|
|
| 666 |
};
|
| 667 |
}));
|
| 668 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 669 |
setNodes(nds => nds.map(n => {
|
| 670 |
const isReached = activeNodeIds.has(n.id);
|
| 671 |
const isNextStep = isReached && n.data.status !== 'Done';
|
|
@@ -676,7 +699,7 @@ export const useCanvasLogic = (projectId, user) => {
|
|
| 676 |
.filter(Boolean);
|
| 677 |
|
| 678 |
const subgoalsCount = connectedSubgoals.length;
|
| 679 |
-
const subgoalsDone = connectedSubgoals.filter(node => node.
|
| 680 |
|
| 681 |
const subgoalsData = {
|
| 682 |
total: subgoalsCount,
|
|
|
|
| 666 |
};
|
| 667 |
}));
|
| 668 |
|
| 669 |
+
// Helper to check if a node itself and all its downstream tree is completed
|
| 670 |
+
const isNodeAndTreeCompleted = (nodeId, ndsList) => {
|
| 671 |
+
const queue = [nodeId];
|
| 672 |
+
const visited = new Set(queue);
|
| 673 |
+
|
| 674 |
+
while (queue.length > 0) {
|
| 675 |
+
const currentId = queue.shift();
|
| 676 |
+
const currentNode = ndsList.find(node => node.id === currentId);
|
| 677 |
+
if (!currentNode || currentNode.data.status !== 'Done') {
|
| 678 |
+
return false;
|
| 679 |
+
}
|
| 680 |
+
|
| 681 |
+
const outEdges = edges.filter(e => e.source === currentId);
|
| 682 |
+
outEdges.forEach(edge => {
|
| 683 |
+
if (!visited.has(edge.target)) {
|
| 684 |
+
visited.add(edge.target);
|
| 685 |
+
queue.push(edge.target);
|
| 686 |
+
}
|
| 687 |
+
});
|
| 688 |
+
}
|
| 689 |
+
return true;
|
| 690 |
+
};
|
| 691 |
+
|
| 692 |
setNodes(nds => nds.map(n => {
|
| 693 |
const isReached = activeNodeIds.has(n.id);
|
| 694 |
const isNextStep = isReached && n.data.status !== 'Done';
|
|
|
|
| 699 |
.filter(Boolean);
|
| 700 |
|
| 701 |
const subgoalsCount = connectedSubgoals.length;
|
| 702 |
+
const subgoalsDone = connectedSubgoals.filter(node => isNodeAndTreeCompleted(node.id, nds)).length;
|
| 703 |
|
| 704 |
const subgoalsData = {
|
| 705 |
total: subgoalsCount,
|