diff --git a/packages/datalib/src/PerspectiveCache.ts b/packages/datalib/src/PerspectiveCache.ts index 00ef68cd9..478bca5dd 100644 --- a/packages/datalib/src/PerspectiveCache.ts +++ b/packages/datalib/src/PerspectiveCache.ts @@ -5,6 +5,7 @@ import _difference from 'lodash/difference'; import debug from 'debug'; import stableStringify from 'json-stable-stringify'; import { PerspectiveDataPattern } from './PerspectiveDataPattern'; +import { perspectiveValueMatcherSimple } from './perspectiveTools'; const dbg = debug('dbgate:PerspectiveCache'); @@ -17,7 +18,9 @@ export class PerspectiveBindingGroup { bindingValues: any[]; matchRow(row) { - return this.table.bindingColumns.every((column, index) => row[column] == this.bindingValues[index]); + return this.table.bindingColumns.every((column, index) => + perspectiveValueMatcherSimple(row[column], this.bindingValues[index]) + ); } } @@ -69,7 +72,11 @@ export class PerspectiveCacheTable { } storeGroupSize(props: PerspectiveDataLoadProps, bindingValues: any[], count: number) { - const originalBindingValue = props.bindingValues.find(v => _zip(v, bindingValues).every(([x, y]) => x == y)); + const originalBindingValue = props.bindingValues.find(v => + _zip(v, bindingValues).every(([x, y]) => perspectiveValueMatcherSimple(x, y)) + ); + // console.log('storeGroupSize NEW', bindingValues); + // console.log('storeGroupSize ORIGINAL', originalBindingValue); if (originalBindingValue) { const key = stableStringify(originalBindingValue); // console.log('SET SIZE', originalBindingValue, bindingValues, key, count); diff --git a/packages/datalib/src/PerspectiveDataProvider.ts b/packages/datalib/src/PerspectiveDataProvider.ts index d05e0a891..d1dd11dd1 100644 --- a/packages/datalib/src/PerspectiveDataProvider.ts +++ b/packages/datalib/src/PerspectiveDataProvider.ts @@ -47,6 +47,7 @@ export class PerspectiveDataProvider { async loadDataNested(props: PerspectiveDataLoadProps): Promise<{ rows: any[]; incomplete: boolean }> { const tableCache = this.cache.getTableCache(props); + // console.log('loadDataNested', props); const uncached = tableCache.getUncachedBindingGroups(props); if (uncached.length > 0) { diff --git a/packages/datalib/src/PerspectiveTreeNode.ts b/packages/datalib/src/PerspectiveTreeNode.ts index 05ae64277..2ee46e502 100644 --- a/packages/datalib/src/PerspectiveTreeNode.ts +++ b/packages/datalib/src/PerspectiveTreeNode.ts @@ -39,7 +39,11 @@ import { Condition, Expression, Select } from 'dbgate-sqltree'; // import { getPerspectiveDefaultColumns } from './getPerspectiveDefaultColumns'; import uuidv1 from 'uuid/v1'; import { PerspectiveDataPatternColumn } from './PerspectiveDataPattern'; -import { getPerspectiveMostNestedChildColumnName, getPerspectiveParentColumnName } from './perspectiveTools'; +import { + getPerspectiveMostNestedChildColumnName, + getPerspectiveParentColumnName, + perspectiveValueMatcher, +} from './perspectiveTools'; export interface PerspectiveDataLoadPropsWithNode { props: PerspectiveDataLoadProps; @@ -1248,9 +1252,14 @@ 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]) { + if ( + !perspectiveValueMatcher( + parentRow[getPerspectiveMostNestedChildColumnName(column.baseColumnName)], + childRow[column.refColumnName] + ) + ) { return false; } } diff --git a/packages/datalib/src/perspectiveTools.ts b/packages/datalib/src/perspectiveTools.ts index 38a2c84ba..5a93757b3 100644 --- a/packages/datalib/src/perspectiveTools.ts +++ b/packages/datalib/src/perspectiveTools.ts @@ -8,3 +8,15 @@ export function getPerspectiveMostNestedChildColumnName(columnName: string) { const path = columnName.split('::'); return path[path.length - 1]; } + +export function perspectiveValueMatcher(value1, value2): boolean { + if (value1?.$oid && value2?.$oid) return value1.$oid == value2.$oid; + if (Array.isArray(value1)) return !!value1.find(x => perspectiveValueMatcher(x, value2)); + if (Array.isArray(value2)) return !!value2.find(x => perspectiveValueMatcher(value1, x)); + return value1 == value2; +} + +export function perspectiveValueMatcherSimple(value1, value2): boolean { + if (value1?.$oid && value2?.$oid) return value1.$oid == value2.$oid; + return value1 == value2; +} diff --git a/packages/web/src/perspectives/PerspectiveTable.svelte b/packages/web/src/perspectives/PerspectiveTable.svelte index 115628661..de62982f0 100644 --- a/packages/web/src/perspectives/PerspectiveTable.svelte +++ b/packages/web/src/perspectives/PerspectiveTable.svelte @@ -106,6 +106,7 @@ }); } } else if (!node.preloadedLevelData) { + // console.log('LOADED ROWS', rows); let lastRowWithChildren = null; for (const parentRow of parentRows) { const childRows = rows.filter(row => node.matchChildRow(parentRow, row));