@openshift-assisted/ui-lib
Version:
React component library for the Assisted Installer UI
73 lines • 4.76 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const React = tslib_1.__importStar(require("react"));
const Yup = tslib_1.__importStar(require("yup"));
const formik_1 = require("formik");
const noop_js_1 = tslib_1.__importDefault(require("lodash-es/noop.js"));
const react_core_1 = require("@patternfly/react-core");
const HostsForm_1 = tslib_1.__importDefault(require("./HostsForm"));
const use_translation_wrapper_1 = require("../../../../../common/hooks/use-translation-wrapper");
const helpers_1 = require("../../../helpers");
const common_1 = require("../../../common");
const validationSchema = (clusterName, nodePools, t) => Yup.lazy((values) => Yup.object().shape({
agentNamespace: Yup.string().required(t('ai:Required field')),
nodePools: Yup.array().of(Yup.object()
.shape({
nodePoolName: Yup.string()
.required(t('ai:Required field'))
.test(t('ai:Must be unique'), t('ai:Must be unique'), (value) => {
if (!value) {
return true;
}
return (values.nodePools.filter(({ nodePoolName }) => nodePoolName === value).length ===
1 &&
!nodePools.some(({ metadata }) => (metadata === null || metadata === void 0 ? void 0 : metadata.name) === value && (metadata === null || metadata === void 0 ? void 0 : metadata.namespace) === clusterName));
}),
clusterName: Yup.string().required(t('ai:Required field')),
count: Yup.number(),
releaseImage: Yup.string().required(t('ai:Required field')),
autoscaling: Yup.object().shape({
minReplicas: Yup.number().min(1, t('ai:Must be at least 1')),
maxReplicas: Yup.number().min(1, t('ai:Must be at least 1')),
}),
})
.required(t('ai:Required field'))),
}));
const HostsStep = ({ formRef, onValuesChanged, infraEnvs, agents, clusterName, initInfraEnv, initNodePools, initReleaseImage, nodePools, controllerAvailabilityPolicy, infrastructureAvailabilityPolicy, olmCatalogPlacement, }) => {
var _a, _b;
const { t } = (0, use_translation_wrapper_1.useTranslation)();
const availableAgents = (0, helpers_1.getAgentsForSelection)(agents);
const infraEnvsWithAgents = infraEnvs.filter((ie) => availableAgents.some((a) => {
var _a, _b, _c, _d, _e;
return ((_b = (_a = a.metadata) === null || _a === void 0 ? void 0 : _a.labels) === null || _b === void 0 ? void 0 : _b[common_1.INFRAENV_AGENTINSTALL_LABEL_KEY]) === ((_c = ie.metadata) === null || _c === void 0 ? void 0 : _c.name) &&
((_d = a.metadata) === null || _d === void 0 ? void 0 : _d.namespace) === ((_e = ie.metadata) === null || _e === void 0 ? void 0 : _e.namespace) &&
!a.spec.clusterDeploymentName;
}));
return (React.createElement(react_core_1.Stack, { hasGutter: true },
React.createElement(react_core_1.StackItem, null, t('ai:Define the quantity of worker nodes and nodepools to create for your cluster. Additional worker nodes and nodepools can be added after the cluster is created.')),
React.createElement(react_core_1.StackItem, null,
React.createElement(formik_1.Formik, { initialValues: {
controllerAvailabilityPolicy: controllerAvailabilityPolicy || 'HighlyAvailable',
infrastructureAvailabilityPolicy: infrastructureAvailabilityPolicy || 'HighlyAvailable',
olmCatalogPlacement: olmCatalogPlacement || 'management',
agentNamespace: initInfraEnv || ((_b = (_a = infraEnvsWithAgents[0]) === null || _a === void 0 ? void 0 : _a.metadata) === null || _b === void 0 ? void 0 : _b.namespace) || '',
nodePools: initNodePools || [
{
nodePoolName: `nodepool-${clusterName}-1`,
count: 1,
agentLabels: [],
releaseImage: initReleaseImage,
clusterName,
useAutoscaling: false,
autoscaling: {
minReplicas: 1,
maxReplicas: 1,
},
},
],
}, validationSchema: validationSchema(clusterName, nodePools, t), innerRef: formRef, onSubmit: noop_js_1.default },
React.createElement(HostsForm_1.default, { onValuesChanged: onValuesChanged, infraEnvs: infraEnvsWithAgents, agents: agents, clusterName: clusterName, initReleaseImage: initReleaseImage })))));
};
exports.default = HostsStep;
//# sourceMappingURL=HostsStep.js.map