Skip to content

Commit d87d9a0

Browse files
authored
Merge pull request #3058 from devtron-labs/fix/duplicate-resource-list
feat: duplicate resource list
2 parents f759f16 + 198d2c5 commit d87d9a0

File tree

3 files changed

+34
-28
lines changed

3 files changed

+34
-28
lines changed

src/components/ClusterNodes/ClusterList/ClusterList.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ const ClusterList = ({
6767
</div>
6868
{filteredList.map((clusterData) => (
6969
<ClusterListRow
70-
key={clusterData.id ?? clusterData.installationId}
70+
key={`${clusterData.name}-${clusterData.id ?? clusterData.installationId}`}
7171
clusterData={clusterData}
7272
clusterListLoader={clusterListLoader}
7373
showKubeConfigModal={showKubeConfigModal}

src/components/ClusterNodes/ClusterList/ClusterListRow.tsx

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17+
import { useMemo } from 'react'
1718
import { generatePath, Link } from 'react-router-dom'
1819

1920
import {
@@ -51,35 +52,29 @@ const ClusterListRow = ({
5152
onChangeShowKubeConfigModal,
5253
setSelectedClusterName,
5354
}: ClusterListRowTypes) => {
54-
const { selectedIdentifiers: bulkSelectionState, getSelectedIdentifiersCount } =
55+
const { selectedIdentifiers, getSelectedIdentifiersCount } =
5556
useBulkSelection<BulkSelectionIdentifiersType<ClusterDetail>>()
56-
const errorCount = clusterData.nodeErrors ? Object.keys(clusterData.nodeErrors).length : 0
5757
const identifierCount = getSelectedIdentifiersCount()
58+
const isIdentifierSelected = Boolean(selectedIdentifiers[clusterData.name])
5859

59-
const hideDataOnLoad = (value) => {
60-
if (clusterListLoader) {
61-
return null
62-
}
63-
return value
64-
}
65-
66-
const renderClusterStatus = ({ errorInNodeListing, status }: ClusterDetail) => {
67-
if (!status) {
68-
return null
69-
}
70-
71-
return <ClusterStatus status={status} errorInNodeListing={errorInNodeListing} />
72-
}
73-
74-
const isIdentifierSelected = !!bulkSelectionState[clusterData.name]
60+
const errorCount = useMemo(
61+
() => (clusterData.nodeErrors ? Object.keys(clusterData.nodeErrors).length : 0),
62+
[clusterData.nodeErrors],
63+
)
7564

76-
const isClusterInCreationPhase = !!clusterData.installationId && !clusterData.id
65+
const isClusterInCreationPhase = Boolean(clusterData.installationId && !clusterData.id)
7766

78-
const clusterLinkURL = getClusterChangeRedirectionUrl(
79-
isClusterInCreationPhase,
80-
String(isClusterInCreationPhase ? clusterData.installationId : clusterData.id),
67+
const clusterLinkURL = useMemo(
68+
() =>
69+
getClusterChangeRedirectionUrl(
70+
isClusterInCreationPhase,
71+
String(isClusterInCreationPhase ? clusterData.installationId : clusterData.id),
72+
),
73+
[isClusterInCreationPhase, clusterData.installationId, clusterData.id],
8174
)
8275

76+
const hideDataOnLoad = (value) => (clusterListLoader ? null : value)
77+
8378
const wrapWithLinkForClusterName = (children) => (
8479
<Link className="dc__ellipsis-right dc__no-decor" to={clusterLinkURL}>
8580
{children}
@@ -88,9 +83,8 @@ const ClusterListRow = ({
8883

8984
return (
9085
<div
91-
key={`cluster-${clusterData.id}`}
9286
className={`cluster-list-row fw-4 cn-9 fs-13 dc__border-bottom-n1 py-12 px-20 hover-class dc__visible-hover dc__visible-hover--parent
93-
${clusterListLoader ? 'show-shimmer-loading dc__align-items-center' : ''}`}
87+
${clusterListLoader ? 'show-shimmer-loading dc__align-items-center' : ''}`}
9488
>
9589
{KubeConfigRowCheckbox && <KubeConfigRowCheckbox clusterData={clusterData} />}
9690
{!isIdentifierSelected && identifierCount === 0 && (
@@ -125,9 +119,11 @@ const ClusterListRow = ({
125119
}}
126120
/>
127121
)}
122+
128123
{CompareClusterButton && clusterData.status !== ClusterStatusType.CONNECTION_FAILED && (
129124
<CompareClusterButton sourceClusterId={clusterData.id} isIconButton />
130125
)}
126+
131127
{KubeConfigButton && (
132128
<KubeConfigButton
133129
onChangeShowKubeConfigModal={onChangeShowKubeConfigModal}
@@ -139,8 +135,18 @@ const ClusterListRow = ({
139135
</div>
140136
)}
141137
</div>
142-
<div className="child-shimmer-loading">{hideDataOnLoad(renderClusterStatus(clusterData))}</div>
143-
{}
138+
139+
<div className="child-shimmer-loading">
140+
{hideDataOnLoad(
141+
clusterData.status && (
142+
<ClusterStatus
143+
status={clusterData.status}
144+
errorInNodeListing={clusterData.errorInNodeListing}
145+
/>
146+
),
147+
)}
148+
</div>
149+
144150
<div className="child-shimmer-loading">
145151
{hideDataOnLoad(clusterData.isProd ? CLUSTER_PROD_TYPE.PRODUCTION : CLUSTER_PROD_TYPE.NON_PRODUCTION)}
146152
</div>

src/components/ClusterNodes/ClusterList/ClusterListView.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ const ClusterListView = (props: ClusterViewType) => {
7474

7575
return (!searchKey || option.name.toLowerCase().includes(loweredSearchKey)) && filterCondition
7676
})
77-
}, [searchKey, clusterOptions, `${clusterFilter}`, sortBy, sortOrder])
77+
}, [searchKey, clusterOptions, clusterFilter, sortBy, sortOrder])
7878

7979
const handleFilterKeyPress = (value: string) => {
8080
handleSearch(value)

0 commit comments

Comments
 (0)