14
14
* limitations under the License.
15
15
*/
16
16
17
- import React , { useEffect , useMemo , useState } from 'react'
17
+ import React , { useMemo , useState } from 'react'
18
18
import dayjs , { Dayjs } from 'dayjs'
19
19
20
20
import {
21
- BulkSelection ,
22
21
BulkSelectionEvents ,
23
22
BulkSelectionIdentifiersType ,
24
23
BulkSelectionProvider ,
@@ -27,7 +26,6 @@ import {
27
26
GenericEmptyState ,
28
27
SearchBar ,
29
28
SelectAllDialogStatus ,
30
- SortableTableHeaderCell ,
31
29
useBulkSelection ,
32
30
useUrlFilters ,
33
31
} from '@devtron-labs/devtron-fe-common-lib'
@@ -38,10 +36,10 @@ import Timer from '@Components/common/DynamicTabs/DynamicTabs.timer'
38
36
import { AddClusterButton } from '@Components/ResourceBrowser/PageHeader.buttons'
39
37
40
38
import { ClusterSelectionType } from '../ResourceBrowser/Types'
41
- import { ClusterListRow } from './ClusterListRow '
39
+ import { ClusterList } from './ClusterList '
42
40
import ClusterNodeEmptyState from './ClusterNodeEmptyStates'
43
- import { ClusterMapListSortableKeys , ClusterMapListSortableTitle , ClusterStatusByFilter } from './constants'
44
- import { getSortedClusterList } from './utils'
41
+ import { ClusterMapListSortableKeys , ClusterStatusByFilter } from './constants'
42
+ import { getSortedClusterList , parseSearchParams } from './utils'
45
43
46
44
import './clusterNodes.scss'
47
45
@@ -52,10 +50,7 @@ const ClusterBulkSelectionActionWidget = importComponentFromFELibrary(
52
50
null ,
53
51
'function' ,
54
52
)
55
-
56
- const parseSearchParams = ( searchParams : URLSearchParams ) => ( {
57
- clusterFilter : ( searchParams . get ( 'clusterFilter' ) as ClusterFiltersType ) || ClusterFiltersType . ALL_CLUSTERS ,
58
- } )
53
+ const KubeConfigModal = importComponentFromFELibrary ( 'KubeConfigModal' , null , 'function' )
59
54
60
55
const ClusterSelectionList : React . FC < ClusterSelectionType > = ( {
61
56
clusterOptions,
@@ -65,34 +60,18 @@ const ClusterSelectionList: React.FC<ClusterSelectionType> = ({
65
60
parentRef,
66
61
} ) => {
67
62
const [ lastSyncTime , setLastSyncTime ] = useState < Dayjs > ( dayjs ( ) )
63
+ const [ showKubeConfigModal , setKubeConfigModal ] = useState ( false )
64
+ const [ selectedClusterName , setSelectedClusterName ] = useState ( '' )
68
65
69
- const {
70
- searchKey,
71
- clusterFilter,
72
- updateSearchParams,
73
- handleSearch,
74
- clearFilters,
75
- sortBy,
76
- sortOrder,
77
- handleSorting,
78
- } = useUrlFilters < ClusterMapListSortableKeys , { clusterFilter : ClusterFiltersType } > ( {
79
- parseSearchParams,
80
- initialSortKey : ClusterMapListSortableKeys . CLUSTER_NAME ,
81
- } )
66
+ const { searchKey, clusterFilter, updateSearchParams, handleSearch, clearFilters, sortBy, sortOrder } =
67
+ useUrlFilters < ClusterMapListSortableKeys , { clusterFilter : ClusterFiltersType } > ( {
68
+ parseSearchParams,
69
+ initialSortKey : ClusterMapListSortableKeys . CLUSTER_NAME ,
70
+ } )
82
71
83
- const { handleBulkSelection, setIdentifiers , isBulkSelectionApplied, getSelectedIdentifiersCount } =
72
+ const { handleBulkSelection, isBulkSelectionApplied, getSelectedIdentifiersCount } =
84
73
useBulkSelection < BulkSelectionIdentifiersType < ClusterDetail > > ( )
85
74
86
- useEffect ( ( ) => {
87
- if ( clusterOptions . length ) {
88
- const clusterIdentifier : BulkSelectionIdentifiersType < ClusterDetail > = { }
89
- clusterOptions . forEach ( ( cluster ) => {
90
- clusterIdentifier [ cluster . name ] = cluster
91
- } )
92
- setIdentifiers ( clusterIdentifier )
93
- }
94
- } , [ clusterOptions ] )
95
-
96
75
const filteredList : ClusterDetail [ ] = useMemo ( ( ) => {
97
76
const loweredSearchKey = searchKey . toLowerCase ( )
98
77
const updatedClusterOptions = [ ...clusterOptions ]
@@ -141,11 +120,15 @@ const ClusterSelectionList: React.FC<ClusterSelectionType> = ({
141
120
)
142
121
}
143
122
144
- const handleCellSorting = ( cellToSort : ClusterMapListSortableKeys ) => ( ) => {
145
- handleSorting ( cellToSort )
123
+ const onChangeShowKubeConfigModal = ( ) => {
124
+ setKubeConfigModal ( true )
146
125
}
147
126
148
- const renderClusterListContent = ( ) => (
127
+ const onChangeCloseKubeConfigModal = ( ) => {
128
+ setKubeConfigModal ( false )
129
+ }
130
+
131
+ const renderClusterList = ( ) => (
149
132
< div className = "cluster-list-main-container flex-grow-1 flexbox-col bg__primary dc__overflow-auto" >
150
133
< div className = "flexbox dc__content-space pl-20 pr-20 pt-16 pb-16 dc__zi-4" >
151
134
< div className = "flex dc__gap-12" >
@@ -198,29 +181,13 @@ const ClusterSelectionList: React.FC<ClusterSelectionType> = ({
198
181
< ClusterNodeEmptyState actionHandler = { clearFilters } />
199
182
</ div >
200
183
) : (
201
- < div data-testid = "cluster-list-container" className = "flexbox-col flex-grow-1" >
202
- < div className = "cluster-list-row fw-6 cn-7 fs-12 dc__border-bottom pt-8 pb-8 pr-20 pl-20 dc__uppercase bg__primary dc__position-sticky dc__top-0 dc__zi-3" >
203
- { Object . entries ( ClusterMapListSortableKeys ) . map ( ( [ cellName , cellKey ] ) => (
204
- < >
205
- { cellKey === ClusterMapListSortableKeys . CLUSTER_NAME && (
206
- < BulkSelection showPagination = { false } />
207
- ) }
208
- < SortableTableHeaderCell
209
- key = { cellName }
210
- title = { ClusterMapListSortableTitle [ cellName ] }
211
- isSorted = { sortBy === cellKey }
212
- sortOrder = { sortOrder }
213
- isSortable
214
- disabled = { false }
215
- triggerSorting = { handleCellSorting ( cellKey ) }
216
- />
217
- </ >
218
- ) ) }
219
- </ div >
220
- { filteredList . map ( ( clusterData , index ) => (
221
- < ClusterListRow clusterData = { clusterData } index = { index } clusterListLoader = { clusterListLoader } />
222
- ) ) }
223
- </ div >
184
+ < ClusterList
185
+ filteredList = { filteredList }
186
+ clusterListLoader = { clusterListLoader }
187
+ setSelectedClusterName = { setSelectedClusterName }
188
+ showKubeConfigModal = { showKubeConfigModal }
189
+ onChangeShowKubeConfigModal = { onChangeShowKubeConfigModal }
190
+ />
224
191
) }
225
192
</ div >
226
193
)
@@ -232,6 +199,7 @@ const ClusterSelectionList: React.FC<ClusterSelectionType> = ({
232
199
parentRef = { parentRef }
233
200
count = { isBulkSelectionApplied ? clusterOptions ?. length ?? 0 : getSelectedIdentifiersCount ( ) }
234
201
handleClearBulkSelection = { handleClearBulkSelection }
202
+ onChangeShowKubeConfigModal = { onChangeShowKubeConfigModal }
235
203
/>
236
204
)
237
205
}
@@ -241,7 +209,14 @@ const ClusterSelectionList: React.FC<ClusterSelectionType> = ({
241
209
return (
242
210
< div ref = { parentRef } className = "flexbox-col flex-grow-1" >
243
211
{ renderClusterBulkSelection ( ) }
244
- { renderClusterListContent ( ) }
212
+ { renderClusterList ( ) }
213
+ { showKubeConfigModal && KubeConfigModal && (
214
+ < KubeConfigModal
215
+ clusterName = { selectedClusterName || getSelectedIdentifiersCount ( ) === 0 }
216
+ handleModalClose = { onChangeCloseKubeConfigModal }
217
+ isSingleClusterButton = { ! ! selectedClusterName }
218
+ />
219
+ ) }
245
220
</ div >
246
221
)
247
222
}
@@ -257,10 +232,12 @@ const BaseClusterList = (props: ClusterSelectionType) => {
257
232
[ clusterOptions ] ,
258
233
)
259
234
235
+ const getSelectAllDialogStatus = ( ) => SelectAllDialogStatus . CLOSED
236
+
260
237
return (
261
238
< BulkSelectionProvider < BulkSelectionIdentifiersType < ClusterDetail > >
262
239
identifiers = { allOnThisPageIdentifiers }
263
- getSelectAllDialogStatus = { ( ) => SelectAllDialogStatus . CLOSED }
240
+ getSelectAllDialogStatus = { getSelectAllDialogStatus }
264
241
>
265
242
< ClusterSelectionList { ...props } />
266
243
</ BulkSelectionProvider >
0 commit comments