mirror of
https://github.com/umami-software/umami.git
synced 2026-02-06 21:57:16 +01:00
Filter tag enhancements.
This commit is contained in:
parent
a4d8afe516
commit
ef11124672
12 changed files with 160 additions and 64 deletions
|
|
@ -94,6 +94,13 @@ export const OPERATORS = {
|
|||
after: 'af',
|
||||
} as const;
|
||||
|
||||
export const OPERATOR_PREFIXES = {
|
||||
[OPERATORS.equals]: '',
|
||||
[OPERATORS.notEquals]: '!',
|
||||
[OPERATORS.contains]: '~',
|
||||
[OPERATORS.doesNotContain]: '!~',
|
||||
};
|
||||
|
||||
export const DATA_TYPES = {
|
||||
[DATA_TYPE.string]: 'string',
|
||||
[DATA_TYPE.number]: 'number',
|
||||
|
|
|
|||
15
src/lib/params.ts
Normal file
15
src/lib/params.ts
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
import { OPERATOR_PREFIXES, OPERATORS } from 'lib/constants';
|
||||
|
||||
export function parseParameterValue(param: string) {
|
||||
const [, prefix, value] = param.match(/^(!~|!|~)?(.*)$/);
|
||||
|
||||
const operator =
|
||||
Object.keys(OPERATOR_PREFIXES).find(key => OPERATOR_PREFIXES[key] === prefix) ||
|
||||
OPERATORS.equals;
|
||||
|
||||
return { operator, value };
|
||||
}
|
||||
|
||||
export function operatorEquals(operator: any) {
|
||||
return [OPERATORS.equals, OPERATORS.notEquals].includes(operator);
|
||||
}
|
||||
|
|
@ -1,13 +1,7 @@
|
|||
import { NextApiRequest } from 'next';
|
||||
import { getAllowedUnits, getMinimumUnit } from './date';
|
||||
import { getWebsiteDateRange } from '../queries';
|
||||
import { FILTER_COLUMNS, OPERATORS } from 'lib/constants';
|
||||
|
||||
const OPERATOR_SYMBOLS = {
|
||||
'!': 'neq',
|
||||
'~': 'c',
|
||||
'!~': 'dnc',
|
||||
};
|
||||
import { FILTER_COLUMNS, OPERATORS, OPERATOR_PREFIXES } from 'lib/constants';
|
||||
|
||||
export async function parseDateRangeQuery(req: NextApiRequest) {
|
||||
const { websiteId, startAt, endAt, unit } = req.query;
|
||||
|
|
@ -52,7 +46,7 @@ export function getQueryFilters(req: NextApiRequest) {
|
|||
obj[key] = {
|
||||
name: key,
|
||||
column: FILTER_COLUMNS[key],
|
||||
operator: OPERATOR_SYMBOLS[prefix] || OPERATORS.equals,
|
||||
operator: OPERATOR_PREFIXES[prefix] || OPERATORS.equals,
|
||||
value: paramValue,
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue