@@ -21,16 +21,14 @@ import { parse as parseQueryString, ParsedQuery, stringify as stringifyQueryStri
21
21
import {
22
22
FilterChips ,
23
23
GroupedFilterSelectPicker ,
24
- OptionType ,
25
24
SearchBar ,
26
- SelectPicker ,
27
25
useAsync ,
28
26
useRegisterShortcut ,
29
27
} from '@devtron-labs/devtron-fe-common-lib'
30
28
31
29
import { getClusterCapacity } from '@Components/ClusterNodes/clusterNodes.service'
32
30
33
- import { DEFAULT_NODE_K8S_VERSION , NODE_K8S_VERSION_FILTER_KEY } from '../Constants'
31
+ import { NODE_K8S_VERSION_FILTER_KEY } from '../Constants'
34
32
import { ClusterDetailBaseParams , NODE_SEARCH_KEYS , NodeListSearchFilterType } from '../Types'
35
33
import ColumnSelector from './ColumnSelector'
36
34
import {
@@ -75,7 +73,10 @@ const NodeListSearchFilter = ({
75
73
} , [ ] )
76
74
77
75
// CONSTANTS
78
- const isNodeSearchFilterApplied = searchParams [ NODE_SEARCH_KEYS . LABEL ] || searchParams [ NODE_SEARCH_KEYS . NODE_GROUP ]
76
+ const isNodeSearchFilterApplied =
77
+ searchParams [ NODE_SEARCH_KEYS . LABEL ] ||
78
+ searchParams [ NODE_SEARCH_KEYS . NODE_GROUP ] ||
79
+ searchParams [ NODE_K8S_VERSION_FILTER_KEY ]
79
80
80
81
// ASYNC CALLS
81
82
const [ nodeK8sVersionsLoading , nodeK8sVersionOptions , nodeK8sVersionsError , refetchNodeK8sVersions ] =
@@ -84,34 +85,26 @@ const NodeListSearchFilter = ({
84
85
result : { nodeK8sVersions : versions } ,
85
86
} = await getClusterCapacity ( clusterId )
86
87
87
- return [
88
- DEFAULT_NODE_K8S_VERSION ,
89
- ...( versions ?. map ( ( version ) => ( {
90
- label : `K8s version: ${ version } ` ,
91
- value : version ,
92
- } ) ) || [ ] ) ,
93
- ]
88
+ return ( versions || [ ] ) . map ( ( version ) => ( {
89
+ label : version ,
90
+ value : version ,
91
+ } ) )
94
92
} , [ clusterId ] )
95
93
96
94
// CONFIGS
97
- const selectedK8sNodeVersion = searchParams [ NODE_K8S_VERSION_FILTER_KEY ] ?? ''
98
-
99
- const selectedK8sVersionOption = useMemo (
100
- ( ) =>
101
- nodeK8sVersionOptions ?. find ( ( option ) => option . value === selectedK8sNodeVersion ) ??
102
- DEFAULT_NODE_K8S_VERSION ,
103
- [ nodeK8sVersionOptions , selectedK8sNodeVersion ] ,
104
- )
105
-
106
95
const { nodeGroups, labels } = useMemo ( ( ) => getNodeSearchKeysOptionsList ( rows ) , [ JSON . stringify ( rows ) ] )
107
96
108
97
const appliedFilters = useMemo ( ( ) => {
109
98
const nodeGroupMap = new Set ( ( ( searchParams [ NODE_SEARCH_KEYS . NODE_GROUP ] as string ) || '' ) . split ( ',' ) )
110
99
const labelMap = new Set ( ( ( searchParams [ NODE_SEARCH_KEYS . LABEL ] as string ) || '' ) . split ( ',' ) )
100
+ const k8sNodeVersionMap = new Set ( ( ( searchParams [ NODE_K8S_VERSION_FILTER_KEY ] as string ) || '' ) . split ( ',' ) )
111
101
112
102
return {
113
103
[ NODE_SEARCH_KEYS . NODE_GROUP ] : nodeGroups . filter ( ( { value } ) => nodeGroupMap . has ( value ) ) ,
114
104
[ NODE_SEARCH_KEYS . LABEL ] : labels . filter ( ( { value } ) => labelMap . has ( value ) ) ,
105
+ [ NODE_K8S_VERSION_FILTER_KEY ] : ( nodeK8sVersionOptions || [ ] ) . filter ( ( { value } ) =>
106
+ k8sNodeVersionMap . has ( value ) ,
107
+ ) ,
115
108
}
116
109
} , [ searchParams ] )
117
110
@@ -127,28 +120,15 @@ const NodeListSearchFilter = ({
127
120
push ( `?${ finalQueryString } ` )
128
121
}
129
122
130
- const handleApplyNodeK8sVersion = ( option : OptionType ) => {
131
- handleQueryParamsUpdate ( ( queryObject ) => {
132
- const finalQueryObject = structuredClone ( queryObject )
133
-
134
- if ( option . value === DEFAULT_NODE_K8S_VERSION . value ) {
135
- delete finalQueryObject [ NODE_K8S_VERSION_FILTER_KEY ]
136
- } else {
137
- finalQueryObject [ NODE_K8S_VERSION_FILTER_KEY ] = option . value
138
- }
139
-
140
- return finalQueryObject
141
- } )
142
- }
143
-
144
123
const handleSearchInputKeyUp = ( e : KeyboardEvent < HTMLInputElement > ) => {
145
124
if ( e . key === 'Escape' || e . key === 'Esc' ) {
146
125
searchInputRef . current ?. blur ( )
147
126
}
148
127
}
149
128
150
129
const handleSearchFilterChange =
151
- ( nodeSearchKey : NODE_SEARCH_KEYS ) => ( filtersToApply : NodeSearchListOptionType [ ] ) => {
130
+ ( nodeSearchKey : NODE_SEARCH_KEYS | typeof NODE_K8S_VERSION_FILTER_KEY ) =>
131
+ ( filtersToApply : NodeSearchListOptionType [ ] ) => {
152
132
handleQueryParamsUpdate ( ( queryObject ) => {
153
133
const updatedQueryObject = structuredClone ( queryObject )
154
134
@@ -188,6 +168,8 @@ const NodeListSearchFilter = ({
188
168
delete updatedQueryObject [ keyValue ]
189
169
} )
190
170
171
+ delete updatedQueryObject [ NODE_K8S_VERSION_FILTER_KEY ]
172
+
191
173
return updatedQueryObject
192
174
} )
193
175
}
@@ -196,7 +178,9 @@ const NodeListSearchFilter = ({
196
178
197
179
return (
198
180
< >
199
- < div className = "node-listing-search-container pt-16 px-20 dc__zi-5" >
181
+ < div
182
+ className = { `node-listing-search-container pt-16 px-20 dc__zi-5 ${ ! isNodeSearchFilterApplied ? 'pb-12' : '' } ` }
183
+ >
200
184
< SearchBar
201
185
initialSearchText = { searchKey }
202
186
handleSearchChange = { handleSearch }
@@ -208,7 +192,7 @@ const NodeListSearchFilter = ({
208
192
} }
209
193
/>
210
194
211
- < GroupedFilterSelectPicker < NODE_SEARCH_KEYS >
195
+ < GroupedFilterSelectPicker < NODE_SEARCH_KEYS | typeof NODE_K8S_VERSION_FILTER_KEY >
212
196
filterSelectPickerPropsMap = { {
213
197
[ NODE_SEARCH_KEYS . NODE_GROUP ] : {
214
198
inputId : 'node-search-filter-node-groups' ,
@@ -230,23 +214,25 @@ const NodeListSearchFilter = ({
230
214
isDisabled : false ,
231
215
isLoading : false ,
232
216
} ,
217
+ [ NODE_K8S_VERSION_FILTER_KEY ] : {
218
+ inputId : 'k8s-version-select' ,
219
+ placeholder : NODE_SEARCH_KEY_PLACEHOLDER [ NODE_K8S_VERSION_FILTER_KEY ] ,
220
+ options : [ { label : 'K8s version' , options : nodeK8sVersionOptions || [ ] } ] ,
221
+ getOptionValue,
222
+ appliedFilterOptions : appliedFilters [ NODE_K8S_VERSION_FILTER_KEY ] ,
223
+ handleApplyFilter : handleSearchFilterChange ( NODE_K8S_VERSION_FILTER_KEY ) ,
224
+ isDisabled : false ,
225
+ isLoading : nodeK8sVersionsLoading ,
226
+ optionListError : nodeK8sVersionsError ,
227
+ reloadOptionList : refetchNodeK8sVersions ,
228
+ } ,
233
229
} }
234
230
id = "node-list-search-filter"
235
231
options = { NODE_LIST_SEARCH_FILTER_OPTIONS }
236
232
isFilterApplied = { isNodeSearchFilterApplied }
237
233
width = { 150 }
238
234
/>
239
235
240
- < SelectPicker
241
- inputId = "k8s-version-select"
242
- optionListError = { nodeK8sVersionsError }
243
- reloadOptionList = { refetchNodeK8sVersions }
244
- isLoading = { nodeK8sVersionsLoading }
245
- options = { nodeK8sVersionOptions ?? [ ] }
246
- onChange = { handleApplyNodeK8sVersion }
247
- value = { selectedK8sVersionOption }
248
- />
249
-
250
236
< div className = "dc__border-left h-20 mt-6" />
251
237
252
238
{ allColumns . length ? (
@@ -261,13 +247,16 @@ const NodeListSearchFilter = ({
261
247
< div className = "shimmer h-32" />
262
248
) }
263
249
</ div >
264
- < FilterChips < Partial < Record < NODE_SEARCH_KEYS , string [ ] > > >
250
+ < FilterChips < Partial < Record < NODE_SEARCH_KEYS | typeof NODE_K8S_VERSION_FILTER_KEY , string [ ] > > >
265
251
className = "px-20 pb-12"
266
252
filterConfig = { {
267
253
[ NODE_SEARCH_KEYS . NODE_GROUP ] : appliedFilters [ NODE_SEARCH_KEYS . NODE_GROUP ] . map (
268
254
( { value } ) => value ,
269
255
) ,
270
256
[ NODE_SEARCH_KEYS . LABEL ] : appliedFilters [ NODE_SEARCH_KEYS . LABEL ] . map ( ( { value } ) => value ) ,
257
+ [ NODE_K8S_VERSION_FILTER_KEY ] : appliedFilters [ NODE_K8S_VERSION_FILTER_KEY ] . map (
258
+ ( { value } ) => value ,
259
+ ) ,
271
260
} }
272
261
onRemoveFilter = { handleRemoveFilter }
273
262
clearFilters = { handleClearFilters }
0 commit comments