/* eslint-disable camelcase */ import React, { useContext, useState } from 'react'; import { some } from 'lodash'; import { CodeBlock, CodeBlockAction, CodeBlockCode, ClipboardCopyButton, Button, Grid, GridItem, Alert, Checkbox, } from '@patternfly/react-core'; import { ExternalLinkSquareAltIcon } from '@patternfly/react-icons'; import { translate as __ } from 'foremanReact/common/I18n'; import { foremanUrl } from 'foremanReact/common/helpers'; import { useForemanHostsPageUrl, useForemanHostDetailsPageUrl, } from 'foremanReact/Root/Context/ForemanContext'; import OpenscapRemediationWizardContext from '../OpenscapRemediationWizardContext'; import WizardHeader from '../WizardHeader'; import ViewSelectedHostsLink from '../ViewSelectedHostsLink'; import { FAIL_RULE_SEARCH } from '../constants'; import { findFixBySnippet } from '../helpers'; import './ReviewRemediation.scss'; const ReviewRemediation = () => { const { fixes, snippet, method, hostName, source, isRebootSelected, setIsRebootSelected, isAllHostsSelected, hostIdsParam, defaultFailedHostsSearch, } = useContext(OpenscapRemediationWizardContext); const [copied, setCopied] = useState(false); const selectedFix = findFixBySnippet(fixes, snippet); const snippetText = selectedFix?.full_text; // can be one of null, "true", "false" // if null, it may indicate that reboot might be needed const checkForReboot = () => !some(fixes, { reboot: 'false' }); const isRebootRequired = () => some(fixes, { reboot: 'true' }); const copyToClipboard = (e, text) => { navigator.clipboard.writeText(text.toString()); }; const onCopyClick = (e, text) => { copyToClipboard(e, text); setCopied(true); }; const description = method === 'manual' ? __('Review the remediation snippet and apply it to the host manually.') : __( 'Review the remediation snippet that will be applied to selected host(s).' ); const rebootAlertTitle = isRebootRequired() ? __('A reboot is required after applying remediation.') : __('A reboot might be required after applying remediation.'); const actions = ( onCopyClick(e, snippetText)} exitDelay={copied ? 1500 : 600} maxWidth="110px" variant="plain" onTooltipHidden={() => setCopied(false)} > {copied ? __('Successfully copied to clipboard!') : __('Copy to clipboard')} ); return ( <>
{' '} {checkForReboot() ? ( <> {method === 'manual' ? null : ( setIsRebootSelected(selected)} /> )} ) : null} {snippetText}
); }; export default ReviewRemediation;