Skip to content
Snippets Groups Projects
Commit d615d07f authored by Maximilian Giller's avatar Maximilian Giller :squid:
Browse files

Prevents creation of duplicate links

parent be4e86a0
No related branches found
No related tags found
1 merge request!2Implemented editor in the react framework
Pipeline #56838 passed
......@@ -295,6 +295,21 @@ export class Graph extends ManagedData {
return true;
}
getLink(sourceId: number, targetId: number, directionSensitive = true): Link {
return this.links.find((l) => {
if (l.sourceId === sourceId && l.targetId === targetId) {
return true;
}
// Check other direction if allowed
if (!directionSensitive && (l.sourceId === targetId && l.targetId === sourceId)) {
return true;
}
return false;
});
}
getNode(id: number): Node {
return this.getElementWithId(this.nodes, id);
}
......@@ -318,7 +333,7 @@ export class Graph extends ManagedData {
* @returns True, if successful.
*/
public addLink(link: Link): boolean {
if (this.data.links.includes(link)) {
if (this.getLink(link.sourceId, link.targetId, false) !== undefined) {
return true; // Already exists in graph.
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment