focalboard/webapp/src/filterGroup.ts

32 lines
953 B
TypeScript
Raw Normal View History

2020-10-20 21:50:53 +02:00
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
2020-10-20 21:52:56 +02:00
import {FilterClause} from './filterClause'
2020-10-08 18:21:27 +02:00
2020-10-20 21:50:53 +02:00
type FilterGroupOperation = 'and' | 'or'
2020-10-08 18:21:27 +02:00
// A FilterGroup has 2 forms: (A or B or C) OR (A and B and C)
class FilterGroup {
2020-10-20 21:50:53 +02:00
operation: FilterGroupOperation = 'and'
filters: (FilterClause | FilterGroup)[] = []
2020-10-08 18:21:27 +02:00
2020-10-20 21:50:53 +02:00
static isAnInstanceOf(object: any): object is FilterGroup {
return 'innerOperation' in object && 'filters' in object
2020-10-20 21:50:53 +02:00
}
2020-10-08 18:21:27 +02:00
2020-10-20 21:50:53 +02:00
constructor(o: any = {}) {
2020-10-20 21:52:56 +02:00
this.operation = o.operation || 'and'
2020-10-22 04:54:21 +02:00
if (o.filters) {
this.filters = o.filters.map((p: any) => {
2020-10-20 21:50:53 +02:00
if (FilterGroup.isAnInstanceOf(p)) {
return new FilterGroup(p)
}
return new FilterClause(p)
2020-10-22 04:54:21 +02:00
})
} else {
this.filters = []
}
2020-10-20 21:50:53 +02:00
}
2020-10-08 18:21:27 +02:00
}
2020-10-20 21:50:53 +02:00
export {FilterGroup, FilterGroupOperation}