Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions addon/components/ember-tbody/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import CollapseTree, { SELECT_MODE } from '../../-private/collapse-tree';
import defaultTo from '../../-private/utils/default-to';

import layout from './template';
import { assert } from '@ember/debug';
import { assert, runInDebug } from '@ember/debug';

/**
The table body component. This component manages the main bulk of the rows of
Expand Down Expand Up @@ -258,12 +258,24 @@ export default Component.extend({

this._updateCollapseTree();

runInDebug(() => {
let scheduleUpdate = (this._scheduleUpdate = () => {
run.scheduleOnce('actions', this, this._updateDataTestRowCount);
});
this.collapseTree.addObserver('rows', scheduleUpdate);
this.collapseTree.addObserver('[]', scheduleUpdate);
});

assert(
'You must create an {{ember-thead}} with columns before creating an {{ember-tbody}}',
!!this.get('unwrappedApi.columnTree')
);
},

_updateDataTestRowCount() {
this.set('dataTestRowCount', this.get('collapseTree.length'));
},

// eslint-disable-next-line
_updateCollapseTree: observer(
'unwrappedApi.{sorts,sortFunction,compareFunction,sortEmptyLast}',
Expand Down Expand Up @@ -295,6 +307,10 @@ export default Component.extend({
this.rowMetaCache.delete(row);
}

runInDebug(() => {
this.collapseTree.removeObserver('rows', this._scheduleUpdate);
this.collapseTree.removeObserver('[]', this._scheduleUpdate);
});
this.collapseTree.destroy();
},

Expand All @@ -309,11 +325,6 @@ export default Component.extend({
this.collapseTree.set('rowMetaCache', this.rowMetaCache);
this.collapseTree.set('rows', rows);

run.schedule('actions', () => {
// eslint-disable-next-line ember-best-practices/no-side-effect-cp
this.set('dataTestRowCount', this.get('wrappedRows.length')); // eslint-disable-line ember/no-side-effects
});

return this.collapseTree;
}),

Expand Down
3 changes: 3 additions & 0 deletions tests/integration/components/tree-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,21 @@ module('Integration | Tree', () => {
await generateTable(this, { rowCount: 2, rowDepth: 2 });

assert.equal(table.rows.length, 6, 'renders all rows');
assert.equal(table.body.rowCount, 6, 'total number of rows');
assert.equal(table.getCell(0, 0).text, '0A', 'correct cell rendered');
assert.equal(table.getCell(1, 0).text, '00A', 'correct cell rendered');

// toggle a row
await table.rows.objectAt(0).toggleCollapse();
assert.equal(table.rows.length, 4, 'rows were removed');
assert.equal(table.body.rowCount, 4, 'total number of rows removed');
assert.equal(table.getCell(0, 0).text, '0A', 'correct cell rendered');
assert.equal(table.getCell(1, 0).text, '1A', 'correct cell rendered');

// uncollapse
await table.rows.objectAt(0).toggleCollapse();
assert.equal(table.rows.length, 6, 'rows were removed');
assert.equal(table.body.rowCount, 6, 'total number of rows removed');
assert.equal(table.getCell(0, 0).text, '0A', 'correct cell rendered');
assert.equal(table.getCell(1, 0).text, '00A', 'correct cell rendered');
});
Expand Down