SYNC: fixes

This commit is contained in:
SPRINX0\prochazka
2025-03-31 13:09:55 +02:00
committed by Diflow
parent 97357f082d
commit fde257c722
2 changed files with 23 additions and 13 deletions

View File

@@ -9,16 +9,17 @@ import type {
import _flatten from 'lodash/flatten'; import _flatten from 'lodash/flatten';
import _uniq from 'lodash/uniq'; import _uniq from 'lodash/uniq';
import _keys from 'lodash/keys'; import _keys from 'lodash/keys';
import _compact from 'lodash/compact';
export function addTableDependencies(db: DatabaseInfo): DatabaseInfo { export function addTableDependencies(db: DatabaseInfo): DatabaseInfo {
if (!db.tables) { if (!db.tables) {
return db; return db;
} }
const allForeignKeys = _flatten(db.tables.map(x => x.foreignKeys || [])); const allForeignKeys = _flatten(db.tables.map(x => x?.foreignKeys || []));
return { return {
...db, ...db,
tables: db.tables.map(table => ({ tables: _compact(db.tables).map(table => ({
...table, ...table,
dependencies: allForeignKeys.filter(x => x.refSchemaName == table.schemaName && x.refTableName == table.pureName), dependencies: allForeignKeys.filter(x => x.refSchemaName == table.schemaName && x.refTableName == table.pureName),
})), })),

View File

@@ -140,12 +140,14 @@
onChange(current => { onChange(current => {
let newTables = current.tables || []; let newTables = current.tables || [];
for (const table of 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 ( if (
stableStringify(_.pick(dbTable, ['columns', 'primaryKey', 'foreignKeys'])) != stableStringify(_.pick(dbTable, ['columns', 'primaryKey', 'foreignKeys'])) !=
stableStringify(_.pick(table, ['columns', 'primaryKey', 'foreignKeys'])) stableStringify(_.pick(table, ['columns', 'primaryKey', 'foreignKeys']))
) { ) {
newTables = newTables.map(x => newTables = _.compact(newTables).map(x =>
x == table x == table
? { ? {
...table, ...table,
@@ -628,11 +630,13 @@
...current, ...current,
tables: (current.tables || []).map(x => { tables: (current.tables || []).map(x => {
const domTable = domTables[x.designerId] as any; const domTable = domTables[x.designerId] as any;
if (domTable) {
const rect = domTable.getRect(); const rect = domTable.getRect();
return { return {
...x, ...x,
isSelectedTable: rectanglesHaveIntersection(rect, bounds), isSelectedTable: rectanglesHaveIntersection(rect, bounds),
}; };
}
}), }),
}), }),
true true
@@ -676,9 +680,14 @@
const rect = domTable.getRect(); const rect = domTable.getRect();
graph.addNode( graph.addNode(
table.designerId, table.designerId,
rect.right - rect.left, (rect.right - rect.left) / zoomKoef,
rect.bottom - rect.top, (rect.bottom - rect.top) / zoomKoef,
arrangeAll || table.needsArrange ? null : { x: (rect.left + rect.right) / 2, y: (rect.top + rect.bottom) / 2 } arrangeAll || table.needsArrange
? null
: {
x: (rect.left + rect.right) / 2 / zoomKoef,
y: (rect.top + rect.bottom) / 2 / zoomKoef,
}
); );
} }
@@ -718,7 +727,7 @@
current => { current => {
return { return {
...current, ...current,
tables: (current?.tables || []).map(table => { tables: _.compact(current?.tables || []).map(table => {
const node = layout.nodes[table.designerId]; const node = layout.nodes[table.designerId];
// console.log('POSITION', position); // console.log('POSITION', position);
return node return node