Skip to content

Commit 6201b4c

Browse files
committed
PF4 wizard use formRenderer in tests
1 parent 7574fda commit 6201b4c

File tree

4 files changed

+3161
-1645
lines changed

4 files changed

+3161
-1645
lines changed

packages/pf4-component-mapper/src/form-fields/wizard/wizard-nav.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React from 'react';
22
import { WizardNavItem, WizardNav } from '@patternfly/react-core';
33
import isEqual from 'lodash/isEqual';
44
import get from 'lodash/get';
5+
import { PropTypes } from 'prop-types';
56

67
const memoValues = (initialValue) => {
78
let valueCache = initialValue;
@@ -52,6 +53,16 @@ const WizardNavigationInternal = React.memo(({
5253
}));
5354
}, isEqual);
5455

56+
WizardNavigationInternal.propTypes = {
57+
activeStepIndex: PropTypes.number.isRequired,
58+
formOptions: PropTypes.shape({
59+
valid: PropTypes.bool.isRequired,
60+
}).isRequired,
61+
maxStepIndex: PropTypes.number.isRequired,
62+
jumpToStep: PropTypes.func.isRequired,
63+
navSchema: PropTypes.array.isRequired,
64+
};
65+
5566
class WizardNavigationClass extends React.Component {
5667
constructor(props) {
5768
super(props);
@@ -112,4 +123,15 @@ class WizardNavigationClass extends React.Component {
112123
}
113124
}
114125

126+
WizardNavigationClass.propTypes = {
127+
activeStepIndex: PropTypes.number.isRequired,
128+
formOptions: PropTypes.object.isRequired,
129+
maxStepIndex: PropTypes.number.isRequired,
130+
jumpToStep: PropTypes.func.isRequired,
131+
setPrevSteps: PropTypes.func.isRequired,
132+
navSchema: PropTypes.array.isRequired,
133+
values: PropTypes.object.isRequired,
134+
crossroads: PropTypes.arrayOf(PropTypes.string),
135+
};
136+
115137
export default WizardNavigationClass;

packages/pf4-component-mapper/src/form-fields/wizard/wizard.js

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,21 @@ class Wizard extends React.Component {
183183
return schema;
184184
};
185185

186+
handleSubmitFinal = () => this.props.formOptions.onSubmit(
187+
this.handleSubmit(
188+
this.props.formOptions.getState().values,
189+
[ ...this.state.prevSteps, this.state.activeStep ],
190+
this.props.formOptions.getRegisteredFields,
191+
),
192+
this.props.formOptions
193+
);
194+
195+
setPrevSteps = () => this.setState((prevState) => ({
196+
navSchema: this.createSchema({ currentIndex: this.state.activeStepIndex }),
197+
prevSteps: prevState.prevSteps.slice(0, this.state.activeStepIndex),
198+
maxStepIndex: this.state.activeStepIndex,
199+
}))
200+
186201
render() {
187202
if (this.state.loading) {
188203
return null;
@@ -205,22 +220,12 @@ class Wizard extends React.Component {
205220
} = this.props;
206221
const { activeStepIndex, navSchema, maxStepIndex, isDynamic } = this.state;
207222

208-
const handleSubmit = () =>
209-
formOptions.onSubmit(
210-
this.handleSubmit(
211-
formOptions.getState().values,
212-
[ ...this.state.prevSteps, this.state.activeStep ],
213-
formOptions.getRegisteredFields,
214-
),
215-
formOptions
216-
);
217-
218223
const currentStep = (
219224
<WizardStep
220225
{ ...this.findCurrentStep(this.state.activeStep) }
221226
formOptions={{
222227
...formOptions,
223-
handleSubmit,
228+
handleSubmit: this.handleSubmitFinal,
224229
}}
225230
buttonLabels={ buttonLabels }
226231
FieldProvider={ FieldProvider }
@@ -233,7 +238,7 @@ class Wizard extends React.Component {
233238
<div className={ `pf-c-wizard ${inModal ? '' : 'no-shadow'} ${isCompactNav ? 'pf-m-compact-nav' : ''} ${setFullWidth ? 'pf-m-full-width' : ''} ${setFullHeight ? 'pf-m-full-height' : ''}` }
234239
role="dialog"
235240
aria-modal={ inModal ? 'true' : undefined }
236-
onKeyDown={ e => handleEnter(e, formOptions, this.state.activeStep, this.findCurrentStep, this.handleNext, handleSubmit) }
241+
onKeyDown={ e => handleEnter(e, formOptions, this.state.activeStep, this.findCurrentStep, this.handleNext, this.handleSubmitFinal) }
237242
>
238243
{ title && <WizardHeader
239244
title={ title }
@@ -253,11 +258,7 @@ class Wizard extends React.Component {
253258
crossroads={ crossroads }
254259
isDynamic={ isDynamic }
255260
values={ values }
256-
setPrevSteps={ () => this.setState((prevState) => ({
257-
navSchema: this.createSchema({ currentIndex: activeStepIndex }),
258-
prevSteps: prevState.prevSteps.slice(0, activeStepIndex),
259-
maxStepIndex: activeStepIndex,
260-
})) }
261+
setPrevSteps={ this.setPrevSteps }
261262
/>
262263
) }
263264
</FormSpyProvider>

0 commit comments

Comments
 (0)