mirror of
https://github.com/umami-software/umami.git
synced 2026-02-10 15:47:13 +01:00
Updated filtering logic.
This commit is contained in:
parent
6ee9bb07da
commit
810b0639c8
14 changed files with 97 additions and 83 deletions
|
|
@ -1,15 +1,46 @@
|
|||
import { OPERATOR_PREFIXES, OPERATORS } from 'lib/constants';
|
||||
import { FILTER_COLUMNS, OPERATOR_PREFIXES, OPERATORS } from 'lib/constants';
|
||||
import { QueryFilters, QueryOptions } from 'lib/types';
|
||||
|
||||
export function parseParameterValue(param: string) {
|
||||
const [, prefix, value] = param.match(/^(!~|!|~)?(.*)$/);
|
||||
export function parseParameterValue(param: any) {
|
||||
if (typeof param === 'string') {
|
||||
const [, prefix, value] = param.match(/^(!~|!|~)?(.*)$/);
|
||||
|
||||
const operator =
|
||||
Object.keys(OPERATOR_PREFIXES).find(key => OPERATOR_PREFIXES[key] === prefix) ||
|
||||
OPERATORS.equals;
|
||||
const operator =
|
||||
Object.keys(OPERATOR_PREFIXES).find(key => OPERATOR_PREFIXES[key] === prefix) ||
|
||||
OPERATORS.equals;
|
||||
|
||||
return { operator, value };
|
||||
return { operator, value };
|
||||
}
|
||||
return { operator: OPERATORS.equals, value: param };
|
||||
}
|
||||
|
||||
export function operatorEquals(operator: any) {
|
||||
export function isEqualsOperator(operator: any) {
|
||||
return [OPERATORS.equals, OPERATORS.notEquals].includes(operator);
|
||||
}
|
||||
|
||||
export function isSearchOperator(operator: any) {
|
||||
return [OPERATORS.contains, OPERATORS.doesNotContain].includes(operator);
|
||||
}
|
||||
|
||||
export function filtersToArray(filters: QueryFilters = {}, options: QueryOptions = {}) {
|
||||
return Object.keys(filters).reduce((arr, key) => {
|
||||
const filter = filters[key];
|
||||
|
||||
if (filter === undefined || filter === null) {
|
||||
return arr;
|
||||
}
|
||||
|
||||
if (filter?.name && filter?.value !== undefined) {
|
||||
return arr.concat(filter);
|
||||
}
|
||||
|
||||
const { operator, value } = parseParameterValue(filter);
|
||||
|
||||
return arr.concat({
|
||||
name: key,
|
||||
column: options?.columns?.[key] ?? FILTER_COLUMNS[key],
|
||||
operator,
|
||||
value,
|
||||
});
|
||||
}, []);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue