-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support auto migrate your v3 form
- Loading branch information
Showing
16 changed files
with
632 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
transforms/__testfixtures__/v3-Form-to-FieldForm/form-item.input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { Form } from 'antd'; | ||
|
||
const input = <input />; | ||
|
||
ReactDOM.render( | ||
<div> | ||
<Form.Item> | ||
{getFieldDecorator('field1', { | ||
rules: [{ required: true }] | ||
})(<input style={{ width: 100 }} />)} | ||
</Form.Item> | ||
<Form.Item> | ||
{getFieldDecorator('field2', { | ||
rules: [{ required: true }] | ||
})(input)} | ||
</Form.Item> | ||
</div>, | ||
mountNode | ||
); |
15 changes: 15 additions & 0 deletions
15
transforms/__testfixtures__/v3-Form-to-FieldForm/form-item.output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { Form } from 'antd'; | ||
|
||
const input = <input />; | ||
|
||
ReactDOM.render( | ||
<div> | ||
<Form.Item name='field1' rules={[{ required: true }]}> | ||
<input style={{ width: 100 }} /> | ||
</Form.Item> | ||
<Form.Item name='field2' rules={[{ required: true }]}> | ||
{input} | ||
</Form.Item> | ||
</div>, | ||
mountNode | ||
); |
19 changes: 19 additions & 0 deletions
19
transforms/__testfixtures__/v3-Form-to-FieldForm/getFieldDecorator.input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { Form } from 'antd'; | ||
|
||
const input = <input />; | ||
|
||
ReactDOM.render( | ||
<div> | ||
<div> | ||
{getFieldDecorator('field1', { | ||
rules: [{ required: true }] | ||
})(<input style={{ width: 100 }} />)} | ||
</div> | ||
<div> | ||
{getFieldDecorator('field2', { | ||
rules: [{ required: true }] | ||
})(input)} | ||
</div> | ||
</div>, | ||
mountNode | ||
); |
15 changes: 15 additions & 0 deletions
15
transforms/__testfixtures__/v3-Form-to-FieldForm/getFieldDecorator.output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { Form } from 'antd'; | ||
|
||
const input = <input />; | ||
|
||
ReactDOM.render( | ||
<div> | ||
<div> | ||
<Form.Item noStyle name='field1' rules={[{ required: true }]}><input style={{ width: 100 }} /></Form.Item> | ||
</div> | ||
<div> | ||
<Form.Item noStyle name='field2' rules={[{ required: true }]}>{input}</Form.Item> | ||
</div> | ||
</div>, | ||
mountNode | ||
); |
18 changes: 18 additions & 0 deletions
18
transforms/__testfixtures__/v3-Form-to-FieldForm/remove-useless.input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Form, Icon as LegacyIcon } from '@ant-design/compatible'; | ||
|
||
class AntForm extends React.Component { | ||
render() { | ||
return ( | ||
<Form> | ||
<Form.Item> | ||
{getFieldDecorator('field1', { | ||
rules: [{ required: true }], | ||
initialValue: 'antd' | ||
})(<input style={{ width: 100 }} />)} | ||
</Form.Item> | ||
</Form> | ||
); | ||
} | ||
} | ||
|
||
export default Form.create({})(AntForm); |
19 changes: 19 additions & 0 deletions
19
transforms/__testfixtures__/v3-Form-to-FieldForm/remove-useless.output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { Form } from 'antd'; | ||
import { Icon as LegacyIcon } from '@ant-design/compatible'; | ||
|
||
class AntForm extends React.Component { | ||
render() { | ||
return ( | ||
<Form | ||
initialValue={{ | ||
field1: 'antd' | ||
}}> | ||
<Form.Item name='field1' rules={[{ required: true }]}> | ||
<input style={{ width: 100 }} /> | ||
</Form.Item> | ||
</Form> | ||
); | ||
} | ||
} | ||
|
||
export default AntForm; |
20 changes: 20 additions & 0 deletions
20
transforms/__testfixtures__/v3-Form-to-FieldForm/rename-formitem.input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Form } from 'antd'; | ||
import { FormItem } from 'components'; | ||
|
||
const input = <input />; | ||
|
||
ReactDOM.render( | ||
<div> | ||
<FormItem> | ||
{getFieldDecorator('field1', { | ||
rules: [{ required: true }] | ||
})(<input style={{ width: 100 }} />)} | ||
</FormItem> | ||
<FormItem> | ||
{getFieldDecorator('field2', { | ||
rules: [{ required: true }] | ||
})(input)} | ||
</FormItem> | ||
</div>, | ||
mountNode | ||
); |
16 changes: 16 additions & 0 deletions
16
transforms/__testfixtures__/v3-Form-to-FieldForm/rename-formitem.output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { Form } from 'antd'; | ||
import { FormItem } from 'components'; | ||
|
||
const input = <input />; | ||
|
||
ReactDOM.render( | ||
<div> | ||
<FormItem name='field1' rules={[{ required: true }]}> | ||
<input style={{ width: 100 }} /> | ||
</FormItem> | ||
<FormItem name='field2' rules={[{ required: true }]}> | ||
{input} | ||
</FormItem> | ||
</div>, | ||
mountNode | ||
); |
30 changes: 30 additions & 0 deletions
30
transforms/__testfixtures__/v3-Form-to-FieldForm/wrapper-form.input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { Form } from 'antd'; | ||
|
||
const input = <input />; | ||
|
||
const outerForm = ( | ||
<Form.Item> | ||
{getFieldDecorator('outerform', { | ||
initialValue: 'outer' | ||
})(<input />)} | ||
</Form.Item> | ||
); | ||
|
||
ReactDOM.render( | ||
<Form> | ||
<Form.Item> | ||
{getFieldDecorator('field1', { | ||
rules: [{ required: true }], | ||
initialValue: 'antd' | ||
})(<input style={{ width: 100 }} />)} | ||
</Form.Item> | ||
<Form.Item> | ||
{getFieldDecorator(field2, { | ||
rules: [{ required: true }], | ||
initialValue: 'antd-1' | ||
})(input)} | ||
</Form.Item> | ||
{outerForm} | ||
</Form>, | ||
mountNode | ||
); |
27 changes: 27 additions & 0 deletions
27
transforms/__testfixtures__/v3-Form-to-FieldForm/wrapper-form.output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { Form } from 'antd'; | ||
|
||
const input = <input />; | ||
|
||
const outerForm = ( | ||
<Form.Item name='outerform'> | ||
<input /> | ||
</Form.Item> | ||
); | ||
|
||
ReactDOM.render( | ||
<Form | ||
initialValue={{ | ||
outerform: 'outer', | ||
field1: 'antd', | ||
[field2]: 'antd-1' | ||
}}> | ||
<Form.Item name='field1' rules={[{ required: true }]}> | ||
<input style={{ width: 100 }} /> | ||
</Form.Item> | ||
<Form.Item name={field2} rules={[{ required: true }]}> | ||
{input} | ||
</Form.Item> | ||
{outerForm} | ||
</Form>, | ||
mountNode | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
jest.mock('../v3-Form-to-FieldForm', () => { | ||
return Object.assign(require.requireActual('../v3-Form-to-FieldForm'), { | ||
parser: 'babylon', | ||
}); | ||
}); | ||
|
||
const tests = [ | ||
'getFieldDecorator', | ||
'form-item', | ||
'remove-useless', | ||
'wrapper-form', | ||
{ | ||
cmd: 'rename-formitem', | ||
options: { | ||
formitem: 'FormItem', | ||
}, | ||
}, | ||
]; | ||
|
||
const defineTest = require('jscodeshift/dist/testUtils').defineTest; | ||
|
||
const testUnit = 'v3-Form-to-FieldForm'; | ||
|
||
describe(testUnit, () => { | ||
tests.forEach(test => { | ||
const cmd = typeof test === 'string' ? test : test.cmd; | ||
return defineTest( | ||
__dirname, | ||
testUnit, | ||
{ | ||
antdPkgNames: ['antd', '@forked/antd', '@alipay/bigfish/antd'].join( | ||
',', | ||
), | ||
...test.options, | ||
}, | ||
`${testUnit}/${cmd}`, | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.