From 380ab2e69ee7a0ae5c06f84c82632e0187bd15fa Mon Sep 17 00:00:00 2001 From: Jan Prochazka Date: Fri, 30 Dec 2022 10:30:38 +0100 Subject: [PATCH] fixes --- .../datalib/src/PerspectiveDataPattern.ts | 2 +- .../datalib/src/PerspectiveDataProvider.ts | 2 +- packages/datalib/src/PerspectiveTreeNode.ts | 2 +- .../src/perspectives/PerspectiveTable.svelte | 28 ++++++++++++++----- .../dbgate-plugin-mongo/src/backend/driver.js | 2 +- 5 files changed, 25 insertions(+), 11 deletions(-) diff --git a/packages/datalib/src/PerspectiveDataPattern.ts b/packages/datalib/src/PerspectiveDataPattern.ts index 876ffc00..f151f6a2 100644 --- a/packages/datalib/src/PerspectiveDataPattern.ts +++ b/packages/datalib/src/PerspectiveDataPattern.ts @@ -51,7 +51,7 @@ function addObjectToColumns(columns: PerspectiveDataPatternColumn[], row) { if (!column.types.includes(type)) { column.types.push(type); } - if (_isPlainObject(value)) { + if (_isPlainObject(value) && type != 'oid') { addObjectToColumns(column.columns, value); } if (_isArray(value)) { diff --git a/packages/datalib/src/PerspectiveDataProvider.ts b/packages/datalib/src/PerspectiveDataProvider.ts index 6bd8d0d6..d05e0a89 100644 --- a/packages/datalib/src/PerspectiveDataProvider.ts +++ b/packages/datalib/src/PerspectiveDataProvider.ts @@ -54,7 +54,7 @@ export class PerspectiveDataProvider { ...props, bindingValues: uncached, }); - // console.log('COUNTS', counts); + // console.log('loadDataNested COUNTS', counts); for (const resetItem of uncached) { tableCache.storeGroupSize(props, resetItem, 0); } diff --git a/packages/datalib/src/PerspectiveTreeNode.ts b/packages/datalib/src/PerspectiveTreeNode.ts index cd627f9d..05ae6427 100644 --- a/packages/datalib/src/PerspectiveTreeNode.ts +++ b/packages/datalib/src/PerspectiveTreeNode.ts @@ -1248,7 +1248,7 @@ export class PerspectiveCustomJoinTreeNode extends PerspectiveTableNode { } matchChildRow(parentRow: any, childRow: any): boolean { - // console.log('MATCH ROW', parentRow, childRow); + console.log('MATCH ROW', parentRow, childRow); for (const column of this.customJoin.columns) { if (parentRow[getPerspectiveMostNestedChildColumnName(column.baseColumnName)] != childRow[column.refColumnName]) { return false; diff --git a/packages/web/src/perspectives/PerspectiveTable.svelte b/packages/web/src/perspectives/PerspectiveTable.svelte index 0184deb1..11562866 100644 --- a/packages/web/src/perspectives/PerspectiveTable.svelte +++ b/packages/web/src/perspectives/PerspectiveTable.svelte @@ -79,8 +79,12 @@ const lastVisibleRowIndexRef = createRef(0); const disableLoadNextRef = createRef(false); + // Essential function !! + // Fills nested data into parentRows (assigns into array parentRows[i][node.fieldName]) + // eg. when node is CustomJoinTreeNode, loads data from data provider async function loadLevelData(node: PerspectiveTreeNode, parentRows: any[], counts) { - /// console.log('loadLevelData', node, parentRows, counts); + // console.log('loadLevelData', node.codeName, node.fieldName, parentRows); + // console.log('COUNTS', node.codeName, counts); dbg('load level data', counts); // const loadProps: PerspectiveDataLoadPropsWithNode[] = []; const loadChildNodes = []; @@ -115,6 +119,9 @@ incompleteRowsIndicator: [node.designerId], }); } + } else { + // this is needed for nested call + rows = _.compact(_.flatten(parentRows.map(x => x[node.fieldName]))); } // console.log('TESTING NODE', node); @@ -127,14 +134,21 @@ // if (child.preloadedLevelData) console.log('LOADING CHILD DATA', rows); // console.log(child.preloadedLevelData, child); // console.log('LOADING FOR CHILD', child.codeName, child.columnName, child); - // console.log('ROWS', child.preloadedLevelData ? parentRows : rows); + // console.log('CALL CHILD', child.codeName, rows, parentRows); await loadLevelData( child, - child.preloadedLevelData - ? _.compact(_.flatten(parentRows.map(x => x[child.columnName]))) - : node.preloadedLevelData - ? parentRows - : rows, + rows, + // node.preloadedLevelData + // ? _.compact(_.flatten(parentRows.map(x => x[child.columnName]))) + // : child.preloadedLevelData + // ? parentRows + // : rows, + // child.preloadedLevelData + // ? _.compact(_.flatten(parentRows.map(x => x[child.columnName]))) + // : node.preloadedLevelData + // ? parentRows + // : rows, + counts ); // loadProps.push(child.getNodeLoadProps()); diff --git a/plugins/dbgate-plugin-mongo/src/backend/driver.js b/plugins/dbgate-plugin-mongo/src/backend/driver.js index 1fd8444a..cbd81c33 100644 --- a/plugins/dbgate-plugin-mongo/src/backend/driver.js +++ b/plugins/dbgate-plugin-mongo/src/backend/driver.js @@ -258,7 +258,7 @@ const driver = { const count = await collection.countDocuments(convertObjectId(options.condition) || {}); return { count }; } else if (options.aggregate) { - let cursor = await collection.aggregate(options.aggregate); + let cursor = await collection.aggregate(convertObjectId(options.aggregate)); const rows = await cursor.toArray(); return { rows: rows.map(transformMongoData) }; } else {