1
1
import React , { useState , useEffect } from 'react' ;
2
2
import PropTypes from 'prop-types' ;
3
3
import { useTranslation } from 'react-i18next' ;
4
- import { Stepper as CoralStepper } from '@talend/design-system' ;
4
+ import { ErrorState , StackVertical , Stepper as CoralStepper } from '@talend/design-system' ;
5
5
import Icon from '../Icon' ;
6
6
import CircularProgress from '../CircularProgress' ;
7
7
import { getTheme } from '../theme' ;
@@ -33,6 +33,8 @@ const LOADING_STEP_STATUSES = {
33
33
*/
34
34
const isErrorInSteps = steps => steps . some ( step => step . status === LOADING_STEP_STATUSES . FAILURE ) ;
35
35
36
+ const getStepInError = steps => steps . find ( step => step . status === LOADING_STEP_STATUSES . FAILURE ) ;
37
+
36
38
/**
37
39
* This function tells if all the steps are successful
38
40
* @param {array } steps array of steps
@@ -149,7 +151,7 @@ const transitionEmptyToLoading = transition(TRANSITION_STATE.STEPS, DEFAULT_TRAN
149
151
150
152
function Stepper ( { steps, title, renderActions, children } ) {
151
153
const { t } = useTranslation ( I18N_DOMAIN_COMPONENTS ) ;
152
- const isInError = isErrorInSteps ( steps ) ;
154
+ const errorStep = getStepInError ( steps ) ;
153
155
const [ transitionState , setTransitionState ] = useState (
154
156
isStepsLoading ( steps ) || ! children ? TRANSITION_STATE . STEPS : TRANSITION_STATE . CHILD ,
155
157
) ;
@@ -170,25 +172,29 @@ function Stepper({ steps, title, renderActions, children }) {
170
172
}
171
173
} , [ steps ] ) ;
172
174
175
+ if ( ! ! errorStep ) {
176
+ return (
177
+ < StackVertical gap = { 0 } align = "center" justify = "center" >
178
+ < ErrorState title = { errorStep . label } description = { errorStep . message ?. label } />
179
+ { renderActions && renderActions ( ! ! errorStep ) ? (
180
+ < div > { renderActions ( ! ! errorStep ) } </ div >
181
+ ) : null }
182
+ </ StackVertical >
183
+ ) ;
184
+ }
185
+
173
186
return (
174
187
< React . Fragment >
175
188
< StepperTransition active = { transitionState === TRANSITION_STATE . CHILD } >
176
189
{ children }
177
190
</ StepperTransition >
178
191
< StepperTransition active = { transitionState === TRANSITION_STATE . STEPS } >
179
192
< div className = { getClass ( 'stepper' ) } >
180
- < div
181
- className = { getClass ( 'loading-content-steps' , {
182
- 'stepper-content-error' : isInError ,
183
- } ) }
184
- >
193
+ < div className = { getClass ( 'loading-content-steps' ) } >
185
194
{ title && < h2 > { title } </ h2 > }
186
195
< ol className = { getClass ( 'stepper-steps' ) } >
187
196
{ steps . map ( ( step , index , array ) => showStep ( t , step , index , array ) ) }
188
197
</ ol >
189
- { renderActions && renderActions ( isInError ) ? (
190
- < div > { renderActions ( isInError ) } </ div >
191
- ) : null }
192
198
</ div >
193
199
</ div >
194
200
</ StepperTransition >
0 commit comments