fixed bug in perspective display + fixed test

This commit is contained in:
Jan Prochazka
2022-08-25 18:01:00 +02:00
parent daf7629f5f
commit 5e4ae3208b
2 changed files with 37 additions and 8 deletions

View File

@@ -90,7 +90,7 @@ export class PerspectiveDisplay {
columns: PerspectiveDisplayColumn[] = [];
rows: PerspectiveDisplayRow[] = [];
readonly columnLevelCount: number;
loadIndicatorsCounts: { [uniqueName: string]: number } = {};
loadIndicatorsCounts: { [designerId: string]: number } = {};
constructor(public root: PerspectiveTreeNode, rows: any[]) {
// dbg('source rows', rows);
@@ -152,13 +152,25 @@ export class PerspectiveDisplay {
}
findColumnIndexFromNode(node: PerspectiveTreeNode) {
return _findIndex(this.columns, x => x.dataNode.designerId == node.designerId);
return _findIndex(
this.columns,
x =>
x.dataNode.columnName == node.columnName && x.dataNode?.parentNode?.designerId == node?.parentNode?.designerId
);
}
// findColumnIndexFromNode(node: PerspectiveTreeNode) {
// return _findIndex(this.columns, x => x.dataNode.designerId == node.designerId);
// }
collectRows(sourceRows: any[], nodes: PerspectiveTreeNode[]): CollectedPerspectiveDisplayRow[] {
// console.log('********** COLLECT ROWS', sourceRows);
const columnNodes = nodes.filter(x => x.isChecked && !x.isExpandable);
const treeNodes = nodes.filter(x => x.isChecked && x.isExpandable);
// console.log('columnNodes', columnNodes);
// console.log('treeNodes', treeNodes);
const columnIndexes = columnNodes.map(node => this.findColumnIndexFromNode(node));
const res: CollectedPerspectiveDisplayRow[] = [];

View File

@@ -2,7 +2,7 @@ import { TableInfo } from 'dbgate-types';
import { PerspectiveDisplay } from '../PerspectiveDisplay';
import { PerspectiveTableNode } from '../PerspectiveTreeNode';
import { chinookDbInfo } from './chinookDbInfo';
import { createPerspectiveConfig } from '../PerspectiveConfig';
import { createPerspectiveConfig, createPerspectiveNodeConfig } from '../PerspectiveConfig';
import artistDataFlat from './artistDataFlat';
import artistDataAlbum from './artistDataAlbum';
import artistDataAlbumTrack from './artistDataAlbumTrack';
@@ -16,7 +16,8 @@ test('test flat view', () => {
null,
null,
{ conid: 'conid', database: 'db' },
null
null,
'1'
);
const display = new PerspectiveDisplay(root, artistDataFlat);
@@ -35,19 +36,23 @@ test('test flat view', () => {
test('test one level nesting', () => {
const artistTable = chinookDbInfo.tables.find(x => x.pureName == 'Artist');
const config = createPerspectiveConfig({ pureName: 'Artist' });
config.nodes[0].checkedNodes = ['Album'];
const root = new PerspectiveTableNode(
artistTable,
{ conid: { db: chinookDbInfo } },
{ ...createPerspectiveConfig({ pureName: 'Artist' }), checkedColumns: ['Artist::Album'] },
config,
null,
null,
{ conid: 'conid', database: 'db' },
null
null,
config.nodes[0].designerId
);
const display = new PerspectiveDisplay(root, artistDataAlbum);
console.log(display.loadIndicatorsCounts);
// console.log(display.rows);
expect(display.rows.length).toEqual(6);
expect(display.rows[0]).toEqual(
expect.objectContaining({
@@ -85,14 +90,26 @@ test('test one level nesting', () => {
test('test two level nesting', () => {
const artistTable = chinookDbInfo.tables.find(x => x.pureName == 'Artist');
const config = createPerspectiveConfig({ pureName: 'Artist' });
config.nodes.push(createPerspectiveNodeConfig({ pureName: 'Album' }));
config.references.push({
sourceId: config.nodes[0].designerId,
targetId: config.nodes[1].designerId,
designerId: '1',
columns: [{ source: 'ArtistId', target: 'ArtistId' }],
});
config.nodes[0].checkedNodes = ['Album'];
config.nodes[1].checkedNodes = ['Track'];
const root = new PerspectiveTableNode(
artistTable,
{ conid: { db: chinookDbInfo } },
{ ...createPerspectiveConfig({ pureName: 'Artist' }), checkedColumns: ['Artist::Album', 'Artist::Album::Track'] },
config,
null,
null,
{ conid: 'conid', database: 'db' },
null
null,
config.nodes[0].designerId
);
const display = new PerspectiveDisplay(root, artistDataAlbumTrack);