From 55788682960ed0bac7422dacf3646f1bc2325467 Mon Sep 17 00:00:00 2001 From: Ujjansh Sundram Date: Thu, 2 Oct 2025 20:09:43 +0530 Subject: [PATCH 1/2] Update DiagramContext.jsx --- src/context/DiagramContext.jsx | 64 ++++++++++++++++++++-------------- 1 file changed, 37 insertions(+), 27 deletions(-) diff --git a/src/context/DiagramContext.jsx b/src/context/DiagramContext.jsx index 5e6b54e0a..91ad77a38 100644 --- a/src/context/DiagramContext.jsx +++ b/src/context/DiagramContext.jsx @@ -25,33 +25,43 @@ export default function DiagramContextProvider({ children }) { return temp; }); } else { - setTables((prev) => [ - ...prev, - { - id, - name: `table_${prev.length}`, - x: transform.pan.x, - y: transform.pan.y, - locked: false, - fields: [ - { - name: "id", - type: database === DB.GENERIC ? "INT" : "INTEGER", - default: "", - check: "", - primary: true, - unique: true, - notNull: true, - increment: true, - comment: "", - id: nanoid(), - }, - ], - comment: "", - indices: [], - color: defaultBlue, - }, - ]); + setTables((prev) => { + // Find a unique name for the new table + let index = prev.length; + let newName = `table_${index}`; + const existingNames = prev.map((table) => table.name); + while (existingNames.includes(newName)) { + index++; + newName = `table_${index}`; + } + return [ + ...prev, + { + id, + name: newName, + x: transform.pan.x, + y: transform.pan.y, + locked: false, + fields: [ + { + name: "id", + type: database === DB.GENERIC ? "INT" : "INTEGER", + default: "", + check: "", + primary: true, + unique: true, + notNull: true, + increment: true, + comment: "", + id: nanoid(), + }, + ], + comment: "", + indices: [], + color: defaultBlue, + }, + ]; + }); } if (addToHistory) { setUndoStack((prev) => [ From 0caf7a8a8b0fd120cd9c5ec390b250a4d475fc0b Mon Sep 17 00:00:00 2001 From: Ujjansh Sundram Date: Thu, 2 Oct 2025 22:11:16 +0530 Subject: [PATCH 2/2] Update DiagramContext.jsx --- src/context/DiagramContext.jsx | 64 ++++++++++++++-------------------- 1 file changed, 27 insertions(+), 37 deletions(-) diff --git a/src/context/DiagramContext.jsx b/src/context/DiagramContext.jsx index 91ad77a38..eb43016c4 100644 --- a/src/context/DiagramContext.jsx +++ b/src/context/DiagramContext.jsx @@ -25,43 +25,33 @@ export default function DiagramContextProvider({ children }) { return temp; }); } else { - setTables((prev) => { - // Find a unique name for the new table - let index = prev.length; - let newName = `table_${index}`; - const existingNames = prev.map((table) => table.name); - while (existingNames.includes(newName)) { - index++; - newName = `table_${index}`; - } - return [ - ...prev, - { - id, - name: newName, - x: transform.pan.x, - y: transform.pan.y, - locked: false, - fields: [ - { - name: "id", - type: database === DB.GENERIC ? "INT" : "INTEGER", - default: "", - check: "", - primary: true, - unique: true, - notNull: true, - increment: true, - comment: "", - id: nanoid(), - }, - ], - comment: "", - indices: [], - color: defaultBlue, - }, - ]; - }); + setTables((prev) => [ + ...prev, + { + id, + name: `table_${id}`, + x: transform.pan.x, + y: transform.pan.y, + locked: false, + fields: [ + { + name: "id", + type: database === DB.GENERIC ? "INT" : "INTEGER", + default: "", + check: "", + primary: true, + unique: true, + notNull: true, + increment: true, + comment: "", + id: nanoid(), + }, + ], + comment: "", + indices: [], + color: defaultBlue, + }, + ]); } if (addToHistory) { setUndoStack((prev) => [