Skip to content

Commit

Permalink
Add order independent TreeTable Row Child creation for js
Browse files Browse the repository at this point in the history
This tracks all row instances created and delays finalizing
the structure rather than doing it upon each row creation.
  • Loading branch information
twojtasz committed Jul 14, 2020
1 parent 0c68dce commit cd39bcd
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 9 deletions.
15 changes: 6 additions & 9 deletions modules/builder/src/builders/xviz-ui-primitive-builder.js
Expand Up @@ -69,16 +69,13 @@ export default class XVIZUIPrimitiveBuilder extends XVIZBaseBuilder {
}

row(id, values) {
if (this._type) {
this._flush();
}

this.validatePropSetOnce('_id');

this._row = new XVIZTreeTableRowBuilder(id, values);
const row = new XVIZTreeTableRowBuilder(id, values);
this._rows.push(row);
this._type = PRIMITIVE_TYPES.treetable;

return this._row;
return row;
}

_validate() {
Expand Down Expand Up @@ -144,8 +141,8 @@ export default class XVIZUIPrimitiveBuilder extends XVIZBaseBuilder {
_formatPrimitives() {
switch (this._type) {
case PRIMITIVE_TYPES.treetable:
if (this._row !== null) {
return this._row.getData();
if (this._rows.length > 0) {
return [].concat(...this._rows.map(row => row.getData()));
}
break;

Expand All @@ -159,6 +156,6 @@ export default class XVIZUIPrimitiveBuilder extends XVIZBaseBuilder {
this._type = null;

this._columns = null;
this._row = null;
this._rows = [];
}
}
33 changes: 33 additions & 0 deletions test/modules/builder/builders/xviz-ui-primitive-builder.spec.js
Expand Up @@ -101,3 +101,36 @@ test('XVIZUIPrimitiveBuilder#treetable', t => {

t.end();
});

test('XVIZUIPrimitiveBuilder#treetable row build order', t => {
let builder = new XVIZUIPrimitiveBuilder({validator});
builder = new XVIZUIPrimitiveBuilder({validator});
const row0 = builder
.stream('/test')
.treetable(TEST_COLUMNS)
.row(0, ['row0']);
const row2 = builder.row(2, null);

row0.child(1, ['row1']);
row2.child(3, ['row3']);

t.deepEquals(
builder.getData(),
{
'/test': {
treetable: {
columns: TEST_COLUMNS,
nodes: [
{id: 0, column_values: ['row0']},
{id: 1, parent: 0, column_values: ['row1']},
{id: 2},
{id: 3, parent: 2, column_values: ['row3']}
]
}
}
},
'XVIZUIPrimitiveBuilder returns correct data'
);

t.end();
});

0 comments on commit cd39bcd

Please sign in to comment.