Skip to content

Commit 88b0471

Browse files
committed
chore: checkboc logic moved to fe lib
1 parent 12a95ca commit 88b0471

File tree

3 files changed

+25
-61
lines changed

3 files changed

+25
-61
lines changed

src/components/ClusterNodes/ClusterList/ClusterList.tsx

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,15 @@ import {
77
useUrlFilters,
88
} from '@devtron-labs/devtron-fe-common-lib'
99

10+
import { importComponentFromFELibrary } from '@Components/common'
11+
1012
import { ClusterMapListSortableKeys, ClusterMapListSortableTitle } from '../constants'
1113
import { parseSearchParams } from '../utils'
1214
import ClusterListRow from './ClusterListRow'
1315
import { ClusterListTypes } from './types'
1416

17+
const KubeConfigRowCheckbox = importComponentFromFELibrary('KubeConfigRowCheckbox', null, 'function')
18+
1519
const ClusterList = ({
1620
filteredList,
1721
clusterListLoader,
@@ -36,7 +40,7 @@ const ClusterList = ({
3640
<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">
3741
{Object.entries(ClusterMapListSortableKeys).map(([cellName, cellKey]) => (
3842
<React.Fragment key={cellName}>
39-
{cellKey === ClusterMapListSortableKeys.CLUSTER_NAME && (
43+
{KubeConfigRowCheckbox && cellKey === ClusterMapListSortableKeys.CLUSTER_NAME && (
4044
<BulkSelection showPagination={false} />
4145
)}
4246
<SortableTableHeaderCell
@@ -52,15 +56,14 @@ const ClusterList = ({
5256
))}
5357
</div>
5458
{filteredList.map((clusterData) => (
55-
<React.Fragment key={clusterData.id}>
56-
<ClusterListRow
57-
clusterData={clusterData}
58-
clusterListLoader={clusterListLoader}
59-
showKubeConfigModal={showKubeConfigModal}
60-
onChangeShowKubeConfigModal={onChangeShowKubeConfigModal}
61-
setSelectedClusterName={setSelectedClusterName}
62-
/>
63-
</React.Fragment>
59+
<ClusterListRow
60+
key={clusterData.id}
61+
clusterData={clusterData}
62+
clusterListLoader={clusterListLoader}
63+
showKubeConfigModal={showKubeConfigModal}
64+
onChangeShowKubeConfigModal={onChangeShowKubeConfigModal}
65+
setSelectedClusterName={setSelectedClusterName}
66+
/>
6467
))}
6568
</div>
6669
)

src/components/ClusterNodes/ClusterList/ClusterListRow.tsx

Lines changed: 6 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,11 @@ import { Link } from 'react-router-dom'
22

33
import {
44
ALL_NAMESPACE_OPTION,
5-
BulkSelectionEvents,
65
BulkSelectionIdentifiersType,
76
Button,
87
ButtonComponentType,
98
ButtonStyleType,
109
ButtonVariantType,
11-
Checkbox,
12-
CHECKBOX_VALUE,
1310
ClusterDetail,
1411
ClusterStatusType,
1512
ComponentSizeType,
@@ -31,42 +28,18 @@ import { ClusterListRowTypes } from './types'
3128
const CompareClusterButton = importComponentFromFELibrary('CompareClusterButton', null, 'function')
3229
const ClusterStatusCell = importComponentFromFELibrary('ClusterStatus', null, 'function')
3330
const KubeConfigButton = importComponentFromFELibrary('KubeConfigButton', null, 'function')
31+
const KubeConfigRowCheckbox = importComponentFromFELibrary('KubeConfigRowCheckbox', null, 'function')
3432

3533
const ClusterListRow = ({
3634
clusterData,
3735
clusterListLoader,
3836
onChangeShowKubeConfigModal,
3937
setSelectedClusterName,
4038
}: ClusterListRowTypes) => {
41-
const {
42-
selectedIdentifiers: bulkSelectionState,
43-
handleBulkSelection,
44-
getSelectedIdentifiersCount,
45-
} = useBulkSelection<BulkSelectionIdentifiersType<ClusterDetail>>()
39+
const { selectedIdentifiers: bulkSelectionState, getSelectedIdentifiersCount } =
40+
useBulkSelection<BulkSelectionIdentifiersType<ClusterDetail>>()
4641
const errorCount = clusterData.nodeErrors ? Object.keys(clusterData.nodeErrors).length : 0
47-
48-
const handleSelection = () => {
49-
const { name } = clusterData
50-
if (bulkSelectionState[name]) {
51-
handleBulkSelection({
52-
action: BulkSelectionEvents.CLEAR_IDENTIFIERS,
53-
data: {
54-
identifierIds: [name],
55-
},
56-
})
57-
} else {
58-
handleBulkSelection({
59-
action: BulkSelectionEvents.SELECT_IDENTIFIER,
60-
data: {
61-
identifierObject: {
62-
...bulkSelectionState,
63-
[name]: clusterData,
64-
},
65-
},
66-
})
67-
}
68-
setSelectedClusterName('')
69-
}
42+
const identifierCount = getSelectedIdentifiersCount()
7043

7144
const hideDataOnLoad = (value) => {
7245
if (clusterListLoader) {
@@ -92,22 +65,8 @@ const ClusterListRow = ({
9265
className={`cluster-list-row fw-4 cn-9 fs-13 dc__border-bottom-n1 pt-12 pb-12 pr-20 pl-20 hover-class dc__visible-hover dc__visible-hover--parent
9366
${clusterListLoader ? 'show-shimmer-loading dc__align-items-center' : ''}`}
9467
>
95-
<div
96-
className={
97-
isIdentifierSelected || getSelectedIdentifiersCount() > 0
98-
? 'dc__visible'
99-
: 'dc__visible-hover--child flex left'
100-
}
101-
>
102-
<Checkbox
103-
isChecked={isIdentifierSelected}
104-
onChange={handleSelection}
105-
rootClassName="icon-dim-20 m-0"
106-
dataTestId={`activate-${clusterData.name}`}
107-
value={CHECKBOX_VALUE.CHECKED}
108-
/>
109-
</div>
110-
{!isIdentifierSelected && getSelectedIdentifiersCount() === 0 && (
68+
{KubeConfigRowCheckbox && <KubeConfigRowCheckbox clusterData={clusterData} />}
69+
{!isIdentifierSelected && identifierCount === 0 && (
11170
<div className="dc__visible-hover--hide-child flex left">
11271
<Icon name="ic-bg-cluster" color={null} size={24} />
11372
</div>

src/components/ClusterNodes/ClusterList/ClusterSelectionBody.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,11 @@ const ClusterSelectionBody: React.FC<ClusterSelectionBodyTypes> = ({
6565
initialSortKey: ClusterMapListSortableKeys.CLUSTER_NAME,
6666
})
6767

68-
const { handleBulkSelection, isBulkSelectionApplied, getSelectedIdentifiersCount } =
68+
const { handleBulkSelection, getSelectedIdentifiersCount } =
6969
useBulkSelection<BulkSelectionIdentifiersType<ClusterDetail>>()
7070

71+
const identifierCount = getSelectedIdentifiersCount()
72+
7173
const handleClearBulkSelection = () => {
7274
handleBulkSelection({
7375
action: BulkSelectionEvents.CLEAR_ALL_SELECTIONS,
@@ -149,11 +151,11 @@ const ClusterSelectionBody: React.FC<ClusterSelectionBodyTypes> = ({
149151
)
150152

151153
const renderClusterBulkSelection = () => {
152-
if (getSelectedIdentifiersCount() > 0 || isBulkSelectionApplied) {
154+
if (identifierCount > 0) {
153155
return (
154156
<ClusterBulkSelectionActionWidget
155157
parentRef={parentRef}
156-
count={isBulkSelectionApplied ? clusterOptions?.length ?? 0 : getSelectedIdentifiersCount()}
158+
count={identifierCount}
157159
handleClearBulkSelection={handleClearBulkSelection}
158160
onChangeShowKubeConfigModal={onChangeShowKubeConfigModal}
159161
/>
@@ -168,7 +170,7 @@ const ClusterSelectionBody: React.FC<ClusterSelectionBodyTypes> = ({
168170
{renderClusterList()}
169171
{showKubeConfigModal && KubeConfigModal && (
170172
<KubeConfigModal
171-
clusterName={selectedClusterName || getSelectedIdentifiersCount() === 0}
173+
clusterName={selectedClusterName || identifierCount === 0}
172174
handleModalClose={onChangeCloseKubeConfigModal}
173175
isSingleClusterButton={!!selectedClusterName}
174176
/>

0 commit comments

Comments
 (0)