From d7f6563e3f3f4b2f3f6c352994b29513280b73af Mon Sep 17 00:00:00 2001
From: Leonardo Christino <lchristino@graphpolaris.com>
Date: Thu, 20 Mar 2025 18:07:51 +0100
Subject: [PATCH] fix: make qb node id be bigger than all existing ones to
 avoid clash

---
 src/lib/querybuilder/model/graphology/utils.ts | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/lib/querybuilder/model/graphology/utils.ts b/src/lib/querybuilder/model/graphology/utils.ts
index 5e830e6f4..5e1adb664 100644
--- a/src/lib/querybuilder/model/graphology/utils.ts
+++ b/src/lib/querybuilder/model/graphology/utils.ts
@@ -51,7 +51,10 @@ export class QueryMultiGraphology extends MultiGraph<QueryGraphNodes, QueryGraph
     attributes.width = width;
     attributes.height = height;
 
-    if (!attributes.id) attributes.id = 'id_' + this.nodes().length;
+    const ids: number[] = this.nodes()
+      .map(x => parseInt(x.slice(3)))
+      .sort((a, b) => a - b);
+    if (!attributes.id) attributes.id = 'id_' + String((ids.at(-1) ?? 0) + 1);
 
     // Add to the beginning the meta attributes, such as (# Connection)
     attributes.attributes = [...checkForMetaAttributes(attributes).map(a => ({ handleData: a })), ...attributes.attributes];
-- 
GitLab