Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion GUI/src/hooks/flow/useOnNodeDelete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
};

function getDirectlyConnectedNodes(nodeId: string, nodes: Node[], edges: Edge[], withGhost: boolean = true): Node[] {
const connectedNodeIds = edges.filter((edge) => edge.source === nodeId).map((edge) => edge.target);

Check warning on line 117 in GUI/src/hooks/flow/useOnNodeDelete.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

`connectedNodeIds` should be a `Set`, and use `connectedNodeIds.has()` to check existence or non-existence.

See more on https://sonarcloud.io/project/issues?id=buerokratt_Service-Module&issues=AZ7X-qtcHr3Ux-A8KDqR&open=AZ7X-qtcHr3Ux-A8KDqR&pullRequest=1077
return nodes.filter((node) => connectedNodeIds.includes(node.id) && (withGhost || node.type !== 'ghost'));
}

Expand Down Expand Up @@ -149,7 +149,7 @@
edges.forEach((edge) => {
if (edge.source === nodeId) {
descendants.push(edge.target);
descendants.push(...getAllDescendants(edge.target, edges, visited));

Check warning on line 152 in GUI/src/hooks/flow/useOnNodeDelete.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Do not call `Array#push()` multiple times.

See more on https://sonarcloud.io/project/issues?id=buerokratt_Service-Module&issues=AZ7X-qtcHr3Ux-A8KDqS&open=AZ7X-qtcHr3Ux-A8KDqS&pullRequest=1077
}
});

Expand All @@ -157,7 +157,7 @@
};

const descendantIds = getAllDescendants(nodeToDelete.id, edges);
const uniqueDescendantIds = Array.from(new Set(descendantIds));

Check warning on line 160 in GUI/src/hooks/flow/useOnNodeDelete.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

`uniqueDescendantIds` should be a `Set`, and use `uniqueDescendantIds.has()` to check existence or non-existence.

See more on https://sonarcloud.io/project/issues?id=buerokratt_Service-Module&issues=AZ7X-qtcHr3Ux-A8KDqT&open=AZ7X-qtcHr3Ux-A8KDqT&pullRequest=1077
const descendantNodes = nodes.filter((node) => uniqueDescendantIds.includes(node.id));
const nodesToDelete = [nodeToDelete, ...descendantNodes];

Expand Down Expand Up @@ -236,7 +236,7 @@
type: 'step',
animated: true,
deletable: false,
label: '+',
label: deleted[0].label ?? '+',
};

setNodes((nds) => [...nds, ghostNode]);
Expand Down
6 changes: 6 additions & 0 deletions GUI/src/utils/mcq-flow-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,15 @@ export const applySimpleConnection = ({
let finalNodes = nodes;
let finalEdges = edges;

let preservedLabel: string | undefined;
if (ghostEdges.length > 0) {
const ghostNodeIds = new Set(ghostEdges.map((edge) => edge.target));
finalEdges = edges.filter((edge) => !ghostEdges.includes(edge));
finalNodes = nodes.filter((node) => !ghostNodeIds.has(node.id));
if (ghostEdges.length === 1) {
const label = ghostEdges[0].label;
if (typeof label === 'string' && label !== '+') preservedLabel = label;
}
}

finalEdges = [
Expand All @@ -127,6 +132,7 @@ export const applySimpleConnection = ({
source,
target,
type: 'step',
...(preservedLabel === undefined ? {} : { label: preservedLabel }),
},
];

Expand Down
Loading