1
- import { useMemo } from 'react'
1
+ import { useMemo , useState } from 'react'
2
+ import dayjs , { Dayjs } from 'dayjs'
2
3
3
4
import {
5
+ BulkSelectionEvents ,
4
6
BulkSelectionIdentifiersType ,
5
7
BulkSelectionProvider ,
6
8
ClusterDetail ,
7
9
ClusterFiltersType ,
8
10
SearchBar ,
9
11
SelectAllDialogStatus ,
12
+ useBulkSelection ,
10
13
useUrlFilters ,
11
14
} from '@devtron-labs/devtron-fe-common-lib'
12
15
13
16
import { importComponentFromFELibrary } from '@Components/common'
17
+ import Timer from '@Components/common/DynamicTabs/DynamicTabs.timer'
14
18
15
19
import { ClusterMapListSortableKeys , ClusterStatusByFilter } from '../constants'
16
20
import { getSortedClusterList , parseSearchParams } from '../utils'
@@ -22,14 +26,18 @@ const ClusterFilters = importComponentFromFELibrary('ClusterFilters', null, 'fun
22
26
const getSelectAllDialogStatus = ( ) => SelectAllDialogStatus . CLOSED
23
27
24
28
const ClusterListView = ( props : ClusterViewType ) => {
29
+ const [ lastSyncTime , setLastSyncTime ] = useState < Dayjs > ( dayjs ( ) )
30
+
25
31
const { searchKey, clusterFilter, updateSearchParams, handleSearch, sortBy, sortOrder } = useUrlFilters <
26
32
ClusterMapListSortableKeys ,
27
33
{ clusterFilter : ClusterFiltersType }
28
34
> ( {
29
35
parseSearchParams,
30
36
initialSortKey : ClusterMapListSortableKeys . CLUSTER_NAME ,
31
37
} )
32
- const { clusterOptions, initialLoading } = props
38
+ const { handleBulkSelection } = useBulkSelection < BulkSelectionIdentifiersType < ClusterDetail > > ( )
39
+
40
+ const { clusterOptions, initialLoading, clusterListLoader, refreshData } = props
33
41
34
42
const setClusterFilter = ( _clusterFilter : ClusterFiltersType ) => {
35
43
updateSearchParams ( { clusterFilter : _clusterFilter } )
@@ -65,24 +73,60 @@ const ClusterListView = (props: ClusterViewType) => {
65
73
[ clusterOptions ] ,
66
74
)
67
75
76
+ const handleClearBulkSelection = ( ) => {
77
+ handleBulkSelection ( {
78
+ action : BulkSelectionEvents . CLEAR_ALL_SELECTIONS ,
79
+ } )
80
+ }
81
+
82
+ const handleRefresh = ( ) => {
83
+ refreshData ( )
84
+ setLastSyncTime ( dayjs ( ) )
85
+ handleClearBulkSelection ( )
86
+ }
87
+
68
88
return (
69
89
< BulkSelectionProvider < BulkSelectionIdentifiersType < ClusterDetail > >
70
90
identifiers = { allOnThisPageIdentifiers }
71
91
getSelectAllDialogStatus = { getSelectAllDialogStatus }
72
92
>
73
- < div className = "flex dc__gap-12 dc__content-space" >
74
- < SearchBar
75
- initialSearchText = { searchKey }
76
- handleEnter = { handleFilterKeyPress }
77
- containerClassName = "w-250-imp"
78
- inputProps = { {
79
- placeholder : 'Search clusters' ,
80
- autoFocus : true ,
81
- disabled : initialLoading ,
82
- } }
83
- />
84
- { ClusterFilters && < ClusterFilters clusterFilter = { clusterFilter } setClusterFilter = { setClusterFilter } /> }
93
+ < div className = "flexbox dc__content-space pl-20 pr-20 pt-16 pb-16 dc__zi-4" >
94
+ < div className = "flex dc__gap-12" >
95
+ < SearchBar
96
+ initialSearchText = { searchKey }
97
+ handleEnter = { handleFilterKeyPress }
98
+ containerClassName = "w-250-imp"
99
+ inputProps = { {
100
+ placeholder : 'Search clusters' ,
101
+ autoFocus : true ,
102
+ disabled : initialLoading ,
103
+ } }
104
+ />
105
+ { ClusterFilters && (
106
+ < ClusterFilters clusterFilter = { clusterFilter } setClusterFilter = { setClusterFilter } />
107
+ ) }
108
+ </ div >
109
+ { clusterListLoader ? (
110
+ < span className = "dc__loading-dots mr-20" > Syncing</ span >
111
+ ) : (
112
+ < div className = "flex left" >
113
+ < span >
114
+ Last refreshed
115
+ < Timer start = { lastSyncTime } />
116
+ ago
117
+ </ span >
118
+ < button
119
+ type = "button"
120
+ data-testid = "cluster-list-refresh-button"
121
+ className = "btn btn-link p-0 fw-6 cb-5 ml-5 fs-13"
122
+ onClick = { handleRefresh }
123
+ >
124
+ Refresh
125
+ </ button >
126
+ </ div >
127
+ ) }
85
128
</ div >
129
+
86
130
< ClusterSelectionBody { ...props } filteredList = { filteredList } />
87
131
</ BulkSelectionProvider >
88
132
)
0 commit comments