Skip to content

Commit 3f51a62

Browse files
jgyselovammont82
andauthored
Prevent multiple clusters being created in day 2 (#2880)
Co-authored-by: Montse Ortega Gallart <ammont82@users.noreply.github.com>
1 parent 690a678 commit 3f51a62

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

libs/ui-lib/lib/ocm/components/HostsClusterDetailTab/HostsClusterDetailTabContent.tsx

+12-9
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ export const HostsClusterDetailTabContent = ({
3333
const [day2Cluster, setDay2Cluster] = useStateSafely<Cluster | null>(null);
3434
const pullSecret = usePullSecret();
3535

36+
// eslint-disable-next-line react-hooks/exhaustive-deps
37+
const ocmClusterMemo = React.useMemo(() => ocmCluster, []);
38+
3639
const handleClickTryAgainLink = React.useCallback(() => {
3740
setError(undefined);
3841
setDay2Cluster(null);
@@ -53,19 +56,20 @@ export const HostsClusterDetailTabContent = ({
5356
setDay2Cluster(null);
5457
return;
5558
}
56-
const day1ClusterHostCount = ocmCluster?.metrics?.nodes?.total || 0;
57-
const openshiftClusterId = Day2ClusterService.getOpenshiftClusterId(ocmCluster);
59+
60+
const day1ClusterHostCount = ocmClusterMemo?.metrics?.nodes?.total || 0;
61+
const openshiftClusterId = Day2ClusterService.getOpenshiftClusterId(ocmClusterMemo);
5862
if (day1ClusterHostCount === 0 || !openshiftClusterId) {
5963
setError(<UnableToAddHostsError onTryAgain={handleClickTryAgainLink} />);
6064
}
6165

6266
if (!day2Cluster && pullSecret) {
63-
const { apiVipDnsname, errorType } = getApiVipDnsName(ocmCluster);
67+
const { apiVipDnsname, errorType } = getApiVipDnsName(ocmClusterMemo);
6468
if (errorType) {
6569
const wrongUrlMessage =
6670
errorType === 'console'
67-
? `Cluster Console URL is not valid (${ocmCluster.console?.url || ''})`
68-
: `Cluster API URL is not valid (${ocmCluster.api?.url || ''})`;
71+
? `Cluster Console URL is not valid (${ocmClusterMemo.console?.url || ''})`
72+
: `Cluster API URL is not valid (${ocmClusterMemo.api?.url || ''})`;
6973
setError(
7074
<>
7175
{wrongUrlMessage}, you can{' '}
@@ -85,11 +89,11 @@ export const HostsClusterDetailTabContent = ({
8589

8690
const loadDay2Cluster = async () => {
8791
try {
88-
const day2Cluster = await Day2ClusterService.fetchCluster(ocmCluster, pullSecret);
92+
const day2Cluster = await Day2ClusterService.fetchCluster(ocmClusterMemo, pullSecret);
8993

9094
const aiCluster = Day2ClusterService.completeAiClusterWithOcmCluster(
9195
day2Cluster,
92-
ocmCluster,
96+
ocmClusterMemo,
9397
);
9498
setDay2Cluster(aiCluster ?? null);
9599
} catch (e) {
@@ -103,13 +107,12 @@ export const HostsClusterDetailTabContent = ({
103107
/>,
104108
);
105109
}
106-
return;
107110
}
108111
};
109112

110113
void loadDay2Cluster();
111114
}
112-
}, [ocmCluster, pullSecret, day2Cluster, setDay2Cluster, isVisible, handleClickTryAgainLink]);
115+
}, [pullSecret, day2Cluster, setDay2Cluster, isVisible, handleClickTryAgainLink, ocmClusterMemo]);
113116

114117
const refreshCluster = React.useCallback(async () => {
115118
if (!day2Cluster?.id) {

0 commit comments

Comments
 (0)