Skip to content

Commit

Permalink
refactor(mixins/table-header): set sharedOptions.fixed(Header|Footer)…
Browse files Browse the repository at this point in the history
… once in init

This was previously done in the init of each component.

This also fixes the broken tests. `fixed` is *immutable*.
  • Loading branch information
buschtoens committed Feb 22, 2018
1 parent 21dfd63 commit 35c8993
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 23 deletions.
8 changes: 1 addition & 7 deletions addon/components/lt-foot.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import Component from '@ember/component';
import { get, trySet } from '@ember/object';
import layout from 'ember-light-table/templates/components/lt-foot';
import TableHeaderMixin from 'ember-light-table/mixins/table-header';

Expand Down Expand Up @@ -36,10 +35,5 @@ export default Component.extend(TableHeaderMixin, {
classNames: ['lt-foot-wrap'],
table: null,
sharedOptions: null,

init() {
this._super(...arguments);

trySet(this, 'sharedOptions.fixedFooter', get(this, 'fixed'));
}
sharedOptionsFixedKey: 'fixedFooter'
});
8 changes: 1 addition & 7 deletions addon/components/lt-head.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import Component from '@ember/component';
import { get, trySet } from '@ember/object';
import layout from 'ember-light-table/templates/components/lt-head';
import TableHeaderMixin from 'ember-light-table/mixins/table-header';

Expand Down Expand Up @@ -38,10 +37,5 @@ export default Component.extend(TableHeaderMixin, {
classNames: ['lt-head-wrap'],
table: null,
sharedOptions: null,

init() {
this._super(...arguments);

trySet(this, 'sharedOptions.fixedHeader', get(this, 'fixed'));
}
sharedOptionsFixedKey: 'fixedHeader'
});
9 changes: 6 additions & 3 deletions addon/mixins/table-header.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Mixin from '@ember/object/mixin';
import { computed } from '@ember/object';
import { computed, trySet } from '@ember/object';
import { isEmpty } from '@ember/utils';
import { warn } from '@ember/debug';
import { inject as service } from '@ember/service';
Expand Down Expand Up @@ -146,8 +146,11 @@ export default Mixin.create({
init() {
this._super(...arguments);

let fixed = this.get('fixed');
let height = this.get('sharedOptions.height');
const fixed = this.get('fixed');
const sharedOptionsFixedPath = `sharedOptions.${this.get('sharedOptionsFixedKey')}`;
trySet(this, sharedOptionsFixedPath, fixed);

const height = this.get('sharedOptions.height');

warn(
'You did not set a `height` attribute for your table, but marked a header or footer to be fixed. This means that you have to set the table height via CSS. For more information please refer to: https://github.com/offirgolan/ember-light-table/issues/446',
Expand Down
20 changes: 14 additions & 6 deletions tests/integration/components/light-table-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,37 +61,45 @@ module('Integration | Component | light table', function(hooks) {
test('fixed header', async function(assert) {
assert.expect(2);
this.set('table', new Table(Columns, createUsers(5)));
this.set('fixed', true);

await render(hbs `
{{#light-table table height='500px' id='lightTable' as |t|}}
{{t.head fixed=fixed}}
{{t.head fixed=true}}
{{t.body}}
{{/light-table}}
`);

assert.equal(findAll('#lightTable_inline_head thead').length, 0);

this.set('fixed', false);
await render(hbs `
{{#light-table table height='500px' id='lightTable' as |t|}}
{{t.head fixed=false}}
{{t.body}}
{{/light-table}}
`);

assert.equal(findAll('#lightTable_inline_head thead').length, 1);
});

test('fixed footer', async function(assert) {
assert.expect(2);
this.set('table', new Table(Columns, createUsers(5)));
this.set('fixed', true);

await render(hbs `
{{#light-table table height='500px' id='lightTable' as |t|}}
{{t.body}}
{{t.foot fixed=fixed}}
{{t.foot fixed=true}}
{{/light-table}}
`);

assert.equal(findAll('#lightTable_inline_foot tfoot').length, 0);

this.set('fixed', false);
await render(hbs `
{{#light-table table height='500px' id='lightTable' as |t|}}
{{t.body}}
{{t.foot fixed=false}}
{{/light-table}}
`);

assert.equal(findAll('#lightTable_inline_foot tfoot').length, 1);
});
Expand Down

0 comments on commit 35c8993

Please sign in to comment.