@openshift-assisted/ui-lib
Version:
React component library for the Assisted Installer UI
146 lines • 8.33 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CimConfigurationModal = void 0;
const tslib_1 = require("tslib");
const React = tslib_1.__importStar(require("react"));
const react_core_1 = require("@patternfly/react-core");
const use_translation_wrapper_1 = require("../../../../common/hooks/use-translation-wrapper");
const helpers_1 = require("../../helpers");
const CimConfigurationForm_1 = require("./CimConfigurationForm");
const persist_1 = require("./persist");
const CimConfigDisconnectedAlert_1 = require("./CimConfigDisconnectedAlert");
const constants_1 = require("./constants");
const utils_1 = require("./utils");
const CimConfigProgressAlert_1 = require("./CimConfigProgressAlert");
require("./CimConfigurationModal.css");
const CimConfigurationModal = ({ isOpen, onClose, agentServiceConfig, platform, docDisconnectedUrl, docConfigUrl, docConfigAwsUrl, getResource, listResources, patchResource, createResource, }) => {
const { t } = (0, use_translation_wrapper_1.useTranslation)();
const [error, setError] = React.useState();
const [isSaving, setSaving] = React.useState(false);
const [dbVolSize, _setDbVolSize] = React.useState(() => { var _a, _b, _c, _d; return (0, helpers_1.getStorageSizeGiB)(10, (_d = (_c = (_b = (_a = agentServiceConfig === null || agentServiceConfig === void 0 ? void 0 : agentServiceConfig.spec) === null || _a === void 0 ? void 0 : _a.databaseStorage) === null || _b === void 0 ? void 0 : _b.resources) === null || _c === void 0 ? void 0 : _c.requests) === null || _d === void 0 ? void 0 : _d.storage); });
const [dbVolSizeValidation, setDbVolSizeValidation] = React.useState();
const [fsVolSize, _setFsVolSize] = React.useState(() => {
var _a, _b, _c, _d;
return (0, helpers_1.getStorageSizeGiB)(100, (_d = (_c = (_b = (_a = agentServiceConfig === null || agentServiceConfig === void 0 ? void 0 : agentServiceConfig.spec) === null || _a === void 0 ? void 0 : _a.filesystemStorage) === null || _b === void 0 ? void 0 : _b.resources) === null || _c === void 0 ? void 0 : _c.requests) === null || _d === void 0 ? void 0 : _d.storage);
});
const [fsVolSizeValidation, setFsVolSizeValidation] = React.useState();
const [imgVolSize, _setImgVolSize] = React.useState(() => { var _a, _b, _c, _d; return (0, helpers_1.getStorageSizeGiB)(50, (_d = (_c = (_b = (_a = agentServiceConfig === null || agentServiceConfig === void 0 ? void 0 : agentServiceConfig.spec) === null || _a === void 0 ? void 0 : _a.imageStorage) === null || _b === void 0 ? void 0 : _b.resources) === null || _c === void 0 ? void 0 : _c.requests) === null || _d === void 0 ? void 0 : _d.storage); });
const [imgVolSizeValidation, setImgVolSizeValidation] = React.useState();
const [configureLoadBalancer, setConfigureLoadBalancer] = React.useState(platform === 'AWS');
const [configureLoadBalancerInitial, setConfigureLoadBalancerInitial] = React.useState(true);
const setDbVolSize = (v) => {
if (v < constants_1.MIN_DB_VOL_SIZE) {
setDbVolSizeValidation(t('ai:Minimal value is 1Gi'));
}
else {
setDbVolSizeValidation(undefined);
}
_setDbVolSize(v);
};
const setFsVolSize = (v) => {
if (v < constants_1.MIN_FS_VOL_SIZE) {
setFsVolSizeValidation(t('ai:Minimal value is 1Gi'));
}
else {
setFsVolSizeValidation(undefined);
}
_setFsVolSize(v);
};
const setImgVolSize = (v) => {
if (v < constants_1.MIN_IMG_VOL_SIZE) {
setImgVolSizeValidation(t('ai:Minimal value is 10Gi'));
}
else {
setImgVolSizeValidation(undefined);
}
_setImgVolSize(v);
};
const isEdit = !!agentServiceConfig;
React.useEffect(() => {
const doItAsync = () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
if (platform === 'AWS') {
if (!isEdit || (yield (0, persist_1.isIngressController)(getResource))) {
setConfigureLoadBalancer(true);
setConfigureLoadBalancerInitial(true);
return;
}
}
setConfigureLoadBalancer(false);
setConfigureLoadBalancerInitial(false);
});
void doItAsync();
},
// eslint-disable-next-line react-hooks/exhaustive-deps
[platform]);
const formProps = {
dbVolSize,
dbVolSizeValidation,
setDbVolSize,
fsVolSize,
fsVolSizeValidation,
setFsVolSize,
imgVolSize,
imgVolSizeValidation,
setImgVolSize,
configureLoadBalancer,
configureLoadBalancerInitial,
setConfigureLoadBalancer,
};
const onConfigure = () => {
const doItAsync = () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
setSaving(true);
setError(undefined);
(0, CimConfigProgressAlert_1.resetCimConfigProgressAlertSuccessStatus)();
if (yield (0, persist_1.onEnableCIM)({
t,
setError,
getResource,
listResources,
patchResource,
createResource,
agentServiceConfig,
platform,
dbVolSizeGiB: dbVolSize,
fsVolSizeGiB: fsVolSize,
imgVolSizeGiB: imgVolSize,
configureLoadBalancer,
})) {
// successfuly persisted
onClose();
}
// keep modal open and show error
setConfigureLoadBalancerInitial(configureLoadBalancer);
setSaving(false);
});
void doItAsync();
};
const isError = !!(error === null || error === void 0 ? void 0 : error.title); // this is a communication error only (not the one from agentServiceConfig)
const isConfigure = !isEdit || !configureLoadBalancerInitial; /* The only possible change for the Edit flow */
const isConfigureDisabled = !!(isSaving ||
dbVolSizeValidation ||
fsVolSizeValidation ||
imgVolSizeValidation ||
(isEdit && configureLoadBalancerInitial === configureLoadBalancer));
const isInProgressPeriod = (0, utils_1.isCIMConfigProgressing)({ agentServiceConfig });
// const isConfiguring = isSaving || isInProgressPeriod;
let actions;
if (isConfigure) {
actions = [
React.createElement(react_core_1.Button, { key: "configure", variant: react_core_1.ButtonVariant.primary, isDisabled: isConfigureDisabled, onClick: onConfigure }, t('ai:Configure')),
React.createElement(react_core_1.Button, { key: "cancel", variant: react_core_1.ButtonVariant.link, onClick: onClose }, t('ai:Cancel')),
];
}
else {
actions = [
React.createElement(react_core_1.Button, { key: "close", variant: react_core_1.ButtonVariant.primary, onClick: onClose }, t('ai:Close')),
];
}
return (React.createElement(react_core_1.Modal, { "aria-label": t('ai:Configure host inventory settings'), title: t('ai:Configure host inventory settings'), isOpen: isOpen, onClose: onClose, actions: actions, variant: react_core_1.ModalVariant.medium, id: "cim-config-modal", className: "cim-config-modal" },
t('ai:Configuring the host inventory settings will enable the Central Infrastructure Management.'),
isError && (React.createElement(react_core_1.Alert, { title: error.title, variant: error.variant || react_core_1.AlertVariant.danger, isInline: true }, error.message)),
React.createElement(CimConfigDisconnectedAlert_1.CimConfigDisconnectedAlert, { docDisconnectedUrl: docDisconnectedUrl }),
React.createElement(CimConfigurationForm_1.CimConfigurationForm, Object.assign({ isEdit: isEdit, isInProgressPeriod: isInProgressPeriod, onClose: onClose, docConfigUrl: docConfigUrl, docConfigAwsUrl: docConfigAwsUrl }, formProps)),
isConfigure && (React.createElement(react_core_1.Alert, { variant: react_core_1.AlertVariant.warning, title: t('ai:Storage sizes cannot be changed once you configure.'), isInline: true }))));
};
exports.CimConfigurationModal = CimConfigurationModal;
//# sourceMappingURL=CimConfigurationModal.js.map