⚡ (condition) Add regex comparison item
This commit is contained in:
@@ -43,9 +43,33 @@ export const ComparisonItem = ({
|
||||
<TextInput
|
||||
defaultValue={item.value ?? ''}
|
||||
onChange={handleChangeValue}
|
||||
placeholder="Type a value..."
|
||||
placeholder={parseValuePlaceholder(item.comparisonOperator)}
|
||||
/>
|
||||
)}
|
||||
</Stack>
|
||||
)
|
||||
}
|
||||
|
||||
const parseValuePlaceholder = (
|
||||
operator: ComparisonOperators | undefined
|
||||
): string => {
|
||||
switch (operator) {
|
||||
case ComparisonOperators.NOT_EQUAL:
|
||||
case ComparisonOperators.EQUAL:
|
||||
case ComparisonOperators.CONTAINS:
|
||||
case ComparisonOperators.STARTS_WITH:
|
||||
case ComparisonOperators.ENDS_WITH:
|
||||
case ComparisonOperators.NOT_CONTAINS:
|
||||
case undefined:
|
||||
return 'Type a value...'
|
||||
case ComparisonOperators.LESS:
|
||||
case ComparisonOperators.GREATER:
|
||||
return 'Type a number...'
|
||||
case ComparisonOperators.IS_SET:
|
||||
case ComparisonOperators.IS_EMPTY:
|
||||
return ''
|
||||
case ComparisonOperators.MATCHES_REGEX:
|
||||
case ComparisonOperators.NOT_MATCH_REGEX:
|
||||
return '^[0-9]+$'
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,5 +74,9 @@ const parseComparisonOperatorSymbol = (
|
||||
return 'is empty'
|
||||
case ComparisonOperators.NOT_CONTAINS:
|
||||
return 'not contains'
|
||||
case ComparisonOperators.MATCHES_REGEX:
|
||||
return 'matches'
|
||||
case ComparisonOperators.NOT_MATCH_REGEX:
|
||||
return 'not matches'
|
||||
}
|
||||
}
|
||||
|
||||
@@ -896,7 +896,9 @@
|
||||
"Is set",
|
||||
"Is empty",
|
||||
"Starts with",
|
||||
"Ends with"
|
||||
"Ends with",
|
||||
"Matches regex",
|
||||
"Does not match regex"
|
||||
]
|
||||
},
|
||||
"value": {
|
||||
@@ -1662,7 +1664,9 @@
|
||||
"Is set",
|
||||
"Is empty",
|
||||
"Starts with",
|
||||
"Ends with"
|
||||
"Ends with",
|
||||
"Matches regex",
|
||||
"Does not match regex"
|
||||
]
|
||||
},
|
||||
"value": {
|
||||
@@ -1863,7 +1867,9 @@
|
||||
"Is set",
|
||||
"Is empty",
|
||||
"Starts with",
|
||||
"Ends with"
|
||||
"Ends with",
|
||||
"Matches regex",
|
||||
"Does not match regex"
|
||||
]
|
||||
},
|
||||
"value": {
|
||||
@@ -2457,7 +2463,9 @@
|
||||
"Is set",
|
||||
"Is empty",
|
||||
"Starts with",
|
||||
"Ends with"
|
||||
"Ends with",
|
||||
"Matches regex",
|
||||
"Does not match regex"
|
||||
]
|
||||
},
|
||||
"value": {
|
||||
@@ -2653,7 +2661,9 @@
|
||||
"Is set",
|
||||
"Is empty",
|
||||
"Starts with",
|
||||
"Ends with"
|
||||
"Ends with",
|
||||
"Matches regex",
|
||||
"Does not match regex"
|
||||
]
|
||||
},
|
||||
"value": {
|
||||
|
||||
@@ -490,7 +490,9 @@
|
||||
"Is set",
|
||||
"Is empty",
|
||||
"Starts with",
|
||||
"Ends with"
|
||||
"Ends with",
|
||||
"Matches regex",
|
||||
"Does not match regex"
|
||||
]
|
||||
},
|
||||
"value": {
|
||||
@@ -1256,7 +1258,9 @@
|
||||
"Is set",
|
||||
"Is empty",
|
||||
"Starts with",
|
||||
"Ends with"
|
||||
"Ends with",
|
||||
"Matches regex",
|
||||
"Does not match regex"
|
||||
]
|
||||
},
|
||||
"value": {
|
||||
@@ -1457,7 +1461,9 @@
|
||||
"Is set",
|
||||
"Is empty",
|
||||
"Starts with",
|
||||
"Ends with"
|
||||
"Ends with",
|
||||
"Matches regex",
|
||||
"Does not match regex"
|
||||
]
|
||||
},
|
||||
"value": {
|
||||
@@ -2051,7 +2057,9 @@
|
||||
"Is set",
|
||||
"Is empty",
|
||||
"Starts with",
|
||||
"Ends with"
|
||||
"Ends with",
|
||||
"Matches regex",
|
||||
"Does not match regex"
|
||||
]
|
||||
},
|
||||
"value": {
|
||||
@@ -2247,7 +2255,9 @@
|
||||
"Is set",
|
||||
"Is empty",
|
||||
"Starts with",
|
||||
"Ends with"
|
||||
"Ends with",
|
||||
"Matches regex",
|
||||
"Does not match regex"
|
||||
]
|
||||
},
|
||||
"value": {
|
||||
@@ -3904,7 +3914,9 @@
|
||||
"Is set",
|
||||
"Is empty",
|
||||
"Starts with",
|
||||
"Ends with"
|
||||
"Ends with",
|
||||
"Matches regex",
|
||||
"Does not match regex"
|
||||
]
|
||||
},
|
||||
"value": {
|
||||
@@ -4670,7 +4682,9 @@
|
||||
"Is set",
|
||||
"Is empty",
|
||||
"Starts with",
|
||||
"Ends with"
|
||||
"Ends with",
|
||||
"Matches regex",
|
||||
"Does not match regex"
|
||||
]
|
||||
},
|
||||
"value": {
|
||||
|
||||
@@ -89,6 +89,20 @@ const executeComparison =
|
||||
}
|
||||
return compare(endsWith, inputValue, value)
|
||||
}
|
||||
case ComparisonOperators.MATCHES_REGEX: {
|
||||
const matchesRegex = (a: string | null, b: string | null) => {
|
||||
if (b === '' || !b || !a) return false
|
||||
return new RegExp(b).test(a)
|
||||
}
|
||||
return compare(matchesRegex, inputValue, value, 'some')
|
||||
}
|
||||
case ComparisonOperators.NOT_MATCH_REGEX: {
|
||||
const matchesRegex = (a: string | null, b: string | null) => {
|
||||
if (b === '' || !b || !a) return false
|
||||
return !new RegExp(b).test(a)
|
||||
}
|
||||
return compare(matchesRegex, inputValue, value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user