Skip to content

Commit

Permalink
Changes in ExternalPlatformDropdown
Browse files Browse the repository at this point in the history
  • Loading branch information
ammont82 committed Jul 28, 2023
1 parent 5efc8b4 commit 10e39ec
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe(`Assisted Installer Read Only Cluster`, () => {
});

describe('Read Only cluster', () => {
it.skip('Should display the Cluster details page in viewer mode', () => {
it('Should display the Cluster details page in viewer mode', () => {
commonActions.visitClusterDetailsPage();
navbar.clickOnNavItem('Cluster details');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,21 @@ export const ExternalPlatformDropdown = ({
onChange,
cpuArchitecture,
externalPlatformIntegrationStateMap,
clusterPlatform,
}: ExternalPlatformDropdownProps) => {
const [field, { value }, { setValue }] = useField<string>(INPUT_NAME);
const [field, , { setValue }] = useField<string>(INPUT_NAME);
const [isOpen, setOpen] = React.useState(false);

const defaultValue = React.useMemo(() => {
if (clusterPlatform !== undefined) {
const platform = clusterPlatform === 'baremetal' ? 'none' : clusterPlatform;
return platform;
} else {
return 'none';
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [clusterPlatform]);
const [current, setCurrent] = React.useState<string>(defaultValue);
const tooltipDropdownDisabled = `Platform integration is not supported when ${
cpuArchitecture || ''
} is selected`;
Expand All @@ -97,6 +108,20 @@ export const ExternalPlatformDropdown = ({
externalPlatformIntegrationStateMap,
);

React.useEffect(() => {
let isCurrentValueDisabled = false;

if (current !== 'none') {
isCurrentValueDisabled =
externalPlatformIntegrationStateMap[
externalPlatformTypes[current as ExternalPlatformType].featureId as FeatureIdPlatform
].isDisabled;
}
if (dropdownIsDisabled || isCurrentValueDisabled) {
setCurrent('none');
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [dropdownIsDisabled, current, externalPlatformIntegrationStateMap]);
const enabledItems = Object.keys(externalPlatformTypes)
.filter((platformType) => {
if (platformType === 'oci') {
Expand Down Expand Up @@ -139,11 +164,11 @@ export const ExternalPlatformDropdown = ({
</DropdownItem>
);
});

const onSelect = React.useCallback(
(event?: React.SyntheticEvent<HTMLDivElement>) => {
const selectedPlatform = event?.currentTarget.id as ExternalPlatformType;
setValue(selectedPlatform);
setCurrent(selectedPlatform);
setOpen(false);
onChange(selectedPlatform);
},
Expand All @@ -159,10 +184,10 @@ export const ExternalPlatformDropdown = ({
className="pf-u-w-100"
isDisabled={dropdownIsDisabled}
>
{externalPlatformTypes[value as ExternalPlatformType].label}
{externalPlatformTypes[current as ExternalPlatformType].label}
</DropdownToggle>
),
[dropdownIsDisabled, value],
[dropdownIsDisabled, current],
);

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,34 +133,20 @@ export const OcmClusterDetailsFormFields = ({
const cpuArchitecture = (architectureData[values.cpuArchitecture] as CpuArchitectureItem).label;
const newFeatureSupportLevelContext = useNewFeatureSupportLevel();

const externalPlatformIntegrationStateMap = getExternalPlatformIntegrationStateMap(
newFeatureSupportLevelContext,
cpuArchitecture,
featureSupportLevelData,
const externalPlatformIntegrationStateMap = React.useMemo(
() =>
getExternalPlatformIntegrationStateMap(
newFeatureSupportLevelContext,
cpuArchitecture,
featureSupportLevelData,
),
[newFeatureSupportLevelContext, cpuArchitecture, featureSupportLevelData],
);

React.useEffect(() => {
nameInputRef.current?.focus();
}, []);

React.useEffect(() => {
if (clusterPlatform !== undefined) {
const platform = clusterPlatform === 'baremetal' ? 'none' : clusterPlatform;
setFieldValue('platform', platform);
} else {
if (
(values.platform === 'oci' &&
externalPlatformIntegrationStateMap['EXTERNAL_PLATFORM_OCI'].isDisabled) ||
(values.platform === 'nutanix' &&
externalPlatformIntegrationStateMap['NUTANIX_INTEGRATION'].isDisabled) ||
(values.platform === 'vsphere' &&
externalPlatformIntegrationStateMap['VSPHERE_INTEGRATION'].isDisabled)
) {
setFieldValue('platform', 'none');
}
}
}, [clusterPlatform, externalPlatformIntegrationStateMap, setFieldValue, values.platform]);

const handleExternalPartnerIntegrationsChange = React.useCallback(
(selectedPlatform: ExternalPlatformType) => {
const isOracleSelected = selectedPlatform === 'oci';
Expand All @@ -170,7 +156,8 @@ export const OcmClusterDetailsFormFields = ({
setFieldValue('hostsNetworkConfigurationType', HostsNetworkConfigurationType.DHCP);
}
},
[clusterWizardContext, setFieldValue],
// eslint-disable-next-line react-hooks/exhaustive-deps
[clusterWizardContext],
);

return (
Expand Down

0 comments on commit 10e39ec

Please sign in to comment.