#135 [intUI/Filter] filtering non-/empty values possible with '--'/'++'
This commit is contained in:
parent
1a8fb9276e
commit
ab88505144
@ -38,6 +38,11 @@ export class TableFilter<T extends {}> {
|
|||||||
let queryCriteria: any = {} as any;
|
let queryCriteria: any = {} as any;
|
||||||
Object.keys(this.criteria).forEach(name => {
|
Object.keys(this.criteria).forEach(name => {
|
||||||
const value = this.criteria[name];
|
const value = this.criteria[name];
|
||||||
|
if (value === '--') {
|
||||||
|
queryCriteria[name + '.specified'] = false;
|
||||||
|
} else if (value === '++') {
|
||||||
|
queryCriteria[name + '.specified'] = true;
|
||||||
|
} else {
|
||||||
const queryDef = this.query[name];
|
const queryDef = this.query[name];
|
||||||
if (typeof queryDef !== 'function') {
|
if (typeof queryDef !== 'function') {
|
||||||
queryCriteria[queryDef] = value;
|
queryCriteria[queryDef] = value;
|
||||||
@ -45,6 +50,7 @@ export class TableFilter<T extends {}> {
|
|||||||
const additionalQueryCriteria = queryDef(name, value);
|
const additionalQueryCriteria = queryDef(name, value);
|
||||||
queryCriteria = { ...queryCriteria, ...additionalQueryCriteria };
|
queryCriteria = { ...queryCriteria, ...additionalQueryCriteria };
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
return queryCriteria;
|
return queryCriteria;
|
||||||
}
|
}
|
||||||
|
@ -73,6 +73,28 @@ describe('TableFilter Tests', () => {
|
|||||||
expect(filter.buildQueryCriteria()).toEqual({ 'name.contains': 'test value' });
|
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', () => {
|
it('when filter "number" is set, buildQueryCriteria() returns a number.equals query', () => {
|
||||||
// given
|
// given
|
||||||
filter.criteria.number = '-42';
|
filter.criteria.number = '-42';
|
||||||
|
Loading…
Reference in New Issue
Block a user