mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-05-03 10:33:58 +00:00
diagram - add references
This commit is contained in:
@@ -247,6 +247,44 @@
|
|||||||
: current.references,
|
: current.references,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
updateFromDbInfo();
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleAddTableReferences = table => {
|
||||||
|
if (!dbInfo) return;
|
||||||
|
const db = $dbInfo;
|
||||||
|
if (!db) return;
|
||||||
|
const dbTable = db.tables?.find(x => x.pureName == table.pureName && x.schemaName == table.schemaName);
|
||||||
|
if (!dbTable) return;
|
||||||
|
callChange(current => {
|
||||||
|
const newTables = [];
|
||||||
|
for (const fk of dbTable.foreignKeys || []) {
|
||||||
|
const existing = current.tables.find(x => x.pureName == fk.refTableName && x.schemaName == fk.refSchemaName);
|
||||||
|
if (!existing) {
|
||||||
|
const dst = db.tables.find(x => x.pureName == fk.refTableName && x.schemaName == fk.refSchemaName);
|
||||||
|
if (dst) newTables.push(dst);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (const fk of dbTable.dependencies || []) {
|
||||||
|
const existing = current.tables.find(x => x.pureName == fk.pureName && x.schemaName == fk.schemaName);
|
||||||
|
if (!existing) {
|
||||||
|
const dst = db.tables.find(x => x.pureName == fk.pureName && x.schemaName == fk.schemaName);
|
||||||
|
if (dst) newTables.push(dst);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
...current,
|
||||||
|
tables: [
|
||||||
|
...current.tables,
|
||||||
|
...newTables.map(x => ({
|
||||||
|
...x,
|
||||||
|
designerId: uuidv1(),
|
||||||
|
})),
|
||||||
|
],
|
||||||
|
};
|
||||||
|
});
|
||||||
|
updateFromDbInfo();
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleSelectColumn = column => {
|
const handleSelectColumn = column => {
|
||||||
@@ -408,6 +446,7 @@
|
|||||||
onSelectColumn={handleSelectColumn}
|
onSelectColumn={handleSelectColumn}
|
||||||
onChangeColumn={handleChangeColumn}
|
onChangeColumn={handleChangeColumn}
|
||||||
onAddReferenceByColumn={handleAddReferenceByColumn}
|
onAddReferenceByColumn={handleAddReferenceByColumn}
|
||||||
|
onAddAllReferences={handleAddTableReferences}
|
||||||
onMoveReferences={recomputeReferencePositions}
|
onMoveReferences={recomputeReferencePositions}
|
||||||
{table}
|
{table}
|
||||||
onChangeTable={changeTable}
|
onChangeTable={changeTable}
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
export let onChangeTable;
|
export let onChangeTable;
|
||||||
export let onBringToFront;
|
export let onBringToFront;
|
||||||
export let onRemoveTable;
|
export let onRemoveTable;
|
||||||
|
export let onAddAllReferences;
|
||||||
export let onCreateReference;
|
export let onCreateReference;
|
||||||
export let onAddReferenceByColumn;
|
export let onAddReferenceByColumn;
|
||||||
export let onSelectColumn;
|
export let onSelectColumn;
|
||||||
@@ -87,8 +88,8 @@
|
|||||||
function createMenu() {
|
function createMenu() {
|
||||||
return [
|
return [
|
||||||
{ text: 'Remove', onClick: () => onRemoveTable({ designerId }) },
|
{ text: 'Remove', onClick: () => onRemoveTable({ designerId }) },
|
||||||
settings?.allowTableAlias && [
|
|
||||||
{ divider: true },
|
{ divider: true },
|
||||||
|
settings?.allowTableAlias && [
|
||||||
{ text: 'Set table alias', onClick: handleSetTableAlias },
|
{ text: 'Set table alias', onClick: handleSetTableAlias },
|
||||||
alias && {
|
alias && {
|
||||||
text: 'Remove table alias',
|
text: 'Remove table alias',
|
||||||
@@ -99,6 +100,7 @@
|
|||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
settings?.allowAddAllReferences && { text: 'Add references', onClick: () => onAddAllReferences(table) },
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
@@ -123,7 +125,7 @@
|
|||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
<div class="columns" on:scroll={() => tick().then(onMoveReferences)}>
|
<div class="columns" on:scroll={() => tick().then(onMoveReferences)} class:scroll={settings?.allowScrollColumns}>
|
||||||
{#each columns || [] as column}
|
{#each columns || [] as column}
|
||||||
<ColumnLine
|
<ColumnLine
|
||||||
{column}
|
{column}
|
||||||
@@ -175,9 +177,11 @@
|
|||||||
background: var(--theme-bg-3);
|
background: var(--theme-bg-3);
|
||||||
}
|
}
|
||||||
.columns {
|
.columns {
|
||||||
max-height: 400px;
|
|
||||||
overflow-y: auto;
|
|
||||||
width: calc(100% - 10px);
|
width: calc(100% - 10px);
|
||||||
padding: 5px;
|
padding: 5px;
|
||||||
}
|
}
|
||||||
|
.columns.scroll {
|
||||||
|
max-height: 400px;
|
||||||
|
overflow-y: auto;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -13,5 +13,7 @@
|
|||||||
useDatabaseReferences: true,
|
useDatabaseReferences: true,
|
||||||
showJoinType: false,
|
showJoinType: false,
|
||||||
showReferenceArrow: true,
|
showReferenceArrow: true,
|
||||||
|
allowScrollColumns: false,
|
||||||
|
allowAddAllReferences: true,
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -13,5 +13,7 @@
|
|||||||
useDatabaseReferences: false,
|
useDatabaseReferences: false,
|
||||||
showJoinType: true,
|
showJoinType: true,
|
||||||
showReferenceArrow: false,
|
showReferenceArrow: false,
|
||||||
|
allowScrollColumns: true,
|
||||||
|
allowAddAllReferences: false,
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|||||||
Reference in New Issue
Block a user