perspective display - mongo nested objects

This commit is contained in:
Jan Prochazka
2022-10-02 12:01:07 +02:00
parent d647d30258
commit 7a3c46b691
4 changed files with 124 additions and 59 deletions

View File

@@ -1,4 +1,3 @@
import { TableInfo } from 'dbgate-types';
import { PerspectiveDisplay } from '../PerspectiveDisplay';
import { PerspectiveTableNode } from '../PerspectiveTreeNode';
import { chinookDbInfo } from './chinookDbInfo';
@@ -7,9 +6,6 @@ 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');
@@ -144,52 +140,3 @@ 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']);
});

View File

@@ -0,0 +1,98 @@
import { PerspectiveDisplay } from '../PerspectiveDisplay';
import { PerspectiveTableNode } from '../PerspectiveTreeNode';
import { createPerspectiveConfig, PerspectiveNodeConfig } from '../PerspectiveConfig';
import { processPerspectiveDefaultColunns } from '../processPerspectiveDefaultColunns';
import { DatabaseAnalyser } from 'dbgate-tools';
import { analyseDataPattern } from '../PerspectiveDataPattern';
import { PerspectiveDataProvider } from '../PerspectiveDataProvider';
const accountData = [
{
name: 'jan',
email: 'jan@foo.co',
follows: [{ name: 'lucie' }, { name: 'petr' }],
nested: { email: 'jan@nest.cz' },
},
{
name: 'romeo',
email: 'romeo@foo.co',
follows: [{ name: 'julie' }, { name: 'wiliam' }],
nested: { email: 'romeo@nest.cz' },
},
];
function createDisplay(cfgFunc?: (cfg: PerspectiveNodeConfig) => void) {
const collectionInfo = {
objectTypeField: 'collections',
pureName: 'Account',
};
const dbInfo = {
...DatabaseAnalyser.createEmptyStructure(),
collections: [collectionInfo],
};
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'
);
if (cfgFunc) {
cfgFunc(configColumns.nodes[0]);
}
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);
return display;
}
test('test nosql display', () => {
const display = createDisplay();
expect(display.rows.length).toEqual(2);
expect(display.rows[0].rowData).toEqual(['jan']);
expect(display.rows[1].rowData).toEqual(['romeo']);
});
test('test nosql nested array display', () => {
const display = createDisplay(cfg => {
cfg.checkedColumns = ['name', 'follows::name'];
});
expect(display.rows.length).toEqual(4);
expect(display.rows[0].rowData).toEqual(['jan', 'lucie']);
expect(display.rows[1].rowData).toEqual([undefined, 'petr']);
expect(display.rows[2].rowData).toEqual(['romeo', 'julie']);
expect(display.rows[3].rowData).toEqual([undefined, 'wiliam']);
});
test('test nosql nested object', () => {
const display = createDisplay(cfg => {
cfg.checkedColumns = ['name', 'nested::email'];
});
expect(display.rows.length).toEqual(2);
expect(display.rows[0].rowData).toEqual(['jan', 'jan@nest.cz']);
expect(display.rows[1].rowData).toEqual(['romeo', 'romeo@nest.cz']);
});