@@ -3,6 +3,7 @@ import { SearchIcon } from '@patternfly/react-icons';
33import * as _ from 'lodash' ;
44import * as React from 'react' ;
55import { createFilterValue , FilterDefinition , FilterValue } from '../../../model/filters' ;
6+ import { doubleQuoteValue , undefinedValue } from '../../../utils/filter-definitions' ;
67import { Indicator } from '../../../utils/filters-helper' ;
78
89export interface TextFilterProps {
@@ -11,6 +12,7 @@ export interface TextFilterProps {
1112 setMessageWithDelay : ( m : string | undefined ) => void ;
1213 indicator : Indicator ;
1314 setIndicator : ( ind : Indicator ) => void ;
15+ allowEmpty ?: boolean ;
1416 regexp ?: RegExp ;
1517}
1618
@@ -20,6 +22,7 @@ export const TextFilter: React.FC<TextFilterProps> = ({
2022 setMessageWithDelay,
2123 indicator,
2224 setIndicator,
25+ allowEmpty,
2326 regexp
2427} ) => {
2528 const searchInputRef = React . useRef < HTMLInputElement | null > ( null ) ;
@@ -38,7 +41,7 @@ export const TextFilter: React.FC<TextFilterProps> = ({
3841 const updateValue = React . useCallback (
3942 ( v : string ) => {
4043 let filteredValue = v ;
41- if ( regexp ) {
44+ if ( ! [ doubleQuoteValue , undefinedValue ] . includes ( filteredValue ) && regexp ) {
4245 filteredValue = filteredValue . replace ( regexp , '' ) ;
4346 }
4447 setCurrentValue ( filteredValue ) ;
@@ -53,7 +56,17 @@ export const TextFilter: React.FC<TextFilterProps> = ({
5356 } , [ setCurrentValue , setMessageWithDelay , setIndicator ] ) ;
5457
5558 const onSelect = React . useCallback ( ( ) => {
56- const validation = filterDefinition . validate ( String ( currentValue ) ) ;
59+ // override empty value by undefined value
60+ let v = currentValue ;
61+ if ( allowEmpty ) {
62+ if ( currentValue . length === 0 ) {
63+ v = undefinedValue ;
64+ }
65+ } else if ( v === undefinedValue ) {
66+ v = '' ;
67+ }
68+
69+ const validation = filterDefinition . validate ( String ( v ) ) ;
5770 //show tooltip and icon when user try to validate filter
5871 if ( ! _ . isEmpty ( validation . err ) ) {
5972 setMessageWithDelay ( validation . err ) ;
@@ -66,7 +79,7 @@ export const TextFilter: React.FC<TextFilterProps> = ({
6679 resetFilterValue ( ) ;
6780 }
6881 } ) ;
69- } , [ filterDefinition , currentValue , setMessageWithDelay , setIndicator , addFilter , resetFilterValue ] ) ;
82+ } , [ currentValue , allowEmpty , filterDefinition , setMessageWithDelay , setIndicator , addFilter , resetFilterValue ] ) ;
7083
7184 return (
7285 < >
0 commit comments