#135 [intUI/Filter] filtering non-/empty values possible with '--'/'++'

This commit is contained in:
Michael Hoennig 2019-05-03 12:22:10 +02:00
parent 1a8fb9276e
commit ab88505144
2 changed files with 33 additions and 5 deletions

View File

@ -38,12 +38,18 @@ export class TableFilter<T extends {}> {
let queryCriteria: any = {} as any;
Object.keys(this.criteria).forEach(name => {
const value = this.criteria[name];
const queryDef = this.query[name];
if (typeof queryDef !== 'function') {
queryCriteria[queryDef] = value;
if (value === '--') {
queryCriteria[name + '.specified'] = false;
} else if (value === '++') {
queryCriteria[name + '.specified'] = true;
} else {
const additionalQueryCriteria = queryDef(name, value);
queryCriteria = { ...queryCriteria, ...additionalQueryCriteria };
const queryDef = this.query[name];
if (typeof queryDef !== 'function') {
queryCriteria[queryDef] = value;
} else {
const additionalQueryCriteria = queryDef(name, value);
queryCriteria = { ...queryCriteria, ...additionalQueryCriteria };
}
}
});
return queryCriteria;

View File

@ -73,6 +73,28 @@ describe('TableFilter Tests', () => {
expect(filter.buildQueryCriteria()).toEqual({ 'name.contains': 'test value' });
});
it('when filter "name" is set to "--", buildQueryCriteria() returns a name.specified=false query', () => {
// given
filter.criteria.name = '--';
// when
const actual = filter.buildQueryCriteria();
// then
expect(filter.buildQueryCriteria()).toEqual({ 'name.specified': false });
});
it('when filter "name" is set to "++", buildQueryCriteria() returns a name.specified=true query', () => {
// given
filter.criteria.name = '++';
// when
const actual = filter.buildQueryCriteria();
// then
expect(filter.buildQueryCriteria()).toEqual({ 'name.specified': true });
});
it('when filter "number" is set, buildQueryCriteria() returns a number.equals query', () => {
// given
filter.criteria.number = '-42';