mongo perspective fixes

This commit is contained in:
Jan Prochazka
2022-10-01 16:44:34 +02:00
parent f9e167fc7b
commit efe15bf0bb
7 changed files with 65 additions and 21 deletions

View File

@@ -479,7 +479,7 @@
const rect = e.target.getBoundingClientRect();
var json = JSON.parse(data);
const { objectTypeField } = json;
if (objectTypeField != 'tables' && objectTypeField != 'views') return;
if (objectTypeField != 'tables' && objectTypeField != 'views' && objectTypeField != 'collections') return;
json.designerId = `${json.pureName}-${uuidv1()}`;
json.left = e.clientX - rect.left;
json.top = e.clientY - rect.top;
@@ -941,6 +941,7 @@
.empty {
margin: 50px;
font-size: 20px;
position: absolute;
}
.canvas {
position: relative;

View File

@@ -213,6 +213,8 @@
!isMultipleTableSelection && [{ divider: true }, createDatabaseObjectMenu({ ...table, conid, database })],
];
}
// $: console.log('COLUMNS', columns);
</script>
<div

View File

@@ -39,24 +39,22 @@
...config,
tables: _.compact(
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
);
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) {
const pattern = dataPatterns?.[node.designerId];
if (!pattern) return null;
collection = {
...collection,
columns: pattern.columns.map(x => ({
columnName: x.name,
})),
columns:
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 (
root &&
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))
) {
await tick();
@@ -156,7 +154,7 @@
}
}
$: detectAutoArrange(config, dbInfos, root);
$: detectAutoArrange(config, dbInfos, dataPatterns, root);
// $: console.log('DESIGNER ROOT', root);
</script>

View File

@@ -168,7 +168,7 @@
$: tempRoot = root?.findNodeByDesignerId(tempRootDesignerId);
$: {
if (shouldProcessPerspectiveDefaultColunns(config, $dbInfos, conid, database)) {
if (shouldProcessPerspectiveDefaultColunns(config, $dbInfos, $dataPatterns, conid, database)) {
setConfig(cfg => processPerspectiveDefaultColunns(cfg, $dbInfos, conid, database));
}
}

View File

@@ -11,6 +11,38 @@ import {
import { PerspectiveDataLoader } from 'dbgate-datalib/lib/PerspectiveDataLoader';
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(
databaseConfig: PerspectiveDatabaseConfig,
config: PerspectiveConfig,
@@ -45,6 +77,10 @@ export async function getPerspectiveDataPatterns(
engineType: 'docdb',
pureName,
orderBy: [],
range: {
offset: 0,
limit: 10,
},
};
const rows = await dataLoader.loadData(props);
const pattern = analyseDataPattern(
@@ -71,7 +107,9 @@ export function usePerspectiveDataPatterns(
dbInfos: MultipleDatabaseInfo,
dataLoader: PerspectiveDataLoader
): Readable<PerspectiveDataPatternDict> {
const res = writable({});
getPerspectiveDataPatterns(databaseConfig, config, cache, dbInfos, dataLoader).then(value => res.set(value));
const cached = getPerspectiveDataPatternsFromCache(databaseConfig, config, cache, dbInfos);
const promise = getPerspectiveDataPatterns(databaseConfig, config, cache, dbInfos, dataLoader);
const res = writable(cached);
promise.then(value => res.set(value));
return res;
}