#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;
|
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];
|
||||||
const queryDef = this.query[name];
|
if (value === '--') {
|
||||||
if (typeof queryDef !== 'function') {
|
queryCriteria[name + '.specified'] = false;
|
||||||
queryCriteria[queryDef] = value;
|
} else if (value === '++') {
|
||||||
|
queryCriteria[name + '.specified'] = true;
|
||||||
} else {
|
} else {
|
||||||
const additionalQueryCriteria = queryDef(name, value);
|
const queryDef = this.query[name];
|
||||||
queryCriteria = { ...queryCriteria, ...additionalQueryCriteria };
|
if (typeof queryDef !== 'function') {
|
||||||
|
queryCriteria[queryDef] = value;
|
||||||
|
} else {
|
||||||
|
const additionalQueryCriteria = queryDef(name, value);
|
||||||
|
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