11import React , { cloneElement } from 'react' ;
22import { createPortal } from 'react-dom' ;
33import PropTypes from 'prop-types' ;
4- import { WizardHeader , WizardNav , WizardNavItem , Backdrop , Bullseye } from '@patternfly/react-core' ;
4+ import { WizardHeader , Backdrop , Bullseye , WizardNav } from '@patternfly/react-core' ;
55import WizardStep from './wizard-step' ;
66import './wizard-styles.scss' ;
77import get from 'lodash/get' ;
88import set from 'lodash/set' ;
99import flattenDeep from 'lodash/flattenDeep' ;
1010import handleEnter from '@data-driven-forms/common/src/wizard/enter-handler' ;
11+ import WizardNavigation from './wizard-nav' ;
1112
1213const DYNAMIC_WIZARD_TYPES = [ 'function' , 'object' ] ;
1314
@@ -106,11 +107,12 @@ class Wizard extends React.Component {
106107 const currentStep = this . findCurrentStep ( prevState . prevSteps [ index ] ) ;
107108 const currentStepHasStepMapper = DYNAMIC_WIZARD_TYPES . includes ( typeof currentStep . nextStep ) ;
108109
110+ const hardcodedCrossroads = this . props . crossroads ;
109111 const dynamicStepShouldDisableNav = prevState . isDynamic && ( currentStepHasStepMapper || ! this . props . predictSteps ) ;
110112
111113 const invalidStepShouldDisableNav = valid === false ;
112114
113- if ( dynamicStepShouldDisableNav ) {
115+ if ( dynamicStepShouldDisableNav && ! hardcodedCrossroads ) {
114116 newState = {
115117 navSchema : this . props . predictSteps ? this . createSchema ( { currentIndex : index } ) : prevState . navSchema . slice ( 0 , index + INDEXING_BY_ZERO ) ,
116118 prevSteps : prevState . prevSteps . slice ( 0 , index ) ,
@@ -187,9 +189,21 @@ class Wizard extends React.Component {
187189 }
188190
189191 const {
190- title, description, FieldProvider, formOptions, buttonLabels, buttonsClassName, inModal, setFullWidth, setFullHeight, isCompactNav, showTitles,
192+ title,
193+ description,
194+ FieldProvider,
195+ formOptions,
196+ buttonLabels,
197+ buttonsClassName,
198+ inModal,
199+ setFullWidth,
200+ setFullHeight,
201+ isCompactNav,
202+ showTitles,
203+ FormSpyProvider,
204+ crossroads,
191205 } = this . props ;
192- const { activeStepIndex, navSchema, maxStepIndex } = this . state ;
206+ const { activeStepIndex, navSchema, maxStepIndex, isDynamic } = this . state ;
193207
194208 const handleSubmit = ( ) =>
195209 formOptions . onSubmit (
@@ -214,34 +228,6 @@ class Wizard extends React.Component {
214228 showTitles = { showTitles }
215229 /> ) ;
216230
217- const createStepsMap = ( ) => navSchema
218- . filter ( field => field . primary )
219- . map ( step => {
220- const substeps = step . substepOf && navSchema . filter ( field => field . substepOf === step . substepOf ) ;
221-
222- return < WizardNavItem
223- key = { step . substepOf || step . title }
224- text = { step . substepOf || step . title }
225- isCurrent = { substeps ? activeStepIndex >= step . index && activeStepIndex < step . index + substeps . length : activeStepIndex === step . index }
226- isDisabled = { formOptions . valid ? maxStepIndex < step . index : step . index > activeStepIndex }
227- onNavItemClick = { ( ind ) => this . jumpToStep ( ind , formOptions . valid ) }
228- step = { step . index }
229- >
230- { substeps && < WizardNav returnList >
231- { substeps . map ( substep => < WizardNavItem
232- key = { substep . title }
233- text = { substep . title }
234- isCurrent = { activeStepIndex === substep . index }
235- isDisabled = { formOptions . valid ?
236- maxStepIndex < substep . index
237- : substep . index > activeStepIndex }
238- onNavItemClick = { ( ind ) => this . jumpToStep ( ind , formOptions . valid ) }
239- step = { substep . index }
240- /> ) }
241- </ WizardNav > }
242- </ WizardNavItem > ;
243- } ) ;
244-
245231 return (
246232 < Modal inModal = { inModal } container = { this . container } >
247233 < div className = { `pf-c-wizard ${ inModal ? '' : 'no-shadow' } ${ isCompactNav ? 'pf-m-compact-nav' : '' } ${ setFullWidth ? 'pf-m-full-width' : '' } ${ setFullHeight ? 'pf-m-full-height' : '' } ` }
@@ -256,7 +242,25 @@ class Wizard extends React.Component {
256242 /> }
257243 < div className = "pf-c-wizard__outer-wrap" >
258244 < WizardNav >
259- { createStepsMap ( ) }
245+ < FormSpyProvider >
246+ { ( { values } ) => (
247+ < WizardNavigation
248+ navSchema = { navSchema }
249+ activeStepIndex = { activeStepIndex }
250+ formOptions = { formOptions }
251+ maxStepIndex = { maxStepIndex }
252+ jumpToStep = { this . jumpToStep }
253+ crossroads = { crossroads }
254+ isDynamic = { isDynamic }
255+ 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+ />
262+ ) }
263+ </ FormSpyProvider >
260264 </ WizardNav >
261265 { cloneElement ( currentStep , {
262266 handleNext : ( nextStep ) => this . handleNext ( nextStep , formOptions . getRegisteredFields ) ,
@@ -281,6 +285,7 @@ Wizard.propTypes = {
281285 title : PropTypes . any ,
282286 description : PropTypes . any ,
283287 FieldProvider : PropTypes . PropTypes . oneOfType ( [ PropTypes . object , PropTypes . func ] ) . isRequired ,
288+ FormSpyProvider : PropTypes . PropTypes . oneOfType ( [ PropTypes . object , PropTypes . func ] ) . isRequired ,
284289 formOptions : PropTypes . shape ( {
285290 getState : PropTypes . func . isRequired ,
286291 onSubmit : PropTypes . func . isRequired ,
@@ -298,6 +303,7 @@ Wizard.propTypes = {
298303 isDynamic : PropTypes . bool ,
299304 showTitles : PropTypes . bool ,
300305 predictSteps : PropTypes . bool ,
306+ crossroads : PropTypes . arrayOf ( PropTypes . string ) ,
301307} ;
302308
303309const defaultLabels = {
0 commit comments