Skip to content

Commit 2f004f3

Browse files
committed
Add migration guide to documentation
1 parent 0740fd5 commit 2f004f3

File tree

2 files changed

+156
-0
lines changed

2 files changed

+156
-0
lines changed
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
import Grid from '@material-ui/core/Grid'
2+
import RawComponent from '@docs/raw-component';
3+
import RouterLink from 'next/link';
4+
import Link from '@material-ui/core/Link';
5+
6+
import ListOfContents from '../../src/helpers/list-of-contents';
7+
8+
<Grid container item>
9+
<Grid item xs={12} md={10}>
10+
11+
# Migration guide from 1.x to 2.x
12+
13+
The release of version 2 brings many new features, that as we hope you will find useful and you will like them.
14+
Also, we took this release as an opportunity to fix mistakes we did during the initial development and to remove some obsolete stuff, that is no longer useful.
15+
Major themes are using of React hooks, so update your React before you will continue, and giving more freedom to you how to customize the form.
16+
There are also major enhancements bringing more features to schemas not stored in JavaScript, as the action mapper and validator mapper.
17+
Thank you for your understanding.
18+
19+
## Details
20+
21+
### General rules
22+
23+
- All JSON schemas should remain almost the same
24+
25+
### PF4/PF3/MUI Mapper
26+
27+
- formFieldsMapper was renamed to componentMapper
28+
- Components can be imported separately to create only a subset of full component mapper
29+
30+
### Removed 'treshold' option
31+
32+
- Due to a typo, it was possible to use key treshold as an option in some validators, this option is now disabled. Use only threshold.
33+
34+
### Form Template
35+
36+
- layoutMapper removed - instead of it use FormTemplate
37+
- All props related to form buttons are now removed, use them in you FormTemplate
38+
- showFormControls
39+
- buttonOrder
40+
- disableSubmit
41+
- buttonClassName
42+
- renderFormButtons
43+
- buttonsLabels
44+
- => All these props are now managed by mapper's form templates!
45+
46+
- FormTemplate receives these props:
47+
- formFields : form fields
48+
- schema : provides access to schema.title, schema.description and everything else
49+
- Default templates (it is a function!):
50+
51+
```jsx
52+
import { FormTemplate } from '@data-driven-forms/pf4-component-mapper'
53+
54+
<FormRenderer {...} FormTemplate={props => <FormTemplate {...props} showFormControls={false} />
55+
```
56+
57+
- Options - see removed props above
58+
59+
### layoutComponents removed
60+
61+
- layoutComponents constants have been removed. Please do not use them.
62+
63+
### formOptions props removed
64+
65+
- formOptions as a prop was removed, instead of it use useFormApi hook or you can get formOptions from the rendererContext
66+
67+
```jsx
68+
69+
import { useFormApi } from '@data-driven-forms/react-form-renderer';
70+
71+
const Component = (props) => {
72+
const formOptions = useFormApi();
73+
...
74+
}
75+
```
76+
77+
78+
### formSpy is exported
79+
80+
- formSpyProvider is no longer provided as a prop.
81+
- Use direct import instead of it:
82+
83+
```jsx
84+
import { FormSpy } from '@data-driven-forms/react-form-renderer';
85+
```
86+
87+
### fieldArray is exported
88+
89+
- fieldArrayProvider is no longer provided as a prop.
90+
- Use direct import instead of it:
91+
92+
```jsx
93+
import { FieldArray } from '@data-driven-forms/react-form-renderer';
94+
```
95+
96+
### onStateUpdate removed, replaced by debug
97+
98+
- onStateUpdate prop is removed from the renderer, instead of it use debug (please see <https://final-form.org/docs/react-final-form/types/FormProps#debug>)
99+
100+
```jsx
101+
<FormRenderer {...} debug={console.log} />
102+
```
103+
104+
- In custom component, simulate this prop with using of formSpy
105+
106+
```jsx
107+
import { FormSpy } from '@data-driven-forms/react-form-renderer';
108+
109+
{onStateUpdate && <FormSpy onChange={onStateUpdate} />}
110+
```
111+
112+
### FieldProvider changed
113+
114+
- FieldProvider is no longer wrapping basic components and you cannot access him through props, instead of it use hook:
115+
116+
```jsx
117+
import { useFieldApi } from '@data-driven-forms/react-form-renderer';
118+
119+
...
120+
121+
const { input, isDisabled, label, helperText, description, meta } = useFieldApi(props);
122+
```
123+
124+
- This hook accepts all props and returns them with input and meta included.
125+
- Don't forget to pass a type, for special types as 'checkbox'
126+
127+
128+
### formFieldsMapper renamed to componentMapper
129+
130+
- There is no formFieldsMapper anymore, please use componentMapper
131+
132+
```jsx
133+
import { componentMapper } from '@data-driven-forms/pf4-component-mapper'
134+
135+
<FormRenderer {...} componentMapper={componentMapper} />
136+
```
137+
138+
### Component types
139+
140+
- Removed the "-field" affix from the constants values
141+
- "select-field" -> "select"
142+
- removed duplicate constants SELECT_COMPONENT etc.
143+
144+
### PF4/PF3/MUI Wizard doesn't use 'stepKey' anymore
145+
146+
- stepKey prop is replaced by name
147+
148+
</Grid>
149+
<Grid item xs={false} md={2}>
150+
<ListOfContents file="renderer/migration-guide" />
151+
</Grid>
152+
</Grid>

packages/react-renderer-demo/src/app/src/components/navigation/documentation-pages.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,5 +62,9 @@ export const docs = [
6262
{
6363
component: 'field-array',
6464
linkText: 'FieldArray Provider'
65+
},
66+
{
67+
component: 'migration-guide',
68+
linkText: 'Migration guide 1.x to 2.x'
6569
}
6670
];

0 commit comments

Comments
 (0)