Skip to content

Commit 5203285

Browse files
committed
Disable Nutanix platform integration
Signed-off-by: Elay Aharoni <elayaha@gmail.com>
1 parent 2aca314 commit 5203285

File tree

1 file changed

+67
-30
lines changed

1 file changed

+67
-30
lines changed

libs/ui-lib/lib/ocm/components/clusterConfiguration/platformIntegration/ExternalPlatformDropdown.tsx

+67-30
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ import {
2020
import { ExternalPlaformIds, ExternalPlatformLabels, ExternalPlatformLinks } from './constants';
2121
import { PlatformType, SupportLevel } from '@openshift-assisted/types/assisted-installer-service';
2222
import {
23-
NewFeatureSupportLevelData,
2423
NewFeatureSupportLevelMap,
2524
useNewFeatureSupportLevel,
2625
} from '../../../../common/components/newFeatureSupportLevels';
2726
import NewFeatureSupportLevelBadge from '../../../../common/components/newFeatureSupportLevels/NewFeatureSupportLevelBadge';
27+
import { useFeature } from '../../../hooks/use-feature';
2828

2929
const INPUT_NAME = 'platform';
3030
const fieldId = getFieldId(INPUT_NAME, 'input');
@@ -45,7 +45,12 @@ export type ExternalPlatformInfo = {
4545

4646
const getDisabledReasonForExternalPlatform = (
4747
isSNO: boolean,
48-
newFeatureSupportLevelContext: NewFeatureSupportLevelData,
48+
getFeatureDisabledReason: (
49+
featureId: FeatureId,
50+
supportLevelData?: NewFeatureSupportLevelMap,
51+
cpuArchitecture?: SupportedCpuArchitecture,
52+
platformType?: PlatformType,
53+
) => string | undefined,
4954
platform: PlatformType,
5055
featureSupportLevelData?: NewFeatureSupportLevelMap | null,
5156
cpuArchitecture?: SupportedCpuArchitecture,
@@ -58,43 +63,63 @@ const getDisabledReasonForExternalPlatform = (
5863
) {
5964
return `Plaform integration is not supported for Single-Node OpenShift with the selected CPU architecture.`;
6065
} else {
61-
return newFeatureSupportLevelContext.getFeatureDisabledReason(
66+
return getFeatureDisabledReason(
6267
ExternalPlaformIds[platform] as FeatureId,
6368
featureSupportLevelData ?? undefined,
6469
cpuArchitecture,
6570
);
6671
}
6772
};
6873

74+
const isAvailablePlatform = (platform: PlatformType) => (isDisconnected?: boolean) => {
75+
if (isDisconnected && platform === 'nutanix') {
76+
return false;
77+
}
78+
return platform !== undefined;
79+
};
80+
6981
const getExternalPlatformTypes = (
7082
isSNO: boolean,
71-
newFeatureSupportLevelContext: NewFeatureSupportLevelData,
83+
getFeatureSupportLevel: (
84+
featureId: FeatureId,
85+
supportLevelData?: NewFeatureSupportLevelMap,
86+
) => SupportLevel | undefined,
87+
getFeatureDisabledReason: (
88+
featureId: FeatureId,
89+
supportLevelData?: NewFeatureSupportLevelMap,
90+
cpuArchitecture?: SupportedCpuArchitecture,
91+
platformType?: PlatformType,
92+
) => string | undefined,
7293
featureSupportLevelData?: NewFeatureSupportLevelMap | null,
7394
cpuArchitecture?: SupportedCpuArchitecture,
95+
isDisconnected?: boolean,
7496
): Partial<{ [key in PlatformType]: ExternalPlatformInfo }> => {
7597
const platforms = ['none', 'nutanix', 'external', 'vsphere'] as PlatformType[];
7698

77-
return platforms.filter(Boolean).reduce(
78-
(a, platform) => ({
79-
...a,
80-
[platform]: {
81-
label: ExternalPlatformLabels[platform],
82-
href: ExternalPlatformLinks[platform],
83-
disabledReason: getDisabledReasonForExternalPlatform(
84-
isSNO,
85-
newFeatureSupportLevelContext,
86-
platform,
87-
featureSupportLevelData ?? undefined,
88-
cpuArchitecture,
89-
),
90-
supportLevel: newFeatureSupportLevelContext.getFeatureSupportLevel(
91-
ExternalPlaformIds[platform] as FeatureId,
92-
featureSupportLevelData ?? undefined,
93-
),
94-
},
95-
}),
96-
{},
97-
);
99+
const newPlatform = platforms
100+
.filter((platform) => isAvailablePlatform(platform)(isDisconnected))
101+
.reduce(
102+
(a, platform) => ({
103+
...a,
104+
[platform]: {
105+
label: ExternalPlatformLabels[platform],
106+
href: ExternalPlatformLinks[platform],
107+
disabledReason: getDisabledReasonForExternalPlatform(
108+
isSNO,
109+
getFeatureDisabledReason,
110+
platform,
111+
featureSupportLevelData ?? undefined,
112+
cpuArchitecture,
113+
),
114+
supportLevel: getFeatureSupportLevel(
115+
ExternalPlaformIds[platform] as FeatureId,
116+
featureSupportLevelData ?? undefined,
117+
),
118+
},
119+
}),
120+
{},
121+
);
122+
return newPlatform;
98123
};
99124

100125
export const areAllExternalPlatformIntegrationDisabled = (
@@ -124,30 +149,42 @@ export const ExternalPlatformDropdown = ({
124149
const [externalPlatformTypes, setExternalPlatformTypes] = React.useState<
125150
Partial<{ [key in PlatformType]: ExternalPlatformInfo }>
126151
>({});
152+
const isSingleClusterFeatureEnabled = useFeature('ASSISTED_INSTALLER_SINGLE_CLUSTER_FEATURE');
127153

128154
const tooltipDropdownDisabled = getReasonForDropdownDisabled(
129155
isSNO,
130156
cpuArchitecture ? architectureData[cpuArchitecture].label : '',
131157
);
132158

133-
const handleClick = (event: MouseEvent<HTMLButtonElement>, href: string) => {
159+
const handleClick = (event: MouseEvent<HTMLButtonElement>, href: string): void => {
134160
event.stopPropagation(); // Stop event propagation here
135161
window.open(href, '_blank');
136162
};
137-
const newFeatureSupportLevelContext = useNewFeatureSupportLevel();
163+
164+
// eslint-disable-next-line @typescript-eslint/unbound-method
165+
const { getFeatureSupportLevel, getFeatureDisabledReason } = useNewFeatureSupportLevel();
166+
138167
React.useEffect(() => {
139168
// Calculate updated externalPlatformTypes based on the dependencies
140169
const updatedExternalPlatformTypes = getExternalPlatformTypes(
141170
isSNO,
142-
newFeatureSupportLevelContext,
171+
getFeatureSupportLevel,
172+
getFeatureDisabledReason,
143173
featureSupportLevelData,
144174
cpuArchitecture,
175+
isSingleClusterFeatureEnabled,
145176
);
146177

147178
// Update the state with the new externalPlatformTypes
148179
setExternalPlatformTypes(updatedExternalPlatformTypes);
149-
// eslint-disable-next-line react-hooks/exhaustive-deps
150-
}, [featureSupportLevelData, cpuArchitecture, isSNO]);
180+
}, [
181+
featureSupportLevelData,
182+
cpuArchitecture,
183+
isSNO,
184+
isSingleClusterFeatureEnabled,
185+
getFeatureSupportLevel,
186+
getFeatureDisabledReason,
187+
]);
151188

152189
const dropdownIsDisabled = React.useMemo(() => {
153190
return areAllExternalPlatformIntegrationDisabled(externalPlatformTypes);

0 commit comments

Comments
 (0)