add regex operators
This commit is contained in:
1 parent
67626652f9
commit
f2cf071523
59 files changed
+136
-2
No files matched your search
@@ -14,6 +14,8 @@ export function useFilters() {
|
||||
{ name: 'neq', type: 'string', label: t(labels.isNot) },
|
||||
{ name: 'c', type: 'string', label: t(labels.contains) },
|
||||
{ name: 'dnc', type: 'string', label: t(labels.doesNotContain) },
|
||||
{ name: 're', type: 'string', label: t(labels.regexMatch) },
|
||||
{ name: 'nre', type: 'string', label: t(labels.regexNotMatch) },
|
||||
{ name: 'i', type: 'array', label: t(labels.includes) },
|
||||
{ name: 'dni', type: 'array', label: t(labels.doesNotInclude) },
|
||||
{ name: 't', type: 'boolean', label: t(labels.isTrue) },
|
||||
@@ -36,6 +38,8 @@ export function useFilters() {
|
||||
[OPERATORS.notSet]: t(labels.isNotSet),
|
||||
[OPERATORS.contains]: t(labels.contains),
|
||||
[OPERATORS.doesNotContain]: t(labels.doesNotContain),
|
||||
[OPERATORS.regex]: t(labels.regexMatch),
|
||||
[OPERATORS.notRegex]: t(labels.regexNotMatch),
|
||||
[OPERATORS.true]: t(labels.true),
|
||||
[OPERATORS.false]: t(labels.false),
|
||||
[OPERATORS.greaterThan]: t(labels.greaterThan),
|
||||
@@ -47,7 +51,14 @@ export function useFilters() {
|
||||
};
|
||||
|
||||
const typeFilters = {
|
||||
string: [OPERATORS.equals, OPERATORS.notEquals, OPERATORS.contains, OPERATORS.doesNotContain],
|
||||
string: [
|
||||
OPERATORS.equals,
|
||||
OPERATORS.notEquals,
|
||||
OPERATORS.contains,
|
||||
OPERATORS.doesNotContain,
|
||||
OPERATORS.regex,
|
||||
OPERATORS.notRegex,
|
||||
],
|
||||
array: [OPERATORS.contains, OPERATORS.doesNotContain],
|
||||
boolean: [OPERATORS.true, OPERATORS.false],
|
||||
number: [
|
||||
|
||||
@@ -198,6 +198,8 @@ export const labels: Record<string, string> = {
|
||||
lessThanEquals: 'label.less-than-equals',
|
||||
contains: 'label.contains',
|
||||
doesNotContain: 'label.does-not-contain',
|
||||
regexMatch: 'label.regex-match',
|
||||
regexNotMatch: 'label.regex-not-match',
|
||||
includes: 'label.includes',
|
||||
doesNotInclude: 'label.does-not-include',
|
||||
before: 'label.before',
|
||||
|
||||
@@ -82,6 +82,10 @@ function mapFilter(column: string, operator: string, name: string, type: string
|
||||
return `positionCaseInsensitive(${column}, ${value}) > 0`;
|
||||
case OPERATORS.doesNotContain:
|
||||
return `positionCaseInsensitive(${column}, ${value}) = 0`;
|
||||
case OPERATORS.regex:
|
||||
return `match(${column}, ${value})`;
|
||||
case OPERATORS.notRegex:
|
||||
return `not match(${column}, ${value})`;
|
||||
default:
|
||||
return '';
|
||||
}
|
||||
|
||||
@@ -129,6 +129,8 @@ export const OPERATORS = {
|
||||
notSet: 'ns',
|
||||
contains: 'c',
|
||||
doesNotContain: 'dnc',
|
||||
regex: 're',
|
||||
notRegex: 'nre',
|
||||
true: 't',
|
||||
false: 'f',
|
||||
greaterThan: 'gt',
|
||||
|
||||
+6
-1
@@ -31,7 +31,12 @@ export function isEqualsOperator(operator: any) {
|
||||
}
|
||||
|
||||
export function isSearchOperator(operator: any) {
|
||||
return [OPERATORS.contains, OPERATORS.doesNotContain].includes(operator);
|
||||
return [
|
||||
OPERATORS.contains,
|
||||
OPERATORS.doesNotContain,
|
||||
OPERATORS.regex,
|
||||
OPERATORS.notRegex,
|
||||
].includes(operator);
|
||||
}
|
||||
|
||||
export function filtersObjectToArray(filters: QueryFilters, options: QueryOptions = {}): Filter[] {
|
||||
|
||||
@@ -89,6 +89,10 @@ function mapFilter(column: string, operator: string, name: string, type: string
|
||||
return `${table}.${column} ilike ${value}`;
|
||||
case OPERATORS.doesNotContain:
|
||||
return `${table}.${column} not ilike ${value}`;
|
||||
case OPERATORS.regex:
|
||||
return `${table}.${column} ~ ${value}`;
|
||||
case OPERATORS.notRegex:
|
||||
return `${table}.${column} !~ ${value}`;
|
||||
default:
|
||||
return '';
|
||||
}
|
||||
|
||||
@@ -143,6 +143,8 @@ export const operatorParam = z.enum([
|
||||
'ns',
|
||||
'c',
|
||||
'dnc',
|
||||
're',
|
||||
'nre',
|
||||
't',
|
||||
'f',
|
||||
'gt',
|
||||
|
||||
Reference in new issue
Block a user