focalboard/webapp/src/filterClause.ts

43 lines
1.5 KiB
TypeScript
Raw Normal View History

2020-10-20 12:50:53 -07:00
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
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
static filterConditionDisplayString(filterCondition: FilterCondition, intl: IntlShape): string {
2020-10-20 12:50:53 -07:00
switch (filterCondition) {
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: {
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 {
return (
2020-10-20 12:50:53 -07:00
this.propertyId === o.propertyId &&
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}