Skip to content

Commit

Permalink
Fixes #37677 - Extract RemWizard footer in a separate component
Browse files Browse the repository at this point in the history
  • Loading branch information
ofedoren committed Jul 23, 2024
1 parent 99c00ff commit d0d48a4
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 5 deletions.
54 changes: 54 additions & 0 deletions webpack/components/OpenscapRemediationWizard/Footer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import React from 'react';
import {
Button,
WizardFooter,
WizardContextConsumer,
} from '@patternfly/react-core';
import { translate as __ } from 'foremanReact/common/I18n';
import { WIZARD_TITLES } from './constants';

export const Footer = () => (
<WizardFooter>
<WizardContextConsumer>
{({ activeStep, onNext, onBack, onClose, goToStepByName }) => {
const isValid =
activeStep && activeStep.enableNext !== undefined
? activeStep.enableNext
: true;

return (
<>
{!activeStep.isFinishedStep ? (
<Button
ouiaId="oscap-rem-wiz-next-button"
variant="primary"
type="submit"
onClick={onNext}
isDisabled={!isValid}
>
{activeStep.name === WIZARD_TITLES.reviewRemediation
? __('Run')
: __('Next')}
</Button>
) : null}
<Button
ouiaId="oscap-rem-wiz-back-button"
variant="secondary"
onClick={onBack}
isDisabled={activeStep.name === WIZARD_TITLES.snippetSelect}
>
{__('Back')}
</Button>
<Button
ouiaId="oscap-rem-wiz-cancel-button"
variant="link"
onClick={onClose}
>
{__('Cancel')}
</Button>
</>
);
}}
</WizardContextConsumer>
</WizardFooter>
);
9 changes: 9 additions & 0 deletions webpack/components/OpenscapRemediationWizard/constants.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { translate as __ } from 'foremanReact/common/I18n';

export const OPENSCAP_REMEDIATION_MODAL_ID = 'openscapRemediationModal';
export const HOSTS_PATH = '/hosts';
export const FAIL_RULE_SEARCH = 'fails_xccdf_rule';
Expand All @@ -12,3 +14,10 @@ export const JOB_INVOCATION_API_REQUEST_KEY = 'OPENSCAP_REX_JOB_INVOCATIONS';

export const SNIPPET_SH = 'urn:xccdf:fix:script:sh';
export const SNIPPET_ANSIBLE = 'urn:xccdf:fix:script:ansible';

export const WIZARD_TITLES = {
snippetSelect: __('Select snippet'),
reviewHosts: __('Review hosts'),
reviewRemediation: __('Review remediation'),
finish: __('Done'),
};
16 changes: 11 additions & 5 deletions webpack/components/OpenscapRemediationWizard/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,17 @@ import { sprintf, translate as __ } from 'foremanReact/common/I18n';
import { API_OPERATIONS, get } from 'foremanReact/redux/API';

import OpenscapRemediationWizardContext from './OpenscapRemediationWizardContext';
import { Footer } from './Footer';
import {
selectLogResponse,
selectLogError,
selectLogStatus,
} from './OpenscapRemediationSelectors';
import { REPORT_LOG_REQUEST_KEY, FAIL_RULE_SEARCH } from './constants';
import {
REPORT_LOG_REQUEST_KEY,
FAIL_RULE_SEARCH,
WIZARD_TITLES,
} from './constants';
import { SnippetSelect, ReviewHosts, ReviewRemediation, Finish } from './steps';

const OpenscapRemediationWizard = ({
Expand Down Expand Up @@ -66,31 +71,31 @@ const OpenscapRemediationWizard = ({

const reviewHostsStep = {
id: 2,
name: __('Review hosts'),
name: WIZARD_TITLES.reviewHosts,
component: <ReviewHosts />,
canJumpTo: Boolean(snippet && method === 'job'),
enableNext: Boolean(snippet && method),
};
const steps = [
{
id: 1,
name: __('Select snippet'),
name: WIZARD_TITLES.snippetSelect,
component: <SnippetSelect />,
canJumpTo: true,
enableNext: Boolean(snippet && method),
},
...(snippet && method === 'job' ? [reviewHostsStep] : []),
{
id: 3,
name: __('Review remediation'),
name: WIZARD_TITLES.reviewRemediation,
component: <ReviewRemediation />,
canJumpTo: Boolean(snippet && method),
enableNext: method === 'job',
nextButtonText: __('Run'),
},
{
id: 4,
name: __('Done'),
name: WIZARD_TITLES.finish,
component: <Finish onClose={onWizardClose} />,
isFinishedStep: true,
},
Expand Down Expand Up @@ -128,6 +133,7 @@ const OpenscapRemediationWizard = ({
isOpen={isRemediationWizardOpen}
steps={steps}
onClose={onWizardClose}
footer={<Footer />}
/>
</OpenscapRemediationWizardContext.Provider>
)}
Expand Down

0 comments on commit d0d48a4

Please sign in to comment.