Skip to content

Commit add0b04

Browse files
authored
fix: add private helper without datagraph edge removal (#184)
This PR fixes an issue we had when removing devices where the edges wouldn't come back after undoing the removal.
1 parent 513dacd commit add0b04

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

src/types/graphs/viewgraph.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,9 @@ export class ViewGraph {
234234
return this.packetManager;
235235
}
236236

237+
/**
238+
* Remove a device and its connections from the viewgraph and its underlying datagraph.
239+
*/
237240
// Method to remove a device and its connections (edges)
238241
removeDevice(id: DeviceId): RemovedNodeData | undefined {
239242
const device = this.graph.getVertex(id);
@@ -244,7 +247,7 @@ export class ViewGraph {
244247
}
245248

246249
this.graph.getNeighbors(id).forEach((adjacentId) => {
247-
this.removeEdge(id, adjacentId);
250+
this._removeEdge(id, adjacentId);
248251
});
249252

250253
// Remove device and its connections from the graph
@@ -260,24 +263,32 @@ export class ViewGraph {
260263
return removedData;
261264
}
262265

263-
// Method to remove a specific edge by its ID
266+
/**
267+
* Remove the edge between two devices from the viewgraph and its underlying datagraph.
268+
*/
264269
removeEdge(n1Id: DeviceId, n2Id: DeviceId): boolean {
265270
const datagraphEdge = this.datagraph.getConnection(n1Id, n2Id);
266271

267272
if (!datagraphEdge) {
268273
console.warn(`Edge ${n1Id},${n2Id} is not in the datagraph`);
269274
return false;
270275
}
276+
// Remove connection in DataGraph
277+
this.datagraph.removeConnection(n1Id, n2Id);
278+
279+
return this._removeEdge(n1Id, n2Id);
280+
}
271281

282+
/**
283+
* Removes the edge from the viewgraph without removing from the Datagraph.
284+
*/
285+
private _removeEdge(n1Id: DeviceId, n2Id: DeviceId): boolean {
272286
const edge = this.graph.getEdge(n1Id, n2Id);
273287
if (!edge) {
274288
console.warn(`Edge ${n1Id},${n2Id} is not in the viewgraph.`);
275289
return false;
276290
}
277291

278-
// Remove connection in DataGraph
279-
this.datagraph.removeConnection(n1Id, n2Id);
280-
281292
// Remove connection from each connected device
282293
const { n1, n2 } = edge.connectedNodes;
283294
const device1 = this.graph.getVertex(n1);

0 commit comments

Comments
 (0)