@@ -31,7 +31,10 @@ export const FiltersExpressionsSelect: React.FC<Props> = ({
3131 values : string [ ] ;
3232 } > ( { fieldName : '' , values : [ ] } ) ;
3333
34- const currentFilters = useFilterUpdate ( updatedFieldValues . fieldName , updatedFieldValues . values ) ;
34+ const { selectedLocations, selectedPorts, selectedSchemes, selectedTags } = useFilterUpdate (
35+ updatedFieldValues . fieldName ,
36+ updatedFieldValues . values
37+ ) ;
3538
3639 useEffect ( ( ) => {
3740 if ( updatedFieldValues . fieldName === 'observer.geo.name' ) {
@@ -45,13 +48,6 @@ export const FiltersExpressionsSelect: React.FC<Props> = ({
4548 // eslint-disable-next-line react-hooks/exhaustive-deps
4649 } , [ ] ) ;
4750
48- const selectedTags = currentFilters . get ( 'tags' ) ;
49- const selectedPorts = currentFilters . get ( 'url.port' ) ;
50- const selectedScheme = currentFilters . get ( 'monitor.type' ) ;
51- const selectedLocation = currentFilters . get ( 'observer.geo.name' ) ;
52-
53- const getSelectedItems = ( fieldName : string ) => currentFilters . get ( fieldName ) || [ ] ;
54-
5551 const onFilterFieldChange = ( fieldName : string , values : string [ ] ) => {
5652 setUpdatedFieldValues ( { fieldName, values } ) ;
5753 } ;
@@ -64,10 +60,11 @@ export const FiltersExpressionsSelect: React.FC<Props> = ({
6460 id : 'filter_port' ,
6561 disabled : ports ?. length === 0 ,
6662 items : ports ?. map ( ( p : number ) => p . toString ( ) ) ?? [ ] ,
67- selectedItems : getSelectedItems ( 'url.port' ) ,
63+ selectedItems : selectedPorts ,
6864 title : filterLabels . PORT ,
69- description : selectedPorts ? alertFilterLabels . USING_PORT : alertFilterLabels . USING ,
70- value : selectedPorts ?. join ( ',' ) ?? alertFilterLabels . ANY_PORT ,
65+ description :
66+ selectedPorts . length === 0 ? alertFilterLabels . USING : alertFilterLabels . USING_PORT ,
67+ value : selectedPorts . length === 0 ? alertFilterLabels . ANY_PORT : selectedPorts ?. join ( ',' ) ,
7168 } ,
7269 {
7370 onFilterFieldChange,
@@ -76,10 +73,10 @@ export const FiltersExpressionsSelect: React.FC<Props> = ({
7673 id : 'filter_tags' ,
7774 disabled : tags ?. length === 0 ,
7875 items : tags ?? [ ] ,
79- selectedItems : getSelectedItems ( 'tags' ) ,
76+ selectedItems : selectedTags ,
8077 title : filterLabels . TAGS ,
81- description : selectedTags ? alertFilterLabels . WITH_TAG : alertFilterLabels . WITH ,
82- value : selectedTags ?. join ( ',' ) ?? alertFilterLabels . ANY_TAG ,
78+ description : selectedTags . length === 0 ? alertFilterLabels . WITH : alertFilterLabels . WITH_TAG ,
79+ value : selectedTags . length === 0 ? alertFilterLabels . ANY_TAG : selectedTags ?. join ( ',' ) ,
8380 } ,
8481 {
8582 onFilterFieldChange,
@@ -88,10 +85,10 @@ export const FiltersExpressionsSelect: React.FC<Props> = ({
8885 id : 'filter_scheme' ,
8986 disabled : schemes ?. length === 0 ,
9087 items : schemes ?? [ ] ,
91- selectedItems : getSelectedItems ( 'monitor.type' ) ,
88+ selectedItems : selectedSchemes ,
9289 title : filterLabels . SCHEME ,
93- description : selectedScheme ? alertFilterLabels . OF_TYPE : alertFilterLabels . OF ,
94- value : selectedScheme ?. join ( ',' ) ?? alertFilterLabels . ANY_TYPE ,
90+ description : selectedSchemes . length === 0 ? alertFilterLabels . OF : alertFilterLabels . OF_TYPE ,
91+ value : selectedSchemes . length === 0 ? alertFilterLabels . ANY_TYPE : selectedSchemes ?. join ( ',' ) ,
9592 } ,
9693 {
9794 onFilterFieldChange,
@@ -100,10 +97,14 @@ export const FiltersExpressionsSelect: React.FC<Props> = ({
10097 id : 'filter_location' ,
10198 disabled : locations ?. length === 0 ,
10299 items : locations ?? [ ] ,
103- selectedItems : getSelectedItems ( 'observer.geo.name' ) ,
100+ selectedItems : selectedLocations ,
104101 title : filterLabels . SCHEME ,
105- description : selectedLocation ? alertFilterLabels . FROM_LOCATION : alertFilterLabels . FROM ,
106- value : selectedLocation ?. join ( ',' ) ?? alertFilterLabels . ANY_LOCATION ,
102+ description :
103+ selectedLocations . length === 0 ? alertFilterLabels . FROM : alertFilterLabels . FROM_LOCATION ,
104+ value :
105+ selectedLocations . length === 0
106+ ? alertFilterLabels . ANY_LOCATION
107+ : selectedLocations ?. join ( ',' ) ,
107108 } ,
108109 ] ;
109110
0 commit comments