mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-30 22:03:58 +00:00
mongo perspective fixes
This commit is contained in:
@@ -17,9 +17,9 @@ export interface PerspectiveDatabaseConfig {
|
|||||||
|
|
||||||
export interface PerspectiveDataLoadProps {
|
export interface PerspectiveDataLoadProps {
|
||||||
databaseConfig: PerspectiveDatabaseConfig;
|
databaseConfig: PerspectiveDatabaseConfig;
|
||||||
schemaName: string;
|
schemaName?: string;
|
||||||
pureName: string;
|
pureName: string;
|
||||||
dataColumns: string[];
|
dataColumns?: string[];
|
||||||
orderBy: {
|
orderBy: {
|
||||||
columnName: string;
|
columnName: string;
|
||||||
order: 'ASC' | 'DESC';
|
order: 'ASC' | 'DESC';
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { findForeignKeyForColumn } from 'dbgate-tools';
|
import { findForeignKeyForColumn } from 'dbgate-tools';
|
||||||
import { DatabaseInfo, TableInfo, ViewInfo } from 'dbgate-types';
|
import { DatabaseInfo, TableInfo, ViewInfo } from 'dbgate-types';
|
||||||
import { createPerspectiveNodeConfig, MultipleDatabaseInfo, PerspectiveConfig } from './PerspectiveConfig';
|
import { createPerspectiveNodeConfig, MultipleDatabaseInfo, PerspectiveConfig } from './PerspectiveConfig';
|
||||||
|
import { PerspectiveDataPatternDict } from './PerspectiveDataPattern';
|
||||||
import { PerspectiveTableNode } from './PerspectiveTreeNode';
|
import { PerspectiveTableNode } from './PerspectiveTreeNode';
|
||||||
|
|
||||||
function getPerspectiveDefaultColumns(
|
function getPerspectiveDefaultColumns(
|
||||||
@@ -47,6 +48,7 @@ function getPerspectiveDefaultColumns(
|
|||||||
export function perspectiveNodesHaveStructure(
|
export function perspectiveNodesHaveStructure(
|
||||||
config: PerspectiveConfig,
|
config: PerspectiveConfig,
|
||||||
dbInfos: MultipleDatabaseInfo,
|
dbInfos: MultipleDatabaseInfo,
|
||||||
|
dataPatterns: PerspectiveDataPatternDict,
|
||||||
conid: string,
|
conid: string,
|
||||||
database: string
|
database: string
|
||||||
) {
|
) {
|
||||||
@@ -56,8 +58,10 @@ export function perspectiveNodesHaveStructure(
|
|||||||
|
|
||||||
const table = db.tables.find(x => x.pureName == node.pureName && x.schemaName == node.schemaName);
|
const table = db.tables.find(x => x.pureName == node.pureName && x.schemaName == node.schemaName);
|
||||||
const view = db.views.find(x => x.pureName == node.pureName && x.schemaName == node.schemaName);
|
const view = db.views.find(x => x.pureName == node.pureName && x.schemaName == node.schemaName);
|
||||||
|
const collection = db.collections.find(x => x.pureName == node.pureName && x.schemaName == node.schemaName);
|
||||||
|
|
||||||
if (!table && !view) return false;
|
if (!table && !view && !collection) return false;
|
||||||
|
if (collection && !dataPatterns?.[node.designerId]) return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -66,13 +70,14 @@ export function perspectiveNodesHaveStructure(
|
|||||||
export function shouldProcessPerspectiveDefaultColunns(
|
export function shouldProcessPerspectiveDefaultColunns(
|
||||||
config: PerspectiveConfig,
|
config: PerspectiveConfig,
|
||||||
dbInfos: MultipleDatabaseInfo,
|
dbInfos: MultipleDatabaseInfo,
|
||||||
|
dataPatterns: PerspectiveDataPatternDict,
|
||||||
conid: string,
|
conid: string,
|
||||||
database: string
|
database: string
|
||||||
) {
|
) {
|
||||||
const nodesNotProcessed = config.nodes.filter(x => !x.defaultColumnsProcessed);
|
const nodesNotProcessed = config.nodes.filter(x => !x.defaultColumnsProcessed);
|
||||||
if (nodesNotProcessed.length == 0) return false;
|
if (nodesNotProcessed.length == 0) return false;
|
||||||
|
|
||||||
return perspectiveNodesHaveStructure(config, dbInfos, conid, database);
|
return perspectiveNodesHaveStructure(config, dbInfos, dataPatterns, conid, database);
|
||||||
}
|
}
|
||||||
|
|
||||||
function processPerspectiveDefaultColunnsStep(
|
function processPerspectiveDefaultColunnsStep(
|
||||||
|
|||||||
@@ -479,7 +479,7 @@
|
|||||||
const rect = e.target.getBoundingClientRect();
|
const rect = e.target.getBoundingClientRect();
|
||||||
var json = JSON.parse(data);
|
var json = JSON.parse(data);
|
||||||
const { objectTypeField } = json;
|
const { objectTypeField } = json;
|
||||||
if (objectTypeField != 'tables' && objectTypeField != 'views') return;
|
if (objectTypeField != 'tables' && objectTypeField != 'views' && objectTypeField != 'collections') return;
|
||||||
json.designerId = `${json.pureName}-${uuidv1()}`;
|
json.designerId = `${json.pureName}-${uuidv1()}`;
|
||||||
json.left = e.clientX - rect.left;
|
json.left = e.clientX - rect.left;
|
||||||
json.top = e.clientY - rect.top;
|
json.top = e.clientY - rect.top;
|
||||||
@@ -941,6 +941,7 @@
|
|||||||
.empty {
|
.empty {
|
||||||
margin: 50px;
|
margin: 50px;
|
||||||
font-size: 20px;
|
font-size: 20px;
|
||||||
|
position: absolute;
|
||||||
}
|
}
|
||||||
.canvas {
|
.canvas {
|
||||||
position: relative;
|
position: relative;
|
||||||
|
|||||||
@@ -213,6 +213,8 @@
|
|||||||
!isMultipleTableSelection && [{ divider: true }, createDatabaseObjectMenu({ ...table, conid, database })],
|
!isMultipleTableSelection && [{ divider: true }, createDatabaseObjectMenu({ ...table, conid, database })],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// $: console.log('COLUMNS', columns);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
|
|||||||
@@ -39,24 +39,22 @@
|
|||||||
...config,
|
...config,
|
||||||
tables: _.compact(
|
tables: _.compact(
|
||||||
config.nodes.map(node => {
|
config.nodes.map(node => {
|
||||||
const table = dbInfos?.[node.conid || conid]?.[node.database || database]?.tables?.find(
|
const db = dbInfos?.[node.conid || conid]?.[node.database || database];
|
||||||
|
const table = db?.tables?.find(x => x.pureName == node.pureName && x.schemaName == node.schemaName);
|
||||||
|
const view = db?.views?.find(x => x.pureName == node.pureName && x.schemaName == node.schemaName);
|
||||||
|
let collection: CollectionInfo & { columns?: any[] } = db?.collections?.find(
|
||||||
x => x.pureName == node.pureName && x.schemaName == node.schemaName
|
x => x.pureName == node.pureName && x.schemaName == node.schemaName
|
||||||
);
|
);
|
||||||
const view = dbInfos?.[node.conid || conid]?.[node.database || database]?.views?.find(
|
|
||||||
x => x.pureName == node.pureName && x.schemaName == node.schemaName
|
|
||||||
);
|
|
||||||
let collection: CollectionInfo & { columns?: any[] } = dbInfos?.[node.conid || conid]?.[
|
|
||||||
node.database || database
|
|
||||||
]?.collections?.find(x => x.pureName == node.pureName && x.schemaName == node.schemaName);
|
|
||||||
|
|
||||||
if (collection) {
|
if (collection) {
|
||||||
const pattern = dataPatterns?.[node.designerId];
|
const pattern = dataPatterns?.[node.designerId];
|
||||||
if (!pattern) return null;
|
if (!pattern) return null;
|
||||||
collection = {
|
collection = {
|
||||||
...collection,
|
...collection,
|
||||||
columns: pattern.columns.map(x => ({
|
columns:
|
||||||
columnName: x.name,
|
pattern?.columns.map(x => ({
|
||||||
})),
|
columnName: x.name,
|
||||||
|
})) || [],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -144,11 +142,11 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function detectAutoArrange(config: PerspectiveConfig, dbInfos, root) {
|
async function detectAutoArrange(config: PerspectiveConfig, dbInfos, dataPatterns, root) {
|
||||||
if (
|
if (
|
||||||
root &&
|
root &&
|
||||||
config.nodes.find(x => !x.position) &&
|
config.nodes.find(x => !x.position) &&
|
||||||
perspectiveNodesHaveStructure(config, dbInfos, conid, database) &&
|
perspectiveNodesHaveStructure(config, dbInfos, dataPatterns, conid, database) &&
|
||||||
config.nodes.every(x => root?.findNodeByDesignerId(x.designerId))
|
config.nodes.every(x => root?.findNodeByDesignerId(x.designerId))
|
||||||
) {
|
) {
|
||||||
await tick();
|
await tick();
|
||||||
@@ -156,7 +154,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$: detectAutoArrange(config, dbInfos, root);
|
$: detectAutoArrange(config, dbInfos, dataPatterns, root);
|
||||||
|
|
||||||
// $: console.log('DESIGNER ROOT', root);
|
// $: console.log('DESIGNER ROOT', root);
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -168,7 +168,7 @@
|
|||||||
$: tempRoot = root?.findNodeByDesignerId(tempRootDesignerId);
|
$: tempRoot = root?.findNodeByDesignerId(tempRootDesignerId);
|
||||||
|
|
||||||
$: {
|
$: {
|
||||||
if (shouldProcessPerspectiveDefaultColunns(config, $dbInfos, conid, database)) {
|
if (shouldProcessPerspectiveDefaultColunns(config, $dbInfos, $dataPatterns, conid, database)) {
|
||||||
setConfig(cfg => processPerspectiveDefaultColunns(cfg, $dbInfos, conid, database));
|
setConfig(cfg => processPerspectiveDefaultColunns(cfg, $dbInfos, conid, database));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,38 @@ import {
|
|||||||
import { PerspectiveDataLoader } from 'dbgate-datalib/lib/PerspectiveDataLoader';
|
import { PerspectiveDataLoader } from 'dbgate-datalib/lib/PerspectiveDataLoader';
|
||||||
import { writable, Readable } from 'svelte/store';
|
import { writable, Readable } from 'svelte/store';
|
||||||
|
|
||||||
|
export function getPerspectiveDataPatternsFromCache(
|
||||||
|
databaseConfig: PerspectiveDatabaseConfig,
|
||||||
|
config: PerspectiveConfig,
|
||||||
|
cache: PerspectiveCache,
|
||||||
|
dbInfos: MultipleDatabaseInfo
|
||||||
|
): PerspectiveDataPatternDict {
|
||||||
|
const res = {};
|
||||||
|
|
||||||
|
for (const node of config.nodes) {
|
||||||
|
const conid = node.conid || databaseConfig.conid;
|
||||||
|
const database = node.database || databaseConfig.database;
|
||||||
|
const { schemaName, pureName } = node;
|
||||||
|
|
||||||
|
const cached = cache.dataPatterns.find(
|
||||||
|
x => x.conid == conid && x.database == database && x.schemaName == schemaName && x.pureName == pureName
|
||||||
|
);
|
||||||
|
if (cached) {
|
||||||
|
res[node.designerId] = cached;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const db = dbInfos?.[conid]?.[database];
|
||||||
|
|
||||||
|
if (!db) continue;
|
||||||
|
|
||||||
|
const collection = db.collections?.find(x => x.pureName == pureName && x.schemaName == schemaName);
|
||||||
|
if (!collection) continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
export async function getPerspectiveDataPatterns(
|
export async function getPerspectiveDataPatterns(
|
||||||
databaseConfig: PerspectiveDatabaseConfig,
|
databaseConfig: PerspectiveDatabaseConfig,
|
||||||
config: PerspectiveConfig,
|
config: PerspectiveConfig,
|
||||||
@@ -45,6 +77,10 @@ export async function getPerspectiveDataPatterns(
|
|||||||
engineType: 'docdb',
|
engineType: 'docdb',
|
||||||
pureName,
|
pureName,
|
||||||
orderBy: [],
|
orderBy: [],
|
||||||
|
range: {
|
||||||
|
offset: 0,
|
||||||
|
limit: 10,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
const rows = await dataLoader.loadData(props);
|
const rows = await dataLoader.loadData(props);
|
||||||
const pattern = analyseDataPattern(
|
const pattern = analyseDataPattern(
|
||||||
@@ -71,7 +107,9 @@ export function usePerspectiveDataPatterns(
|
|||||||
dbInfos: MultipleDatabaseInfo,
|
dbInfos: MultipleDatabaseInfo,
|
||||||
dataLoader: PerspectiveDataLoader
|
dataLoader: PerspectiveDataLoader
|
||||||
): Readable<PerspectiveDataPatternDict> {
|
): Readable<PerspectiveDataPatternDict> {
|
||||||
const res = writable({});
|
const cached = getPerspectiveDataPatternsFromCache(databaseConfig, config, cache, dbInfos);
|
||||||
getPerspectiveDataPatterns(databaseConfig, config, cache, dbInfos, dataLoader).then(value => res.set(value));
|
const promise = getPerspectiveDataPatterns(databaseConfig, config, cache, dbInfos, dataLoader);
|
||||||
|
const res = writable(cached);
|
||||||
|
promise.then(value => res.set(value));
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user