UNPKG

@openshift-assisted/ui-lib

Version:

React component library for the Assisted Installer UI

58 lines 3.65 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AvailableSubnetsControl = void 0; const tslib_1 = require("tslib"); const react_1 = tslib_1.__importDefault(require("react")); const react_core_1 = require("@patternfly/react-core"); const ui_1 = require("../../ui"); const config_1 = require("../../../config"); const use_translation_wrapper_1 = require("../../../hooks/use-translation-wrapper"); const AvailableSubnetsControl = ({ hostSubnets, hosts, isRequired = false, isMultiNodeCluster, }) => { const { t } = (0, use_translation_wrapper_1.useTranslation)(); const getHelperText = (value) => { const matchingSubnet = hostSubnets.find((hn) => hn.subnet === value); if (matchingSubnet && isMultiNodeCluster) { const excludedHosts = (hosts === null || hosts === void 0 ? void 0 : 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 = (react_1.default.createElement(react_core_1.Popover, { position: "right", bodyContent: react_1.default.createElement("ul", null, excludedHosts .sort((hostA, hostB) => { var _a; return ((_a = hostA.requestedHostname) === null || _a === void 0 ? void 0 : _a.localeCompare(hostB.requestedHostname || '')) || 0; }) .map((host) => (react_1.default.createElement("li", { key: host.id }, host.requestedHostname || host.id)))), minWidth: "30rem", maxWidth: "50rem" }, react_1.default.createElement(react_core_1.AlertActionLink, { id: "form-input-hostSubnet-field-helper-view-excluded" }, t('ai:View {{count}} affected host', { count: excludedHosts.length, })))); return (react_1.default.createElement(react_core_1.Alert, { title: t('ai:This subnet range is not available on all hosts'), variant: react_core_1.AlertVariant.warning, actionLinks: actionLinks, isInline: true }, t('ai:Hosts outside of this range will not be included in the new cluster.'))); } return undefined; }; const hostSubnetLength = hostSubnets.length; return (react_1.default.createElement(ui_1.SelectField, { name: "hostSubnet", label: t('ai:Available subnets'), options: hostSubnets.length ? [ { label: t('ai:Please select a subnet. ({{hostSubnetLength}} available)', { hostSubnetLength, }), value: config_1.NO_SUBNET_SET, isDisabled: true, id: 'form-input-hostSubnet-field-option-no-subnet', }, ...hostSubnets .sort((subA, subB) => subA.humanized.localeCompare(subB.humanized)) .map((hn, index) => ({ label: hn.humanized, value: hn.subnet, id: `form-input-hostSubnet-field-option-${index}`, })), ] : [ { label: t('ai:No subnets are currently available'), value: config_1.NO_SUBNET_SET, }, ], getHelperText: getHelperText, isDisabled: !hostSubnets.length, isRequired: isRequired })); }; exports.AvailableSubnetsControl = AvailableSubnetsControl; //# sourceMappingURL=AvailableSubnetsControl.js.map