Skip to content

Commit 8fab947

Browse files
committed
breaking(pf3): wizard use name instead of stepKey
1 parent 9010f89 commit 8fab947

File tree

6 files changed

+199
-120
lines changed

6 files changed

+199
-120
lines changed

packages/pf3-component-mapper/demo/demo-schemas/wizard-schema.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ const wizardSchema = {
1212
{
1313
title: 'Get started with adding source',
1414
name: 'step-1',
15-
stepKey: 1,
1615
nextStep: {
1716
when: 'source-type',
1817
stepMapper: {
@@ -55,8 +54,7 @@ const wizardSchema = {
5554
},
5655
{
5756
title: 'Configure AWS',
58-
name: 'step-2',
59-
stepKey: 'aws',
57+
name: 'aws',
6058
nextStep: 'summary',
6159
fields: [
6260
{
@@ -67,9 +65,8 @@ const wizardSchema = {
6765
]
6866
},
6967
{
70-
stepKey: 'google',
68+
name: 'google',
7169
title: 'Configure google',
72-
name: 'step-3',
7370
nextStep: 'summary',
7471
fields: [
7572
{
@@ -88,7 +85,6 @@ const wizardSchema = {
8885
label: 'Summary'
8986
}
9087
],
91-
stepKey: 'summary',
9288
name: 'summary'
9389
}
9490
]

packages/pf3-component-mapper/src/components/button.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import React from 'react';
22
import PropTypes from 'prop-types';
33
import { Button as PFButton } from 'patternfly-react';
44

5-
export const Button = ({ label, variant, dataType, validate, ...rest }) => (
5+
export const Button = ({ label, variant, dataType, validate, children, ...rest }) => (
66
<PFButton bsStyle={variant} {...rest}>
7-
{label}
7+
{label || children}
88
</PFButton>
99
);
1010

@@ -13,7 +13,8 @@ Button.propTypes = {
1313
variant: PropTypes.string,
1414
className: PropTypes.string,
1515
dataType: PropTypes.any, // should be inside inner props or something
16-
validate: PropTypes.any // should be inside inner props or something
16+
validate: PropTypes.any, // should be inside inner props or something
17+
children: PropTypes.any
1718
};
1819

1920
export default Button;

packages/pf3-component-mapper/src/components/wizard.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const defaultButtonLabels = {
1515
const Wizard = ({ title, buttonLabels, stepsInfo, fields, inModal }) => {
1616
const formOptions = useFormApi();
1717

18-
const [activeStep, setActiveStep] = useState(fields[0].stepKey);
18+
const [activeStep, setActiveStep] = useState(fields[0].name);
1919
const [prevSteps, setPrevSteps] = useState([]);
2020

2121
const handleNext = (nextStep) => {
@@ -24,13 +24,14 @@ const Wizard = ({ title, buttonLabels, stepsInfo, fields, inModal }) => {
2424
};
2525

2626
const handlePrev = () => {
27-
const newSteps = prevSteps.slice(0, Math.max(prevSteps.length - 1, 1));
27+
setActiveStep(prevSteps[prevSteps.length - 1]);
2828

29-
setActiveStep(newSteps[newSteps.length - 1]);
29+
const newSteps = prevSteps;
30+
newSteps.pop();
3031
setPrevSteps(newSteps);
3132
};
3233

33-
const findCurrentStep = (activeStep) => fields.find(({ stepKey }) => stepKey === activeStep);
34+
const findCurrentStep = (activeStep) => fields.find(({ name }) => name === activeStep);
3435

3536
const findActiveFields = (visitedSteps) =>
3637
visitedSteps.map((key) => findCurrentStep(key).fields.map(({ name }) => name)).reduce((acc, curr) => curr.concat(acc.map((item) => item)), []);
@@ -94,14 +95,13 @@ Wizard.propTypes = {
9495
inModal: PropTypes.bool,
9596
fields: PropTypes.arrayOf(
9697
PropTypes.shape({
97-
stepKey: PropTypes.string
98+
name: PropTypes.string
9899
})
99100
).isRequired
100101
};
101102

102103
Wizard.defaultProps = {
103104
title: undefined,
104-
buttonLabels: defaultButtonLabels,
105105
stepsInfo: undefined,
106106
inModal: false
107107
};

packages/pf3-component-mapper/src/components/wizard/step-buttons.js

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,37 @@ import React from 'react';
22
import PropTypes from 'prop-types';
33
import Button from '../button';
44
import { Icon, Wizard } from 'patternfly-react';
5-
import { useFieldApi } from '@data-driven-forms/react-form-renderer';
5+
import { useFieldApi, useFormApi } from '@data-driven-forms/react-form-renderer';
66

77
import './button.scss';
88

9-
const SimpleNext = ({ next, valid, handleNext, submit, buttonLabels }) => (
10-
<Button className="margin-left-3" bsStyle="primary" type="button" onClick={() => (valid ? handleNext(next) : submit())}>
11-
{buttonLabels.next}
12-
<Icon type="fa" name="angle-right" />
13-
</Button>
14-
);
9+
const SimpleNext = ({ next, handleNext, submit, buttonLabels, disabled }) => {
10+
const { valid } = useFormApi();
11+
12+
return (
13+
<Button className="margin-left-3" bsStyle="primary" type="button" onClick={() => (valid ? handleNext(next) : submit())} disabled={disabled}>
14+
{buttonLabels.next}
15+
<Icon type="fa" name="angle-right" />
16+
</Button>
17+
);
18+
};
1519

1620
SimpleNext.propTypes = {
1721
next: PropTypes.string,
18-
valid: PropTypes.bool,
1922
handleNext: PropTypes.func.isRequired,
2023
submit: PropTypes.func.isRequired,
21-
buttonLabels: PropTypes.object.isRequired
24+
buttonLabels: PropTypes.object.isRequired,
25+
disabled: PropTypes.bool
2226
};
2327

2428
const ConditionalNext = ({ nextStep, ...rest }) => {
2529
const {
2630
input: { value }
2731
} = useFieldApi({ name: nextStep.when, subscription: { value: true } });
28-
return <SimpleNext next={nextStep.stepMapper[value]} {...rest} />;
32+
33+
const next = nextStep.stepMapper[value];
34+
35+
return <SimpleNext next={next} {...rest} disabled={!next} />;
2936
};
3037

3138
ConditionalNext.propTypes = {

0 commit comments

Comments
 (0)