diff --git a/packages/tools/src/structureTools.ts b/packages/tools/src/structureTools.ts index 96150dec3..342922b71 100644 --- a/packages/tools/src/structureTools.ts +++ b/packages/tools/src/structureTools.ts @@ -9,16 +9,17 @@ import type { import _flatten from 'lodash/flatten'; import _uniq from 'lodash/uniq'; import _keys from 'lodash/keys'; +import _compact from 'lodash/compact'; export function addTableDependencies(db: DatabaseInfo): DatabaseInfo { if (!db.tables) { return db; } - const allForeignKeys = _flatten(db.tables.map(x => x.foreignKeys || [])); + const allForeignKeys = _flatten(db.tables.map(x => x?.foreignKeys || [])); return { ...db, - tables: db.tables.map(table => ({ + tables: _compact(db.tables).map(table => ({ ...table, dependencies: allForeignKeys.filter(x => x.refSchemaName == table.schemaName && x.refTableName == table.pureName), })), diff --git a/packages/web/src/designer/Designer.svelte b/packages/web/src/designer/Designer.svelte index 3f74aece3..8c77d3a56 100644 --- a/packages/web/src/designer/Designer.svelte +++ b/packages/web/src/designer/Designer.svelte @@ -140,12 +140,14 @@ onChange(current => { let newTables = current.tables || []; for (const table of current.tables || []) { - const dbTable = (db.tables || []).find(x => x.pureName == table.pureName && x.schemaName == table.schemaName); + const dbTable = (db.tables || []).find( + x => x?.pureName == table?.pureName && x?.schemaName == table?.schemaName + ); if ( stableStringify(_.pick(dbTable, ['columns', 'primaryKey', 'foreignKeys'])) != stableStringify(_.pick(table, ['columns', 'primaryKey', 'foreignKeys'])) ) { - newTables = newTables.map(x => + newTables = _.compact(newTables).map(x => x == table ? { ...table, @@ -628,11 +630,13 @@ ...current, tables: (current.tables || []).map(x => { const domTable = domTables[x.designerId] as any; - const rect = domTable.getRect(); - return { - ...x, - isSelectedTable: rectanglesHaveIntersection(rect, bounds), - }; + if (domTable) { + const rect = domTable.getRect(); + return { + ...x, + isSelectedTable: rectanglesHaveIntersection(rect, bounds), + }; + } }), }), true @@ -676,9 +680,14 @@ const rect = domTable.getRect(); graph.addNode( table.designerId, - rect.right - rect.left, - rect.bottom - rect.top, - arrangeAll || table.needsArrange ? null : { x: (rect.left + rect.right) / 2, y: (rect.top + rect.bottom) / 2 } + (rect.right - rect.left) / zoomKoef, + (rect.bottom - rect.top) / zoomKoef, + arrangeAll || table.needsArrange + ? null + : { + x: (rect.left + rect.right) / 2 / zoomKoef, + y: (rect.top + rect.bottom) / 2 / zoomKoef, + } ); } @@ -718,7 +727,7 @@ current => { return { ...current, - tables: (current?.tables || []).map(table => { + tables: _.compact(current?.tables || []).map(table => { const node = layout.nodes[table.designerId]; // console.log('POSITION', position); return node