Skip to content
Merged
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
7 changes: 6 additions & 1 deletion GUI/src/hooks/flow/useOnNodeDelete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,12 @@
updatedNodes = [...updatedNodes.filter((n) => n.id !== node.id), ...newGhostNodes];
updatedEdges = [...getRemainingEdges(updatedEdges, getConnectedEdges([node], updatedEdges)), ...newEdges];
} else {
if (outgoers.length === 0 || outgoers.length > 1) {
const edgesWithoutDeleted = getRemainingEdges(updatedEdges, getConnectedEdges([node], updatedEdges));
if (
outgoers.length === 0 ||
outgoers.length > 1 ||
(outgoers.length === 1 && getIncomers(outgoers[0], updatedNodes, edgesWithoutDeleted).length > 0)
) {
const ghostNode: Node = {
id: generateUniqueId(),
type: 'ghost',
Expand Down Expand Up @@ -109,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=AZ67shyBNFGdBggtix5e&open=AZ67shyBNFGdBggtix5e&pullRequest=1072
return nodes.filter((node) => connectedNodeIds.includes(node.id) && (withGhost || node.type !== 'ghost'));
}

Expand Down Expand Up @@ -144,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=AZ67shyBNFGdBggtix5f&open=AZ67shyBNFGdBggtix5f&pullRequest=1072
}
});

Expand All @@ -152,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=AZ67shyBNFGdBggtix5g&open=AZ67shyBNFGdBggtix5g&pullRequest=1072
const descendantNodes = nodes.filter((node) => uniqueDescendantIds.includes(node.id));
const nodesToDelete = [nodeToDelete, ...descendantNodes];

Expand Down
Loading