Skip to content

Commit 691e07a

Browse files
authored
feat(components): use DS Error State in Stepper (#4644)
1 parent 3604ba4 commit 691e07a

File tree

6 files changed

+195
-175
lines changed

6 files changed

+195
-175
lines changed

.changeset/light-pumpkins-smoke.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@talend/react-components': minor
3+
---
4+
5+
feat(components): use ErrorState in the Stepper

packages/components/src/Stepper/Stepper.component.js

+16-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { useState, useEffect } from 'react';
22
import PropTypes from 'prop-types';
33
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';
55
import Icon from '../Icon';
66
import CircularProgress from '../CircularProgress';
77
import { getTheme } from '../theme';
@@ -33,6 +33,8 @@ const LOADING_STEP_STATUSES = {
3333
*/
3434
const isErrorInSteps = steps => steps.some(step => step.status === LOADING_STEP_STATUSES.FAILURE);
3535

36+
const getStepInError = steps => steps.find(step => step.status === LOADING_STEP_STATUSES.FAILURE);
37+
3638
/**
3739
* This function tells if all the steps are successful
3840
* @param {array} steps array of steps
@@ -149,7 +151,7 @@ const transitionEmptyToLoading = transition(TRANSITION_STATE.STEPS, DEFAULT_TRAN
149151

150152
function Stepper({ steps, title, renderActions, children }) {
151153
const { t } = useTranslation(I18N_DOMAIN_COMPONENTS);
152-
const isInError = isErrorInSteps(steps);
154+
const errorStep = getStepInError(steps);
153155
const [transitionState, setTransitionState] = useState(
154156
isStepsLoading(steps) || !children ? TRANSITION_STATE.STEPS : TRANSITION_STATE.CHILD,
155157
);
@@ -170,25 +172,29 @@ function Stepper({ steps, title, renderActions, children }) {
170172
}
171173
}, [steps]);
172174

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+
173186
return (
174187
<React.Fragment>
175188
<StepperTransition active={transitionState === TRANSITION_STATE.CHILD}>
176189
{children}
177190
</StepperTransition>
178191
<StepperTransition active={transitionState === TRANSITION_STATE.STEPS}>
179192
<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')}>
185194
{title && <h2>{title}</h2>}
186195
<ol className={getClass('stepper-steps')}>
187196
{steps.map((step, index, array) => showStep(t, step, index, array))}
188197
</ol>
189-
{renderActions && renderActions(isInError) ? (
190-
<div>{renderActions(isInError)}</div>
191-
) : null}
192198
</div>
193199
</div>
194200
</StepperTransition>

packages/components/src/Stepper/Stepper.component.module.scss

-4
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@ $stepper-icon-size: $svg-md-size !default;
88
justify-content: center;
99
padding-left: $padding-small;
1010

11-
&-content-error {
12-
width: 75rem;
13-
}
14-
1511
&-step {
1612
padding: $padding-small 0;
1713

packages/components/src/Stepper/Stepper.component.test.js

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import React from 'react';
2-
import { shallow } from 'enzyme';
2+
import { render } from '@testing-library/react';
33
import Stepper from './Stepper.component';
44

5+
jest.unmock('@talend/design-system');
6+
57
describe('Stepper Component', () => {
68
describe('render', () => {
79
it('should render when there is no errors in the steps', () => {
@@ -15,12 +17,12 @@ describe('Stepper Component', () => {
1517
];
1618
const renderActions = jest.fn();
1719
// when
18-
const wrapper = shallow(
20+
const { baseElement } = render(
1921
<Stepper steps={steps} title={title} renderActions={renderActions} />,
2022
);
2123
// then
22-
expect(renderActions).toHaveBeenCalledWith(false);
23-
expect(wrapper.getElement()).toMatchSnapshot();
24+
expect(renderActions).not.toHaveBeenCalledWith();
25+
expect(baseElement).toMatchSnapshot();
2426
});
2527

2628
it('should render when there is an errors in the steps', () => {
@@ -41,14 +43,14 @@ describe('Stepper Component', () => {
4143
];
4244
const renderActions = jest.fn();
4345
// when
44-
const wrapper = shallow(
46+
const { baseElement } = render(
4547
<Stepper steps={steps} title={title} renderActions={renderActions}>
4648
Import successfull
4749
</Stepper>,
4850
);
4951
// then
5052
expect(renderActions).toHaveBeenCalledWith(true);
51-
expect(wrapper.getElement()).toMatchSnapshot();
53+
expect(baseElement).toMatchSnapshot();
5254
});
5355
});
5456
});

packages/components/src/Stepper/Stepper.stories.js

+14-5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@ import React, { useState } from 'react';
22
import { action } from '@storybook/addon-actions';
33
import Action from '../Actions/Action';
44
import Stepper from './Stepper.component';
5+
import {
6+
ButtonPrimary,
7+
ButtonSecondary,
8+
Link,
9+
StackHorizontal,
10+
StackVertical,
11+
} from '@talend/design-system';
512

613
export default {
714
title: 'Messaging & Communication/Stepper',
@@ -13,11 +20,13 @@ function renderActions(isInError) {
1320
return null;
1421
}
1522
return (
16-
<React.Fragment>
17-
<Action label="retry" bsStyle="info" className="btn-inverse button-padding" />
18-
<Action label="edit dataset" bsStyle="info" className="button-padding" />
19-
<Action label="edit connection" bsStyle="info" className="button-padding" />
20-
</React.Fragment>
23+
<StackVertical gap="S" padding="M" align="center">
24+
<StackHorizontal gap="M">
25+
<ButtonPrimary onClick={action('retry')}>Retry</ButtonPrimary>
26+
<ButtonSecondary onClick={action('cancel')}>Cancel</ButtonSecondary>
27+
</StackHorizontal>
28+
<Link href="http://www.google.com">Get the documentation</Link>
29+
</StackVertical>
2130
);
2231
}
2332

0 commit comments

Comments
 (0)