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: 15 additions & 8 deletions addon/components/hyper-table-v2/filtering-renderers/numeric.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ interface HyperTableV2FilteringRenderersNumericArgs {
column: Column;
}

export type FilterUpdateIntentStatus = 'pending' | 'fulfilled' | 'rejected';

const RANGE_DEBOUNCE_TIME = 500;
const DEFAULT_MULTIPLIER = 1;

Expand Down Expand Up @@ -77,6 +79,7 @@ export default class HyperTableV2FilteringRenderersNumeric extends Component<Hyp
@action
addRangeFilter(): void {
debounce(this, this._addRangeFilter, isTesting() ? 0 : RANGE_DEBOUNCE_TIME);
this.args.handler.triggerEvent('filterUpdateIntent', this.args.column, 'pending');
}

@action
Expand All @@ -91,14 +94,18 @@ export default class HyperTableV2FilteringRenderersNumeric extends Component<Hyp
}

private _addRangeFilter(): void {
this.args.handler.applyFilters(this.args.column, [
...(this.lowerBoundFilter
? [{ key: 'lower_bound', value: (parseInt(this.lowerBoundFilter) * this.multiplier).toString() }]
: []),
...(this.upperBoundFilter
? [{ key: 'upper_bound', value: (parseInt(this.upperBoundFilter) * this.multiplier).toString() }]
: [])
]);
this.args.handler
.applyFilters(this.args.column, [
...(this.lowerBoundFilter
? [{ key: 'lower_bound', value: (parseInt(this.lowerBoundFilter) * this.multiplier).toString() }]
: []),
...(this.upperBoundFilter
? [{ key: 'upper_bound', value: (parseInt(this.upperBoundFilter) * this.multiplier).toString() }]
: []),
...(this.lowerBoundFilter || this.upperBoundFilter ? [{ key: 'existence', value: 'with' }] : [])
])
.then(() => this.args.handler.triggerEvent('filterUpdateIntent', this.args.column, 'fulfilled'))
.catch(() => this.args.handler.triggerEvent('filterUpdateIntent', this.args.column, 'rejected'));
}

private initLowerBound(): void {
Expand Down
25 changes: 14 additions & 11 deletions addon/core/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,17 +265,20 @@ export default class TableHandler {
column,
'filters',
filters
.reduce((acc, v) => {
const filterWithSameKey = acc.find((filter) => filter.key === v.key);

if (filterWithSameKey) {
filterWithSameKey.value = v.value;
} else {
acc.push(v);
}

return acc;
}, column.filters)
.reduce(
(acc, v) => {
const filterWithSameKey = acc.find((filter) => filter.key === v.key);

if (filterWithSameKey) {
filterWithSameKey.value = v.value;
} else {
acc.push(v);
}

return acc;
},
column.filters.filter((f) => filters.find((nf) => nf.key === f.key))
)
.filter((f) => !isEmpty(f.key) && !isEmpty(f.value))
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,12 @@ module('Integration | Component | hyper-table-v2/filtering-renderers/numeric', f
//@ts-ignore
{ code: 'Enter' }
);
assert.ok(handlerSpy.applyFilters.calledWith(this.column, [{ key: 'lower_bound', value: '1' }]));
assert.ok(
handlerSpy.applyFilters.calledWith(this.column, [
{ key: 'lower_bound', value: '1' },
{ key: 'existence', value: 'with' }
])
);

await fillIn('[data-control-name="hypertable__column_filtering_for_total_range_to"]', '9');
await triggerKeyEvent(
Expand All @@ -196,7 +201,8 @@ module('Integration | Component | hyper-table-v2/filtering-renderers/numeric', f
assert.ok(
handlerSpy.applyFilters.calledWith(this.column, [
{ key: 'lower_bound', value: '1' },
{ key: 'upper_bound', value: '9' }
{ key: 'upper_bound', value: '9' },
{ key: 'existence', value: 'with' }
])
);
});
Expand Down
12 changes: 12 additions & 0 deletions tests/unit/core/handler-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,18 @@ module('Unit | core/handler', function (hooks) {
{ key: 'fizz', value: 'buzz' }
]);
});

test('removed filters are cleared', function (this: TestContext, assert: Assert) {
this.handler.columns[0].filters = [
{ key: 'foo', value: 'bar' },
{ key: 'fizz', value: 'buzz' }
];

this.handler.applyFilters(this.handler.columns[0], [{ key: 'fizz', value: 'buzz' }]);

assert.equal(this.handler.columns[0].filters.length, 1);
assert.deepEqual(this.handler.columns[0].filters, [{ key: 'fizz', value: 'buzz' }]);
});
});

module('Handler#resetColumns', function () {
Expand Down