From 9f6a0782c43246465986bd5ff376142037241453 Mon Sep 17 00:00:00 2001 From: Jack Date: Tue, 3 Oct 2023 21:25:26 +0800 Subject: [PATCH] New nodes takes the max ID automatically --- .../Graph/GraphEventHandlerModel.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/neo4j-arc/graph-visualization/GraphVisualizer/Graph/GraphEventHandlerModel.ts b/src/neo4j-arc/graph-visualization/GraphVisualizer/Graph/GraphEventHandlerModel.ts index 563eac7e4d6..43b3ae2dfaf 100644 --- a/src/neo4j-arc/graph-visualization/GraphVisualizer/Graph/GraphEventHandlerModel.ts +++ b/src/neo4j-arc/graph-visualization/GraphVisualizer/Graph/GraphEventHandlerModel.ts @@ -230,7 +230,20 @@ export class GraphEventHandlerModel { } onCanvasDblClicked(): void { - this.graph.addNodes([new NodeModel('New Node', [], {}, {})]) + const maxId: number = Math.max( + ...this.graph._nodes.map(node => parseInt(node.id)) + ) + const newId = maxId + 1 + + // TODO: make label, properties EDITABLE in followup PR's + this.graph.addNodes([ + new NodeModel( + newId.toString(), + [], + { name: 'New Node' }, + { name: 'string' } + ) + ]) this.visualization.update({ updateNodes: true, updateRelationships: true }) // this will persist node to Neo4J DB...