mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-24 22:16:00 +00:00
fixed bug in perspective display + fixed test
This commit is contained in:
@@ -90,7 +90,7 @@ export class PerspectiveDisplay {
|
|||||||
columns: PerspectiveDisplayColumn[] = [];
|
columns: PerspectiveDisplayColumn[] = [];
|
||||||
rows: PerspectiveDisplayRow[] = [];
|
rows: PerspectiveDisplayRow[] = [];
|
||||||
readonly columnLevelCount: number;
|
readonly columnLevelCount: number;
|
||||||
loadIndicatorsCounts: { [uniqueName: string]: number } = {};
|
loadIndicatorsCounts: { [designerId: string]: number } = {};
|
||||||
|
|
||||||
constructor(public root: PerspectiveTreeNode, rows: any[]) {
|
constructor(public root: PerspectiveTreeNode, rows: any[]) {
|
||||||
// dbg('source rows', rows);
|
// dbg('source rows', rows);
|
||||||
@@ -152,13 +152,25 @@ export class PerspectiveDisplay {
|
|||||||
}
|
}
|
||||||
|
|
||||||
findColumnIndexFromNode(node: PerspectiveTreeNode) {
|
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[] {
|
collectRows(sourceRows: any[], nodes: PerspectiveTreeNode[]): CollectedPerspectiveDisplayRow[] {
|
||||||
|
// console.log('********** COLLECT ROWS', sourceRows);
|
||||||
const columnNodes = nodes.filter(x => x.isChecked && !x.isExpandable);
|
const columnNodes = nodes.filter(x => x.isChecked && !x.isExpandable);
|
||||||
const treeNodes = 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 columnIndexes = columnNodes.map(node => this.findColumnIndexFromNode(node));
|
||||||
|
|
||||||
const res: CollectedPerspectiveDisplayRow[] = [];
|
const res: CollectedPerspectiveDisplayRow[] = [];
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { TableInfo } from 'dbgate-types';
|
|||||||
import { PerspectiveDisplay } from '../PerspectiveDisplay';
|
import { PerspectiveDisplay } from '../PerspectiveDisplay';
|
||||||
import { PerspectiveTableNode } from '../PerspectiveTreeNode';
|
import { PerspectiveTableNode } from '../PerspectiveTreeNode';
|
||||||
import { chinookDbInfo } from './chinookDbInfo';
|
import { chinookDbInfo } from './chinookDbInfo';
|
||||||
import { createPerspectiveConfig } from '../PerspectiveConfig';
|
import { createPerspectiveConfig, createPerspectiveNodeConfig } from '../PerspectiveConfig';
|
||||||
import artistDataFlat from './artistDataFlat';
|
import artistDataFlat from './artistDataFlat';
|
||||||
import artistDataAlbum from './artistDataAlbum';
|
import artistDataAlbum from './artistDataAlbum';
|
||||||
import artistDataAlbumTrack from './artistDataAlbumTrack';
|
import artistDataAlbumTrack from './artistDataAlbumTrack';
|
||||||
@@ -16,7 +16,8 @@ test('test flat view', () => {
|
|||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
{ conid: 'conid', database: 'db' },
|
{ conid: 'conid', database: 'db' },
|
||||||
null
|
null,
|
||||||
|
'1'
|
||||||
);
|
);
|
||||||
const display = new PerspectiveDisplay(root, artistDataFlat);
|
const display = new PerspectiveDisplay(root, artistDataFlat);
|
||||||
|
|
||||||
@@ -35,19 +36,23 @@ test('test flat view', () => {
|
|||||||
|
|
||||||
test('test one level nesting', () => {
|
test('test one level nesting', () => {
|
||||||
const artistTable = chinookDbInfo.tables.find(x => x.pureName == 'Artist');
|
const artistTable = chinookDbInfo.tables.find(x => x.pureName == 'Artist');
|
||||||
|
const config = createPerspectiveConfig({ pureName: 'Artist' });
|
||||||
|
config.nodes[0].checkedNodes = ['Album'];
|
||||||
const root = new PerspectiveTableNode(
|
const root = new PerspectiveTableNode(
|
||||||
artistTable,
|
artistTable,
|
||||||
{ conid: { db: chinookDbInfo } },
|
{ conid: { db: chinookDbInfo } },
|
||||||
{ ...createPerspectiveConfig({ pureName: 'Artist' }), checkedColumns: ['Artist::Album'] },
|
config,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
{ conid: 'conid', database: 'db' },
|
{ conid: 'conid', database: 'db' },
|
||||||
null
|
null,
|
||||||
|
config.nodes[0].designerId
|
||||||
);
|
);
|
||||||
const display = new PerspectiveDisplay(root, artistDataAlbum);
|
const display = new PerspectiveDisplay(root, artistDataAlbum);
|
||||||
|
|
||||||
console.log(display.loadIndicatorsCounts);
|
console.log(display.loadIndicatorsCounts);
|
||||||
// console.log(display.rows);
|
// console.log(display.rows);
|
||||||
|
|
||||||
expect(display.rows.length).toEqual(6);
|
expect(display.rows.length).toEqual(6);
|
||||||
expect(display.rows[0]).toEqual(
|
expect(display.rows[0]).toEqual(
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
@@ -85,14 +90,26 @@ test('test one level nesting', () => {
|
|||||||
|
|
||||||
test('test two level nesting', () => {
|
test('test two level nesting', () => {
|
||||||
const artistTable = chinookDbInfo.tables.find(x => x.pureName == 'Artist');
|
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(
|
const root = new PerspectiveTableNode(
|
||||||
artistTable,
|
artistTable,
|
||||||
{ conid: { db: chinookDbInfo } },
|
{ conid: { db: chinookDbInfo } },
|
||||||
{ ...createPerspectiveConfig({ pureName: 'Artist' }), checkedColumns: ['Artist::Album', 'Artist::Album::Track'] },
|
config,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
{ conid: 'conid', database: 'db' },
|
{ conid: 'conid', database: 'db' },
|
||||||
null
|
null,
|
||||||
|
config.nodes[0].designerId
|
||||||
);
|
);
|
||||||
const display = new PerspectiveDisplay(root, artistDataAlbumTrack);
|
const display = new PerspectiveDisplay(root, artistDataAlbumTrack);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user