Skip to content

Commit 30a7d5e

Browse files
committed
chore: start trying a refactor
1 parent 3cf7857 commit 30a7d5e

File tree

6 files changed

+163
-27
lines changed

6 files changed

+163
-27
lines changed

packages/forms/package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,13 @@
5757
},
5858
"dependencies": {
5959
"classnames": "^2.2.5",
60+
"json-schema-form-core": "^1.0.0-alpha.2",
6061
"keycode": "^2.1.8",
6162
"react-autowhatever": "^7.0.0",
62-
"react-jsonschema-form": "^0.42.0"
63+
"react-jsonschema-form": "^0.42.0",
64+
"react-redux": "^5.0.4",
65+
"redux-form": "^6.6.3",
66+
"tv4": "^1.3.0"
6367
},
6468
"peerDependencies": {
6569
"react": "^15.4.0",
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import React, { PropTypes } from 'react';
2+
import { Field, reduxForm } from 'redux-form';
3+
4+
import {
5+
schemaDefaults,
6+
jsonref,
7+
merge,
8+
traverseSchema,
9+
traverseForm,
10+
} from 'json-schema-form-core';
11+
12+
class UIForm extends React.Component {
13+
14+
render() {
15+
const { jsonSchema, uiSchema, properties } = this.props.data || {};
16+
debugger;
17+
schemaDefaults;
18+
jsonref;
19+
merge;
20+
traverseSchema;
21+
traverseForm;
22+
return (
23+
<form onSubmit={this.props.handleSubmit}>
24+
<div>
25+
<label htmlFor="firstName">First Name</label>
26+
<Field name="firstName" component="input" type="text" />
27+
</div>
28+
<div>
29+
<label htmlFor="lastName">Last Name</label>
30+
<Field name="lastName" component="input" type="text" />
31+
</div>
32+
<div>
33+
<label htmlFor="email">Email</label>
34+
<Field name="email" component="input" type="email" />
35+
</div>
36+
<button type="submit">Submit</button>
37+
</form>
38+
);
39+
}
40+
}
41+
42+
UIForm.propTypes = {
43+
handleSubmit: PropTypes.func.isRequired,
44+
};
45+
46+
export default reduxForm({
47+
form: 'form' // a unique name for this form
48+
})(UIForm);
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import React from 'react';
2+
import { shallow } from 'enzyme';
3+
4+
import UIForm from './UIForm.component';
5+
6+
describe('UIForm', () => {
7+
it('should render', () => {
8+
const wrapper = shallow(
9+
<UIForm />
10+
);
11+
expect(wrapper).toMatchSnapshot();
12+
});
13+
});

packages/forms/src/UIForm/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import UIForm from './UIForm.component';
2+
3+
export default UIForm;

packages/forms/stories/index.js

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,44 @@
11
import React from 'react';
22
import ReactDOM from 'react-dom';
33
import a11y from 'react-a11y';
4-
4+
import { Provider } from 'react-redux';
55
import { storiesOf, action } from '@kadira/storybook';
66
import { withKnobs, object } from '@kadira/storybook-addon-knobs';
77

88
import Well from 'react-bootstrap/lib/Well';
99
import IconsProvider from 'react-talend-components/lib/IconsProvider';
1010

11-
import Form from '../src/Form';
11+
12+
import { createStore, combineReducers } from 'redux';
13+
import { reducer as formReducer } from 'redux-form';
14+
15+
const reducers = {
16+
// ... your other reducers here ...
17+
form: formReducer, // <---- Mounted at 'form'
18+
};
19+
20+
const reducer = combineReducers(reducers);
21+
const store = createStore(reducer);
22+
23+
import Form from '../src/UIForm';
1224

1325
a11y(ReactDOM);
1426

1527
const decoratedStories = storiesOf('Form', module)
1628
.addDecorator(withKnobs)
1729
.addDecorator(story => (
18-
<div className="container-fluid">
19-
<div
20-
className="col-md-offset-1 col-md-10"
21-
style={{ marginTop: '20px', marginBottom: '20px' }}
22-
>
23-
<Well>
24-
{story()}
25-
</Well>
30+
<Provider store={store}>
31+
<div className="container-fluid">
32+
<div
33+
className="col-md-offset-1 col-md-10"
34+
style={{ marginTop: '20px', marginBottom: '20px' }}
35+
>
36+
<Well>
37+
{story()}
38+
</Well>
39+
</div>
2640
</div>
27-
</div>
41+
</Provider>
2842
));
2943

3044
const capitalizeFirstLetter =

packages/forms/yarn.lock

Lines changed: 69 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1256,9 +1256,9 @@ bootstrap-sass@^3.3.7:
12561256
version "3.3.7"
12571257
resolved "https://registry.yarnpkg.com/bootstrap-sass/-/bootstrap-sass-3.3.7.tgz#6596c7ab40f6637393323ab0bc80d064fc630498"
12581258

1259-
bootstrap-talend-theme@^0.71.0:
1260-
version "0.71.0"
1261-
resolved "https://registry.yarnpkg.com/bootstrap-talend-theme/-/bootstrap-talend-theme-0.71.0.tgz#b6946f3d5f9742cbefd7f71d3542c341c887ec7f"
1259+
bootstrap-talend-theme@^0.72.2:
1260+
version "0.72.2"
1261+
resolved "https://registry.yarnpkg.com/bootstrap-talend-theme/-/bootstrap-talend-theme-0.72.2.tgz#d164a2d5cc39538b40bf3918b9e0738184ae9a0b"
12621262
dependencies:
12631263
bootstrap-sass "^3.3.7"
12641264

@@ -1692,6 +1692,13 @@ cpx@^1.5.0:
16921692
shell-quote "^1.6.1"
16931693
subarg "^1.0.0"
16941694

1695+
create-react-class@^15.5.1:
1696+
version "15.5.2"
1697+
resolved "https://registry.yarnpkg.com/create-react-class/-/create-react-class-15.5.2.tgz#6a8758348df660b88326a0e764d569f274aad681"
1698+
dependencies:
1699+
fbjs "^0.8.9"
1700+
object-assign "^4.1.1"
1701+
16951702
cross-spawn@^3.0.0:
16961703
version "3.0.1"
16971704
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-3.0.1.tgz#1256037ecb9f0c5f79e3d6ef135e30770184b982"
@@ -2101,6 +2108,10 @@ es5-shim@^4.5.9:
21012108
version "4.5.9"
21022109
resolved "https://registry.yarnpkg.com/es5-shim/-/es5-shim-4.5.9.tgz#2a1e2b9e583ff5fed0c20a3ee2cbf3f75230a5c0"
21032110

2111+
es6-error@^4.0.0:
2112+
version "4.0.2"
2113+
resolved "https://registry.yarnpkg.com/es6-error/-/es6-error-4.0.2.tgz#eec5c726eacef51b7f6b73c20db6e1b13b069c98"
2114+
21042115
es6-iterator@2, es6-iterator@^2.0.1, es6-iterator@~2.0.1:
21052116
version "2.0.1"
21062117
resolved "https://registry.yarnpkg.com/es6-iterator/-/es6-iterator-2.0.1.tgz#8e319c9f0453bf575d374940a655920e59ca5512"
@@ -2469,7 +2480,7 @@ fb-watchman@^2.0.0:
24692480
dependencies:
24702481
bser "^2.0.0"
24712482

2472-
fbjs@^0.8.1, fbjs@^0.8.4:
2483+
fbjs@^0.8.1, fbjs@^0.8.4, fbjs@^0.8.9:
24732484
version "0.8.12"
24742485
resolved "https://registry.yarnpkg.com/fbjs/-/fbjs-0.8.12.tgz#10b5d92f76d45575fd63a217d4ea02bea2f8ed04"
24752486
dependencies:
@@ -2861,7 +2872,7 @@ hoek@2.x.x:
28612872
version "2.16.3"
28622873
resolved "https://registry.yarnpkg.com/hoek/-/hoek-2.16.3.tgz#20bb7403d3cea398e91dc4710a8ff1b8274a25ed"
28632874

2864-
hoist-non-react-statics@1.x.x, hoist-non-react-statics@^1.2.0:
2875+
hoist-non-react-statics@1.x.x, hoist-non-react-statics@^1.0.3, hoist-non-react-statics@^1.2.0:
28652876
version "1.2.0"
28662877
resolved "https://registry.yarnpkg.com/hoist-non-react-statics/-/hoist-non-react-statics-1.2.0.tgz#aa448cf0986d55cc40773b17174b7dd066cb7cfb"
28672878

@@ -3013,7 +3024,7 @@ interpret@^1.0.0:
30133024
version "1.0.2"
30143025
resolved "https://registry.yarnpkg.com/interpret/-/interpret-1.0.2.tgz#f4f623f0bb7122f15f5717c8e254b8161b5c5b2d"
30153026

3016-
invariant@2.x.x, invariant@^2.1.0, invariant@^2.2.0, invariant@^2.2.1:
3027+
invariant@2.x.x, invariant@^2.0.0, invariant@^2.1.0, invariant@^2.2.0, invariant@^2.2.1, invariant@^2.2.2:
30173028
version "2.2.2"
30183029
resolved "https://registry.yarnpkg.com/invariant/-/invariant-2.2.2.tgz#9e1f56ac0acdb6bf303306f338be3b204ae60360"
30193030
dependencies:
@@ -3156,6 +3167,10 @@ is-primitive@^2.0.0:
31563167
version "2.0.0"
31573168
resolved "https://registry.yarnpkg.com/is-primitive/-/is-primitive-2.0.0.tgz#207bab91638499c07b2adf240a41a87210034575"
31583169

3170+
is-promise@^2.1.0:
3171+
version "2.1.0"
3172+
resolved "https://registry.yarnpkg.com/is-promise/-/is-promise-2.1.0.tgz#79a2a9ece7f096e80f36d2b2f3bc16c1ff4bf3fa"
3173+
31593174
is-property@^1.0.0:
31603175
version "1.0.2"
31613176
resolved "https://registry.yarnpkg.com/is-property/-/is-property-1.0.2.tgz#57fe1c4e48474edd65b09911f26b1cd4095dda84"
@@ -3749,6 +3764,10 @@ json-loader@^0.5.4:
37493764
version "0.5.4"
37503765
resolved "https://registry.yarnpkg.com/json-loader/-/json-loader-0.5.4.tgz#8baa1365a632f58a3c46d20175fc6002c96e37de"
37513766

3767+
json-schema-form-core@^1.0.0-alpha.2:
3768+
version "1.0.0-alpha.2"
3769+
resolved "https://registry.yarnpkg.com/json-schema-form-core/-/json-schema-form-core-1.0.0-alpha.2.tgz#60566287e5f3fb8d2ccb1337dca5d3b80c3391c9"
3770+
37523771
json-schema@0.2.3:
37533772
version "0.2.3"
37543773
resolved "https://registry.yarnpkg.com/json-schema/-/json-schema-0.2.3.tgz#b480c892e59a2f05954ce727bd3f2a4e882f9e13"
@@ -3871,7 +3890,7 @@ locate-path@^2.0.0:
38713890
p-locate "^2.0.0"
38723891
path-exists "^3.0.0"
38733892

3874-
lodash-es@^4.2.1:
3893+
lodash-es@^4.17.3, lodash-es@^4.2.0, lodash-es@^4.2.1:
38753894
version "4.17.4"
38763895
resolved "https://registry.yarnpkg.com/lodash-es/-/lodash-es-4.17.4.tgz#dcc1d7552e150a0640073ba9cb31d70f032950e7"
38773896

@@ -4068,7 +4087,7 @@ lodash.uniq@^4.3.0:
40684087
version "4.5.0"
40694088
resolved "https://registry.yarnpkg.com/lodash.uniq/-/lodash.uniq-4.5.0.tgz#d0225373aeb652adc1bc82e4945339a842754773"
40704089

4071-
lodash@4.x.x, lodash@^4.0.0, lodash@^4.0.1, lodash@^4.14.0, lodash@^4.17.2, lodash@^4.17.4, lodash@^4.2.0, lodash@^4.2.1, lodash@^4.3.0:
4090+
lodash@4.x.x, lodash@^4.0.0, lodash@^4.0.1, lodash@^4.14.0, lodash@^4.17.2, lodash@^4.17.3, lodash@^4.17.4, lodash@^4.2.0, lodash@^4.2.1, lodash@^4.3.0:
40724091
version "4.17.4"
40734092
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.4.tgz#78203a4d1c328ae1d86dca6460e369b57f4055ae"
40744093

@@ -4500,7 +4519,7 @@ object-assign@^3.0.0:
45004519
version "3.0.0"
45014520
resolved "https://registry.yarnpkg.com/object-assign/-/object-assign-3.0.0.tgz#9bedd5ca0897949bca47e7ff408062d549f587f2"
45024521

4503-
object-assign@^4.0.1, object-assign@^4.1.0:
4522+
object-assign@^4.0.1, object-assign@^4.1.0, object-assign@^4.1.1:
45044523
version "4.1.1"
45054524
resolved "https://registry.yarnpkg.com/object-assign/-/object-assign-4.1.1.tgz#2109adc7965887cfc05cbbd442cac8bfbb360863"
45064525

@@ -5057,6 +5076,12 @@ promise@^7.1.1:
50575076
dependencies:
50585077
asap "~2.0.3"
50595078

5079+
prop-types@^15.0.0, prop-types@^15.5.6:
5080+
version "15.5.8"
5081+
resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.5.8.tgz#6b7b2e141083be38c8595aa51fc55775c7199394"
5082+
dependencies:
5083+
fbjs "^0.8.9"
5084+
50605085
proxy-addr@~1.1.3:
50615086
version "1.1.4"
50625087
resolved "https://registry.yarnpkg.com/proxy-addr/-/proxy-addr-1.1.4.tgz#27e545f6960a44a627d9b44467e35c1b6b4ce2f3"
@@ -5283,6 +5308,18 @@ react-prop-types@^0.4.0:
52835308
dependencies:
52845309
warning "^3.0.0"
52855310

5311+
react-redux@^5.0.4:
5312+
version "5.0.4"
5313+
resolved "https://registry.yarnpkg.com/react-redux/-/react-redux-5.0.4.tgz#1563babadcfb2672f57f9ceaa439fb16bf85d55b"
5314+
dependencies:
5315+
create-react-class "^15.5.1"
5316+
hoist-non-react-statics "^1.0.3"
5317+
invariant "^2.0.0"
5318+
lodash "^4.2.0"
5319+
lodash-es "^4.2.0"
5320+
loose-envify "^1.1.0"
5321+
prop-types "^15.0.0"
5322+
52865323
react-simple-di@^1.2.0:
52875324
version "1.2.0"
52885325
resolved "https://registry.yarnpkg.com/react-simple-di/-/react-simple-di-1.2.0.tgz#dde0e5bf689f391ef2ab02c9043b213fe239c6d0"
@@ -5296,9 +5333,9 @@ react-stubber@^1.0.0:
52965333
dependencies:
52975334
babel-runtime "^6.5.0"
52985335

5299-
react-talend-components@^0.71.0:
5300-
version "0.71.0"
5301-
resolved "https://registry.yarnpkg.com/react-talend-components/-/react-talend-components-0.71.0.tgz#dec2f1d5c14669e89460a1dbf56821124d340f9b"
5336+
react-talend-components@^0.72.2:
5337+
version "0.72.2"
5338+
resolved "https://registry.yarnpkg.com/react-talend-components/-/react-talend-components-0.72.2.tgz#9426e165996359ecc82697ce1083157804e98cb1"
53025339
dependencies:
53035340
lodash "^4.17.4"
53045341
react-autowhatever "^7.0.0"
@@ -5428,6 +5465,19 @@ reduce-function-call@^1.0.1:
54285465
dependencies:
54295466
balanced-match "^0.4.2"
54305467

5468+
redux-form@^6.6.3:
5469+
version "6.6.3"
5470+
resolved "https://registry.yarnpkg.com/redux-form/-/redux-form-6.6.3.tgz#62362654f2214c83a8f9fcb8313702bb46f92205"
5471+
dependencies:
5472+
deep-equal "^1.0.1"
5473+
es6-error "^4.0.0"
5474+
hoist-non-react-statics "^1.2.0"
5475+
invariant "^2.2.2"
5476+
is-promise "^2.1.0"
5477+
lodash "^4.17.3"
5478+
lodash-es "^4.17.3"
5479+
prop-types "^15.5.6"
5480+
54315481
redux@^3.5.2:
54325482
version "3.6.0"
54335483
resolved "https://registry.yarnpkg.com/redux/-/redux-3.6.0.tgz#887c2b3d0b9bd86eca2be70571c27654c19e188d"
@@ -6011,9 +6061,9 @@ table@^3.7.8:
60116061
slice-ansi "0.0.4"
60126062
string-width "^2.0.0"
60136063

6014-
talend-icons@^0.71.0:
6015-
version "0.71.0"
6016-
resolved "https://registry.yarnpkg.com/talend-icons/-/talend-icons-0.71.0.tgz#d52c632180d35385a6ae382dfb59e7f56ccb9ac2"
6064+
talend-icons@^0.72.2:
6065+
version "0.72.2"
6066+
resolved "https://registry.yarnpkg.com/talend-icons/-/talend-icons-0.72.2.tgz#4bdabf0091695c6ede2ecdb218c4fb0cb66b8da9"
60176067

60186068
tapable@^0.1.8, tapable@~0.1.8:
60196069
version "0.1.10"
@@ -6126,6 +6176,10 @@ tunnel-agent@^0.6.0:
61266176
dependencies:
61276177
safe-buffer "^5.0.1"
61286178

6179+
tv4@^1.3.0:
6180+
version "1.3.0"
6181+
resolved "https://registry.yarnpkg.com/tv4/-/tv4-1.3.0.tgz#d020c846fadd50c855abb25ebaecc68fc10f7963"
6182+
61296183
tweetnacl@^0.14.3, tweetnacl@~0.14.0:
61306184
version "0.14.5"
61316185
resolved "https://registry.yarnpkg.com/tweetnacl/-/tweetnacl-0.14.5.tgz#5ae68177f192d4456269d108afa93ff8743f4f64"

0 commit comments

Comments
 (0)