Skip to content

Commit 29ef069

Browse files
committed
chore: code refactoring
1 parent a5eb583 commit 29ef069

File tree

2 files changed

+58
-47
lines changed

2 files changed

+58
-47
lines changed

src/components/ClusterNodes/ClusterList/ClusterListView.tsx

Lines changed: 58 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
1-
import { useMemo } from 'react'
1+
import { useMemo, useState } from 'react'
2+
import dayjs, { Dayjs } from 'dayjs'
23

34
import {
5+
BulkSelectionEvents,
46
BulkSelectionIdentifiersType,
57
BulkSelectionProvider,
68
ClusterDetail,
79
ClusterFiltersType,
810
SearchBar,
911
SelectAllDialogStatus,
12+
useBulkSelection,
1013
useUrlFilters,
1114
} from '@devtron-labs/devtron-fe-common-lib'
1215

1316
import { importComponentFromFELibrary } from '@Components/common'
17+
import Timer from '@Components/common/DynamicTabs/DynamicTabs.timer'
1418

1519
import { ClusterMapListSortableKeys, ClusterStatusByFilter } from '../constants'
1620
import { getSortedClusterList, parseSearchParams } from '../utils'
@@ -22,14 +26,18 @@ const ClusterFilters = importComponentFromFELibrary('ClusterFilters', null, 'fun
2226
const getSelectAllDialogStatus = () => SelectAllDialogStatus.CLOSED
2327

2428
const ClusterListView = (props: ClusterViewType) => {
29+
const [lastSyncTime, setLastSyncTime] = useState<Dayjs>(dayjs())
30+
2531
const { searchKey, clusterFilter, updateSearchParams, handleSearch, sortBy, sortOrder } = useUrlFilters<
2632
ClusterMapListSortableKeys,
2733
{ clusterFilter: ClusterFiltersType }
2834
>({
2935
parseSearchParams,
3036
initialSortKey: ClusterMapListSortableKeys.CLUSTER_NAME,
3137
})
32-
const { clusterOptions, initialLoading } = props
38+
const { handleBulkSelection } = useBulkSelection<BulkSelectionIdentifiersType<ClusterDetail>>()
39+
40+
const { clusterOptions, initialLoading, clusterListLoader, refreshData } = props
3341

3442
const setClusterFilter = (_clusterFilter: ClusterFiltersType) => {
3543
updateSearchParams({ clusterFilter: _clusterFilter })
@@ -65,24 +73,60 @@ const ClusterListView = (props: ClusterViewType) => {
6573
[clusterOptions],
6674
)
6775

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+
6888
return (
6989
<BulkSelectionProvider<BulkSelectionIdentifiersType<ClusterDetail>>
7090
identifiers={allOnThisPageIdentifiers}
7191
getSelectAllDialogStatus={getSelectAllDialogStatus}
7292
>
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&nbsp;
115+
<Timer start={lastSyncTime} />
116+
&nbsp;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+
)}
85128
</div>
129+
86130
<ClusterSelectionBody {...props} filteredList={filteredList} />
87131
</BulkSelectionProvider>
88132
)

src/components/ClusterNodes/ClusterList/ClusterSelectionBody.tsx

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616

1717
import React, { useRef, useState } from 'react'
18-
import dayjs, { Dayjs } from 'dayjs'
1918

2019
import {
2120
BulkSelectionEvents,
@@ -29,7 +28,6 @@ import {
2928

3029
import NoClusterEmptyState from '@Images/no-cluster-empty-state.png'
3130
import { importComponentFromFELibrary } from '@Components/common'
32-
import Timer from '@Components/common/DynamicTabs/DynamicTabs.timer'
3331
import { AddClusterButton } from '@Components/ResourceBrowser/PageHeader.buttons'
3432

3533
import ClusterNodeEmptyState from '../ClusterNodeEmptyStates'
@@ -51,12 +49,10 @@ const KubeConfigModal = importComponentFromFELibrary('KubeConfigModal', null, 'f
5149
const ClusterSelectionBody: React.FC<ClusterSelectionBodyTypes> = ({
5250
clusterOptions,
5351
clusterListLoader,
54-
refreshData,
5552
filteredList,
5653
}) => {
5754
const parentRef = useRef<HTMLDivElement>(null)
5855

59-
const [lastSyncTime, setLastSyncTime] = useState<Dayjs>(dayjs())
6056
const [showKubeConfigModal, setShowKubeConfigModal] = useState(false)
6157
const [selectedClusterName, setSelectedClusterName] = useState('')
6258

@@ -76,12 +72,6 @@ const ClusterSelectionBody: React.FC<ClusterSelectionBodyTypes> = ({
7672
})
7773
}
7874

79-
const handleRefresh = () => {
80-
refreshData()
81-
setLastSyncTime(dayjs())
82-
handleClearBulkSelection()
83-
}
84-
8575
if (!clusterOptions.length) {
8676
return (
8777
<GenericEmptyState
@@ -104,29 +94,6 @@ const ClusterSelectionBody: React.FC<ClusterSelectionBodyTypes> = ({
10494

10595
const renderClusterList = () => (
10696
<div className="cluster-list-main-container flex-grow-1 flexbox-col bg__primary dc__overflow-auto">
107-
<div className="flexbox dc__content-space pl-20 pr-20 pt-16 pb-16 dc__zi-4">
108-
<div className="fs-13 flex">
109-
{clusterListLoader ? (
110-
<span className="dc__loading-dots mr-20">Syncing</span>
111-
) : (
112-
<>
113-
<span>
114-
Last refreshed&nbsp;
115-
<Timer start={lastSyncTime} />
116-
&nbsp;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-
</>
127-
)}
128-
</div>
129-
</div>
13097
{ClusterMap && window._env_.FEATURE_CLUSTER_MAP_ENABLE && (
13198
<ClusterMap
13299
isLoading={clusterListLoader}

0 commit comments

Comments
 (0)