UNPKG

@openshift-assisted/ui-lib

Version:

React component library for the Assisted Installer UI

108 lines 5.95 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const React = tslib_1.__importStar(require("react")); const react_core_1 = require("@patternfly/react-core"); const helpers_1 = require("../helpers"); const HostsTable_1 = tslib_1.__importDefault(require("../../../common/components/hosts/HostsTable")); const common_1 = require("../../../common"); const agentStatus_1 = require("../helpers/agentStatus"); const usePagination_1 = require("../../../common/components/hosts/usePagination"); const utils_1 = require("../../../common/utils"); const use_translation_wrapper_1 = require("../../../common/hooks/use-translation-wrapper"); const ApproveTableRow = ({ agent, children }) => (React.createElement("div", { className: (agent === null || agent === void 0 ? void 0 : agent.spec.approved) ? 'pf-v5-u-color-200' : undefined }, children)); const hostnameColumn = (agents, t) => { return { header: { title: t('ai:Hostname'), props: { id: 'col-header-hostname', // ACM jest tests require id over testId }, sort: true, }, cell: (host) => { var _a; const agent = agents.find((a) => { var _a; return ((_a = a.metadata) === null || _a === void 0 ? void 0 : _a.uid) === host.id; }); const hostname = (agent === null || agent === void 0 ? void 0 : agent.spec.hostname) || ((_a = agent === null || agent === void 0 ? void 0 : agent.status) === null || _a === void 0 ? void 0 : _a.inventory.hostname); return { title: React.createElement(ApproveTableRow, { agent: agent }, hostname), props: { 'data-testid': 'hostname' }, sortableValue: hostname, }; }, }; }; const statusColumn = (agents, agentStatuses, t) => { return { header: { title: t('ai:Status'), props: { id: 'col-header-status', // ACM jest tests require id over testId }, sort: true, }, cell: (host) => { const agent = agents.find((a) => { var _a; return ((_a = a.metadata) === null || _a === void 0 ? void 0 : _a.uid) === host.id; }); const status = (agent === null || agent === void 0 ? void 0 : agent.spec.approved) ? t('ai:Already approved') : agentStatuses.discovered.title; const icon = agentStatuses.discovered.icon; return { title: (React.createElement(ApproveTableRow, { agent: agent }, (agent === null || agent === void 0 ? void 0 : agent.spec.approved) ? (status) : (React.createElement(React.Fragment, null, icon, " ", status)))), props: { 'data-testid': 'status' }, sortableValue: status, }; }, }; }; const MassApproveAgentModal = ({ agents, onApprove, isOpen, onClose, }) => { const [progress, setProgress] = React.useState(null); const [error, setError] = React.useState(); const { t } = (0, use_translation_wrapper_1.useTranslation)(); const agentStatuses = (0, agentStatus_1.agentStatus)(t); const onClick = () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { setError(undefined); let i = 0; try { for (const agent of agents) { if (!agent.spec.approved) { setProgress((100 * (i + 1)) / agents.length); yield onApprove(agent); } i++; } setProgress(null); onClose(); } catch (err) { setError({ title: t('ai:An error occured while approving agents'), message: (0, utils_1.getErrorMessage)(err), }); setProgress(null); } }); const { content, hosts } = React.useMemo(() => ({ content: [hostnameColumn(agents, t), statusColumn(agents, agentStatuses, t)], hosts: (0, helpers_1.getAIHosts)(agents), }), [agentStatuses, agents, t]); const paginationProps = (0, usePagination_1.usePagination)(hosts.length); return (React.createElement(react_core_1.Modal, { "aria-label": t('ai:Approve hosts dialog'), title: t('ai:Approve hosts to join infrastructure environment'), isOpen: isOpen, onClose: onClose, hasNoBodyWrapper: true, id: "mass-approve-modal", variant: "medium" }, React.createElement(react_core_1.ModalBoxBody, null, React.createElement(react_core_1.Stack, { hasGutter: true }, React.createElement(react_core_1.StackItem, null, React.createElement(react_core_1.Alert, { isInline: true, variant: "info", title: t('ai:You are approving multiple hosts. All hosts listed below will be approved to join the infrastructure environment if you continue. Make sure that you expect and recognize the hosts before approving.') })), React.createElement(react_core_1.StackItem, null, React.createElement(HostsTable_1.default, Object.assign({ hosts: hosts, content: content }, paginationProps), React.createElement("div", null, t('ai:No hosts selected')))), React.createElement(react_core_1.StackItem, null, React.createElement(common_1.ModalProgress, { error: error, progress: progress })))), React.createElement(react_core_1.ModalBoxFooter, null, React.createElement(react_core_1.Button, { onClick: onClick, isDisabled: progress !== null }, t('ai:Approve all hosts')), React.createElement(react_core_1.Button, { onClick: onClose, variant: react_core_1.ButtonVariant.secondary, isDisabled: progress !== null }, t('ai:Cancel'))))); }; exports.default = MassApproveAgentModal; //# sourceMappingURL=MassApproveAgentModal.js.map