filterClause.ts
TLDR
The filterClause.ts
file contains code related to filter clauses. It includes the types FilterCondition
and FilterClause
, as well as the functions createFilterClause
and areEqual
. These functions allow for the creation and comparison of filter clauses.
Methods
createFilterClause
This method creates a filter clause object based on the given parameters. It takes an optional o
parameter which is an object containing the properties propertyId
, condition
, and values
. If o
is not provided, default values are used. The method returns the created filter clause object.
areEqual
This method compares two filter clause objects a
and b
to determine if they are equal. It checks if the propertyId
, condition
, and values
properties of the two objects are the same. It returns true
if the objects are equal and false
otherwise.
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {Utils} from '../utils'
type FilterCondition =
'includes' | 'notIncludes' |
'isEmpty' | 'isNotEmpty' |
'isSet' | 'isNotSet' |
'is' |
'contains' | 'notContains' |
'startsWith' | 'notStartsWith' |
'endsWith' | 'notEndsWith' |
'isBefore' | 'isAfter'
type FilterClause = {
propertyId: string
condition: FilterCondition
values: string[]
}
function createFilterClause(o?: FilterClause): FilterClause {
return {
propertyId: o?.propertyId || '',
condition: o?.condition || 'includes',
values: o?.values?.slice() || [],
}
}
function areEqual(a: FilterClause, b: FilterClause): boolean {
return (
a.propertyId === b.propertyId &&
a.condition === b.condition &&
Utils.arraysEqual(a.values, b.values)
)
}
export {FilterClause, FilterCondition, createFilterClause, areEqual}