2020-10-20 12:50:53 -07:00
|
|
|
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
|
|
// See LICENSE.txt for license information.
|
2020-10-25 11:15:52 +01:00
|
|
|
import {IntlShape} from 'react-intl'
|
2020-10-08 09:21:27 -07:00
|
|
|
|
2020-10-27 14:00:15 -07:00
|
|
|
import {Utils} from './utils'
|
|
|
|
|
2020-10-20 12:50:53 -07:00
|
|
|
type FilterCondition = 'includes' | 'notIncludes' | 'isEmpty' | 'isNotEmpty'
|
2020-10-08 09:21:27 -07:00
|
|
|
|
|
|
|
class FilterClause {
|
2020-10-20 12:50:53 -07:00
|
|
|
propertyId: string
|
|
|
|
condition: FilterCondition
|
|
|
|
values: string[]
|
2020-10-08 09:21:27 -07:00
|
|
|
|
2020-10-25 11:15:52 +01:00
|
|
|
static filterConditionDisplayString(filterCondition: FilterCondition, intl: IntlShape): string {
|
2020-10-20 12:50:53 -07:00
|
|
|
switch (filterCondition) {
|
2020-10-25 11:15:52 +01:00
|
|
|
case 'includes': return intl.formatMessage({id: 'Filter.includes', defaultMessage: 'includes'})
|
|
|
|
case 'notIncludes': return intl.formatMessage({id: 'Filter.not-includes', defaultMessage: 'doesn\'t include'})
|
|
|
|
case 'isEmpty': return intl.formatMessage({id: 'Filter.is-empty', defaultMessage: 'is empty'})
|
|
|
|
case 'isNotEmpty': return intl.formatMessage({id: 'Filter.is-not-empty', defaultMessage: 'is not empty'})
|
2020-10-20 12:50:53 -07:00
|
|
|
default: {
|
2020-10-21 15:03:12 -07:00
|
|
|
Utils.assertFailure()
|
|
|
|
return '(unknown)'
|
2020-10-20 12:50:53 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-10-08 09:21:27 -07:00
|
|
|
|
2020-10-20 12:50:53 -07:00
|
|
|
constructor(o: any = {}) {
|
2020-10-20 12:52:56 -07:00
|
|
|
this.propertyId = o.propertyId || ''
|
|
|
|
this.condition = o.condition || 'includes'
|
2020-10-20 12:50:53 -07:00
|
|
|
this.values = o.values?.slice() || []
|
|
|
|
}
|
2020-10-08 09:21:27 -07:00
|
|
|
|
2020-10-21 19:54:21 -07:00
|
|
|
isEqual(o: FilterClause): boolean {
|
2020-10-21 15:03:12 -07:00
|
|
|
return (
|
2020-10-20 12:50:53 -07:00
|
|
|
this.propertyId === o.propertyId &&
|
2020-10-21 15:03:12 -07:00
|
|
|
this.condition === o.condition &&
|
|
|
|
Utils.arraysEqual(this.values, o.values)
|
2020-10-20 12:50:53 -07:00
|
|
|
)
|
|
|
|
}
|
2020-10-08 09:21:27 -07:00
|
|
|
}
|
|
|
|
|
2020-10-20 12:50:53 -07:00
|
|
|
export {FilterClause, FilterCondition}
|