From d647d30258b8818871da11b320181408d6ffa10f Mon Sep 17 00:00:00 2001 From: Jan Prochazka Date: Sun, 2 Oct 2022 11:30:05 +0200 Subject: [PATCH] perspective nosql test --- .../datalib/src/PerspectiveDataPattern.ts | 2 +- packages/datalib/src/PerspectiveDisplay.ts | 7 +-- packages/datalib/src/PerspectiveTreeNode.ts | 35 +++++++++++-- .../src/tests/PerspectiveDisplay.test.ts | 52 +++++++++++++++++++ 4 files changed, 88 insertions(+), 8 deletions(-) diff --git a/packages/datalib/src/PerspectiveDataPattern.ts b/packages/datalib/src/PerspectiveDataPattern.ts index e61b0f6f..6974ba5c 100644 --- a/packages/datalib/src/PerspectiveDataPattern.ts +++ b/packages/datalib/src/PerspectiveDataPattern.ts @@ -17,7 +17,7 @@ export interface PerspectiveDataPatternColumn { export interface PerspectiveDataPattern { conid: string; database: string; - schemaName: string; + schemaName?: string; pureName: string; columns: PerspectiveDataPatternColumn[]; } diff --git a/packages/datalib/src/PerspectiveDisplay.ts b/packages/datalib/src/PerspectiveDisplay.ts index 7bf8d3e1..75d7bfa4 100644 --- a/packages/datalib/src/PerspectiveDisplay.ts +++ b/packages/datalib/src/PerspectiveDisplay.ts @@ -126,14 +126,14 @@ export class PerspectiveDisplay { fillColumns(children: PerspectiveTreeNode[], parentNodes: PerspectiveTreeNode[]) { for (const child of children) { - if (child.isCheckedColumn || child.isCheckedNode) { + if (child.generatesHiearchicGridColumn || child.generatesDataGridColumn) { this.processColumn(child, parentNodes); } } } processColumn(node: PerspectiveTreeNode, parentNodes: PerspectiveTreeNode[]) { - if (node.isCheckedColumn) { + if (node.generatesDataGridColumn) { const column = new PerspectiveDisplayColumn(this); column.title = node.columnTitle; column.dataField = node.dataField; @@ -145,7 +145,7 @@ export class PerspectiveDisplay { this.columns.push(column); } - if (node.isExpandable && node.isCheckedNode) { + if (node.generatesHiearchicGridColumn) { const countBefore = this.columns.length; this.fillColumns(node.childNodes, [...parentNodes, node]); @@ -185,6 +185,7 @@ export class PerspectiveDisplay { const subRowCollections = []; for (const node of treeNodes) { + // console.log('sourceRow[node.fieldName]', node.fieldName, sourceRow[node.fieldName]); if (sourceRow[node.fieldName]) { const subrows = { rows: this.collectRows(sourceRow[node.fieldName], node.childNodes), diff --git a/packages/datalib/src/PerspectiveTreeNode.ts b/packages/datalib/src/PerspectiveTreeNode.ts index 00e8ec42..b0c8a5e9 100644 --- a/packages/datalib/src/PerspectiveTreeNode.ts +++ b/packages/datalib/src/PerspectiveTreeNode.ts @@ -81,7 +81,7 @@ export abstract class PerspectiveTreeNode { this.parentNodeConfig = parentNode?.nodeConfig; } readonly nodeConfig: PerspectiveNodeConfig; - readonly parentNodeConfig: PerspectiveNodeConfig; + parentNodeConfig: PerspectiveNodeConfig; // defaultChecked: boolean; abstract get title(); abstract get codeName(); @@ -110,6 +110,15 @@ export abstract class PerspectiveTreeNode { get namedObject(): NamedObjectInfo { return null; } + get parentTableNode(): PerspectiveTableNode { + if (this instanceof PerspectiveTableNode) { + return this; + } + if (this.parentNode == null) { + return null; + } + return this.parentNode.parentTableNode; + } abstract getNodeLoadProps(parentRows: any[]): PerspectiveDataLoadProps; get isRoot() { return this.parentNode == null; @@ -121,6 +130,12 @@ export abstract class PerspectiveTreeNode { get isSortable() { return false; } + get generatesHiearchicGridColumn() { + return this.isExpandable && this.isCheckedNode; + } + get generatesDataGridColumn() { + return this.isCheckedColumn; + } matchChildRow(parentRow: any, childRow: any): boolean { return true; } @@ -273,12 +288,12 @@ export abstract class PerspectiveTreeNode { [field]: isIncluded ? [...(n[field] || []), this.codeName] : (n[field] || []).filter(x => x != this.codeName), }); - const [cfgChanged, nodeCfg] = this.parentNode?.ensureNodeConfig(cfg); + const [cfgChanged, nodeCfg] = this.parentTableNode?.ensureNodeConfig(cfg); return { ...cfgChanged, nodes: cfgChanged.nodes.map(n => - n.designerId == (this.parentNode?.designerId || nodeCfg?.designerId) ? changedFields(n) : n + n.designerId == (this.parentTableNode?.designerId || nodeCfg?.designerId) ? changedFields(n) : n ), }; }); @@ -727,6 +742,7 @@ export class PerspectivePatternColumnNode extends PerspectiveTreeNode { designerId: string ) { super(dbs, config, setConfig, parentNode, dataProvider, databaseConfig, designerId); + this.parentNodeConfig = this.parentTableNode?.nodeConfig; } get isChildColumn() { @@ -780,11 +796,22 @@ export class PerspectivePatternColumnNode extends PerspectiveTreeNode { return null; } + get generatesHiearchicGridColumn() { + return !!this.parentTableNode?.nodeConfig?.checkedColumns?.find(x => x.startsWith(this.codeName + '::')); + } + + // get generatesHiearchicGridColumn() { + // // return this.config &&; + // } + get icon() { return 'img column'; } get codeName() { + if (this.parentNode instanceof PerspectivePatternColumnNode) { + return `${this.parentNode.codeName}::${this.column.name}`; + } return this.column.name; } @@ -793,7 +820,7 @@ export class PerspectivePatternColumnNode extends PerspectiveTreeNode { } get fieldName() { - return this.codeName + 'Ref'; + return this.column.name; } get title() { diff --git a/packages/datalib/src/tests/PerspectiveDisplay.test.ts b/packages/datalib/src/tests/PerspectiveDisplay.test.ts index f86cc6b8..dfba7a3a 100644 --- a/packages/datalib/src/tests/PerspectiveDisplay.test.ts +++ b/packages/datalib/src/tests/PerspectiveDisplay.test.ts @@ -7,6 +7,9 @@ import artistDataFlat from './artistDataFlat'; import artistDataAlbum from './artistDataAlbum'; import artistDataAlbumTrack from './artistDataAlbumTrack'; import { processPerspectiveDefaultColunns } from '../processPerspectiveDefaultColunns'; +import { DatabaseAnalyser, isCollectionInfo } from 'dbgate-tools'; +import { analyseDataPattern } from '../PerspectiveDataPattern'; +import { PerspectiveDataProvider } from '../PerspectiveDataProvider'; test('test flat view', () => { const artistTable = chinookDbInfo.tables.find(x => x.pureName == 'Artist'); @@ -141,3 +144,52 @@ test('test two level nesting', () => { expect(display.rows[2].rowSpans).toEqual([1, 2, 1]); expect(display.rows[2].rowCellSkips).toEqual([true, false, false]); }); + +test('test nosql display', () => { + const collectionInfo = { + objectTypeField: 'collections', + pureName: 'Account', + }; + const dbInfo = { + ...DatabaseAnalyser.createEmptyStructure(), + collections: [collectionInfo], + }; + const accountData = [ + { name: 'jan', email: 'jan@foo.co', follows: [{ name: 'lucie' }, { name: 'petr' }] }, + { name: 'romeo', email: 'romeo@foo.co', follows: [{ name: 'julie' }, { name: 'wiliam' }] }, + ]; + const config = createPerspectiveConfig({ pureName: 'Account' }); + const dataPatterns = { + [config.rootDesignerId]: analyseDataPattern( + { + conid: 'conid', + database: 'db', + pureName: 'Account', + }, + accountData + ), + }; + + const configColumns = processPerspectiveDefaultColunns( + config, + { conid: { db: dbInfo } }, + dataPatterns, + 'conid', + 'db' + ); + const root = new PerspectiveTableNode( + collectionInfo, + { conid: { db: dbInfo } }, + configColumns, + null, + new PerspectiveDataProvider(null, null, dataPatterns), + { conid: 'conid', database: 'db' }, + null, + configColumns.rootDesignerId + ); + const display = new PerspectiveDisplay(root, accountData); + + expect(display.rows.length).toEqual(2); + expect(display.rows[0].rowData).toEqual(['jan']); + expect(display.rows[1].rowData).toEqual(['romeo']); +});