#135 [intUI/Filter] filtering non-/empty values possible with '--'/'++'
This commit is contained in:
parent
1a8fb9276e
commit
ab88505144
@ -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;
|
||||
|
@ -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';
|
||||
|
Loading…
Reference in New Issue
Block a user