Skip to content

Commit

Permalink
Fix subnedt select helper text
Browse files Browse the repository at this point in the history
  • Loading branch information
jgyselov committed Jan 30, 2025
1 parent d1c0d8a commit ecd87fb
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 71 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
import * as Yup from 'yup';
import {
Cluster,
ClusterDefaultConfig,
} from '@openshift-assisted/types/assisted-installer-service';
import { HostSubnets, NetworkConfigurationValues } from '../../../common/types/clusters';
import {
hostPrefixValidationSchema,
hostSubnetValidationSchema,
ipBlockValidationSchema,
sshPublicKeyValidationSchema,
vipValidationSchema,
} from '../../../common/components/ui';

import { NetworkConfigurationValues } from '../../../common/types/clusters';
import {
getSubnetFromMachineNetworkCidr,
getHostSubnets,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,68 +1,11 @@
import React from 'react';
import { Alert, AlertActionLink, AlertVariant, Popover } from '@patternfly/react-core';
import { HostSubnet, HostSubnets } from '../../../types/clusters';
import { Cluster, Host } from '@openshift-assisted/types/assisted-installer-service';
import { HostSubnets } from '../../../types/clusters';
import { Host } from '@openshift-assisted/types/assisted-installer-service';
import { SelectField } from '../../ui';
import { NO_SUBNET_SET } from '../../../config';
import { useTranslation } from '../../../hooks/use-translation-wrapper';

interface SubnetHelperTextProps {
matchingSubnet: HostSubnet;
hosts: Cluster['hosts'];
}

const SubnetHelperText = ({ matchingSubnet, hosts }: SubnetHelperTextProps) => {
const { t } = useTranslation();
const excludedHosts =
hosts?.filter(
(host) =>
!['disabled', 'disconnected'].includes(host.status) &&
!matchingSubnet.hostIDs.includes(host.requestedHostname || ''),
) || [];

// Workaround for bug in CIM backend. hostIDs are empty
if (excludedHosts.length === 0 || !matchingSubnet.hostIDs.length) {
return null;
}

const actionLinks = (
<Popover
position="right"
bodyContent={
<ul>
{excludedHosts
.sort(
(hostA, hostB) =>
hostA.requestedHostname?.localeCompare(hostB.requestedHostname || '') || 0,
)
.map((host) => (
<li key={host.id}>{host.requestedHostname || host.id}</li>
))}
</ul>
}
minWidth="30rem"
maxWidth="50rem"
>
<AlertActionLink id="form-input-hostSubnet-field-helper-view-excluded">
{t('ai:View {{count}} affected host', {
count: excludedHosts.length,
})}
</AlertActionLink>
</Popover>
);

return (
<Alert
title={t('ai:This subnet range is not available on all hosts')}
variant={AlertVariant.warning}
actionLinks={actionLinks}
isInline
>
{t('ai:Hosts outside of this range will not be included in the new cluster.')}
</Alert>
);
};

export interface AvailableSubnetsControlProps {
hostSubnets: HostSubnets;
hosts: Host[];
Expand All @@ -79,14 +22,60 @@ export const AvailableSubnetsControl = ({
const { t } = useTranslation();
const getHelperText = (value: string) => {
const matchingSubnet = hostSubnets.find((hn) => hn.subnet === value);
if (matchingSubnet) {
if (matchingSubnet && isMultiNodeCluster) {
const excludedHosts =
hosts?.filter(
(host) =>
!['disabled', 'disconnected'].includes(host.status) &&
!matchingSubnet.hostIDs.includes(host.requestedHostname || ''),
) || [];

// Workaround for bug in CIM backend. hostIDs are empty
if (excludedHosts.length === 0 || !matchingSubnet.hostIDs.length) {
return undefined;
}

const actionLinks = (
<Popover
position="right"
bodyContent={
<ul>
{excludedHosts
.sort(
(hostA, hostB) =>
hostA.requestedHostname?.localeCompare(hostB.requestedHostname || '') || 0,
)
.map((host) => (
<li key={host.id}>{host.requestedHostname || host.id}</li>
))}
</ul>
}
minWidth="30rem"
maxWidth="50rem"
>
<AlertActionLink id="form-input-hostSubnet-field-helper-view-excluded">
{t('ai:View {{count}} affected host', {
count: excludedHosts.length,
})}
</AlertActionLink>
</Popover>
);

return (
isMultiNodeCluster && <SubnetHelperText matchingSubnet={matchingSubnet} hosts={hosts} />
<Alert
title={t('ai:This subnet range is not available on all hosts')}
variant={AlertVariant.warning}
actionLinks={actionLinks}
isInline
>
{t('ai:Hosts outside of this range will not be included in the new cluster.')}
</Alert>
);
}

return undefined;
};

const hostSubnetLength = hostSubnets.length;
return (
<SelectField
Expand Down

0 comments on commit ecd87fb

Please sign in to comment.