14
14
* limitations under the License.
15
15
*/
16
16
17
- import React , { useMemo , useRef , useState } from 'react'
17
+ import React , { useRef , useState } from 'react'
18
18
import dayjs , { Dayjs } from 'dayjs'
19
19
20
20
import {
21
21
BulkSelectionEvents ,
22
22
BulkSelectionIdentifiersType ,
23
- BulkSelectionProvider ,
24
23
ClusterDetail ,
25
24
ClusterFiltersType ,
26
25
GenericEmptyState ,
27
- SearchBar ,
28
- SelectAllDialogStatus ,
29
26
useBulkSelection ,
30
27
useUrlFilters ,
31
28
} from '@devtron-labs/devtron-fe-common-lib'
@@ -35,65 +32,42 @@ import { importComponentFromFELibrary } from '@Components/common'
35
32
import Timer from '@Components/common/DynamicTabs/DynamicTabs.timer'
36
33
import { AddClusterButton } from '@Components/ResourceBrowser/PageHeader.buttons'
37
34
38
- import { ClusterSelectionType } from '../ResourceBrowser/Types '
39
- import { ClusterList } from './ClusterList '
40
- import ClusterNodeEmptyState from './ClusterNodeEmptyStates '
41
- import { ClusterMapListSortableKeys , ClusterStatusByFilter } from './constants '
42
- import { getSortedClusterList , parseSearchParams } from './utils '
35
+ import ClusterNodeEmptyState from '../ClusterNodeEmptyStates '
36
+ import { ClusterMapListSortableKeys } from '../constants '
37
+ import { parseSearchParams } from '../utils '
38
+ import ClusterList from './ClusterList '
39
+ import { ClusterSelectionBodyTypes } from './types '
43
40
44
- import './clusterNodes.scss'
41
+ import '.. /clusterNodes.scss'
45
42
46
43
const ClusterMap = importComponentFromFELibrary ( 'ClusterMap' , null , 'function' )
47
- const ClusterFilters = importComponentFromFELibrary ( 'ClusterFilters' , null , 'function' )
48
44
const ClusterBulkSelectionActionWidget = importComponentFromFELibrary (
49
45
'ClusterBulkSelectionActionWidget' ,
50
46
null ,
51
47
'function' ,
52
48
)
53
49
const KubeConfigModal = importComponentFromFELibrary ( 'KubeConfigModal' , null , 'function' )
54
50
55
- const ClusterSelectionList : React . FC < ClusterSelectionType > = ( {
51
+ const ClusterSelectionBody : React . FC < ClusterSelectionBodyTypes > = ( {
56
52
clusterOptions,
57
53
clusterListLoader,
58
- initialLoading,
59
54
refreshData,
55
+ filteredList,
60
56
} ) => {
61
57
const parentRef = useRef < HTMLDivElement > ( null )
62
58
63
59
const [ lastSyncTime , setLastSyncTime ] = useState < Dayjs > ( dayjs ( ) )
64
60
const [ showKubeConfigModal , setKubeConfigModal ] = useState ( false )
65
61
const [ selectedClusterName , setSelectedClusterName ] = useState ( '' )
66
62
67
- const { searchKey, clusterFilter, updateSearchParams, handleSearch, clearFilters, sortBy, sortOrder } =
68
- useUrlFilters < ClusterMapListSortableKeys , { clusterFilter : ClusterFiltersType } > ( {
69
- parseSearchParams,
70
- initialSortKey : ClusterMapListSortableKeys . CLUSTER_NAME ,
71
- } )
63
+ const { clearFilters } = useUrlFilters < ClusterMapListSortableKeys , { clusterFilter : ClusterFiltersType } > ( {
64
+ parseSearchParams,
65
+ initialSortKey : ClusterMapListSortableKeys . CLUSTER_NAME ,
66
+ } )
72
67
73
68
const { handleBulkSelection, isBulkSelectionApplied, getSelectedIdentifiersCount } =
74
69
useBulkSelection < BulkSelectionIdentifiersType < ClusterDetail > > ( )
75
70
76
- const filteredList : ClusterDetail [ ] = useMemo ( ( ) => {
77
- const loweredSearchKey = searchKey . toLowerCase ( )
78
- const updatedClusterOptions = [ ...clusterOptions ]
79
- // Sort the cluster list based on the selected sorting key
80
- getSortedClusterList ( updatedClusterOptions , sortBy , sortOrder )
81
-
82
- // Filter the cluster list based on the search key and cluster filter
83
- return updatedClusterOptions . filter ( ( option ) => {
84
- const filterCondition =
85
- clusterFilter === ClusterFiltersType . ALL_CLUSTERS ||
86
- ! option . status ||
87
- option . status === ClusterStatusByFilter [ clusterFilter ]
88
-
89
- return ( ! searchKey || option . name . toLowerCase ( ) . includes ( loweredSearchKey ) ) && filterCondition
90
- } )
91
- } , [ searchKey , clusterOptions , `${ clusterFilter } ` , sortBy , sortOrder ] )
92
-
93
- const handleFilterKeyPress = ( value : string ) => {
94
- handleSearch ( value )
95
- }
96
-
97
71
const handleClearBulkSelection = ( ) => {
98
72
handleBulkSelection ( {
99
73
action : BulkSelectionEvents . CLEAR_ALL_SELECTIONS ,
@@ -106,10 +80,6 @@ const ClusterSelectionList: React.FC<ClusterSelectionType> = ({
106
80
handleClearBulkSelection ( )
107
81
}
108
82
109
- const setClusterFilter = ( _clusterFilter : ClusterFiltersType ) => {
110
- updateSearchParams ( { clusterFilter : _clusterFilter } )
111
- }
112
-
113
83
if ( ! clusterOptions . length ) {
114
84
return (
115
85
< GenericEmptyState
@@ -132,21 +102,6 @@ const ClusterSelectionList: React.FC<ClusterSelectionType> = ({
132
102
const renderClusterList = ( ) => (
133
103
< div className = "cluster-list-main-container flex-grow-1 flexbox-col bg__primary dc__overflow-auto" >
134
104
< div className = "flexbox dc__content-space pl-20 pr-20 pt-16 pb-16 dc__zi-4" >
135
- < div className = "flex dc__gap-12" >
136
- < SearchBar
137
- initialSearchText = { searchKey }
138
- handleEnter = { handleFilterKeyPress }
139
- containerClassName = "w-250-imp"
140
- inputProps = { {
141
- placeholder : 'Search clusters' ,
142
- autoFocus : true ,
143
- disabled : initialLoading ,
144
- } }
145
- />
146
- { ClusterFilters && (
147
- < ClusterFilters clusterFilter = { clusterFilter } setClusterFilter = { setClusterFilter } />
148
- ) }
149
- </ div >
150
105
< div className = "fs-13 flex" >
151
106
{ clusterListLoader ? (
152
107
< span className = "dc__loading-dots mr-20" > Syncing</ span >
@@ -177,7 +132,7 @@ const ClusterSelectionList: React.FC<ClusterSelectionType> = ({
177
132
isProportional
178
133
/>
179
134
) }
180
- { ! filteredList . length ? (
135
+ { ! filteredList ? .length ? (
181
136
< div className = "flex-grow-1" >
182
137
< ClusterNodeEmptyState actionHandler = { clearFilters } />
183
138
</ div >
@@ -222,27 +177,4 @@ const ClusterSelectionList: React.FC<ClusterSelectionType> = ({
222
177
)
223
178
}
224
179
225
- const BaseClusterList = ( props : ClusterSelectionType ) => {
226
- const { clusterOptions } = props
227
- const allOnThisPageIdentifiers = useMemo (
228
- ( ) =>
229
- clusterOptions ?. reduce ( ( acc , cluster ) => {
230
- acc [ cluster . name ] = cluster
231
- return acc
232
- } , { } as ClusterDetail ) ?? { } ,
233
- [ clusterOptions ] ,
234
- )
235
-
236
- const getSelectAllDialogStatus = ( ) => SelectAllDialogStatus . CLOSED
237
-
238
- return (
239
- < BulkSelectionProvider < BulkSelectionIdentifiersType < ClusterDetail > >
240
- identifiers = { allOnThisPageIdentifiers }
241
- getSelectAllDialogStatus = { getSelectAllDialogStatus }
242
- >
243
- < ClusterSelectionList { ...props } />
244
- </ BulkSelectionProvider >
245
- )
246
- }
247
-
248
- export default BaseClusterList
180
+ export default ClusterSelectionBody
0 commit comments