From 9013edc89eefad4c7eca88bf65696574f4892980 Mon Sep 17 00:00:00 2001 From: Jean-Michel FRANCOIS Date: Thu, 27 Apr 2017 09:25:36 +0200 Subject: [PATCH] chore: start trying a refactor --- packages/forms/package.json | 6 +- packages/forms/src/UIForm/UIForm.component.js | 48 +++++++++++ packages/forms/src/UIForm/UIForm.test.js | 13 +++ packages/forms/src/UIForm/index.js | 3 + packages/forms/stories/index.js | 36 +++++--- packages/forms/yarn.lock | 84 +++++++++++++++---- 6 files changed, 163 insertions(+), 27 deletions(-) create mode 100644 packages/forms/src/UIForm/UIForm.component.js create mode 100644 packages/forms/src/UIForm/UIForm.test.js create mode 100644 packages/forms/src/UIForm/index.js diff --git a/packages/forms/package.json b/packages/forms/package.json index e4d5466386d..9ae244537b0 100644 --- a/packages/forms/package.json +++ b/packages/forms/package.json @@ -57,9 +57,13 @@ }, "dependencies": { "classnames": "^2.2.5", + "json-schema-form-core": "^1.0.0-alpha.2", "keycode": "^2.1.8", "react-autowhatever": "^7.0.0", - "react-jsonschema-form": "^0.42.0" + "react-jsonschema-form": "^0.42.0", + "react-redux": "^5.0.4", + "redux-form": "^6.6.3", + "tv4": "^1.3.0" }, "peerDependencies": { "react": "^15.4.0", diff --git a/packages/forms/src/UIForm/UIForm.component.js b/packages/forms/src/UIForm/UIForm.component.js new file mode 100644 index 00000000000..c72294074d9 --- /dev/null +++ b/packages/forms/src/UIForm/UIForm.component.js @@ -0,0 +1,48 @@ +import React, { PropTypes } from 'react'; +import { Field, reduxForm } from 'redux-form'; + +import { + schemaDefaults, + jsonref, + merge, + traverseSchema, + traverseForm, +} from 'json-schema-form-core'; + +class UIForm extends React.Component { + + render() { + const { jsonSchema, uiSchema, properties } = this.props.data || {}; + debugger; + schemaDefaults; + jsonref; + merge; + traverseSchema; + traverseForm; + return ( +
+
+ + +
+
+ + +
+
+ + +
+ +
+ ); + } +} + +UIForm.propTypes = { + handleSubmit: PropTypes.func.isRequired, +}; + +export default reduxForm({ + form: 'form' // a unique name for this form +})(UIForm); diff --git a/packages/forms/src/UIForm/UIForm.test.js b/packages/forms/src/UIForm/UIForm.test.js new file mode 100644 index 00000000000..ceb205da709 --- /dev/null +++ b/packages/forms/src/UIForm/UIForm.test.js @@ -0,0 +1,13 @@ +import React from 'react'; +import { shallow } from 'enzyme'; + +import UIForm from './UIForm.component'; + +describe('UIForm', () => { + it('should render', () => { + const wrapper = shallow( + + ); + expect(wrapper).toMatchSnapshot(); + }); +}); diff --git a/packages/forms/src/UIForm/index.js b/packages/forms/src/UIForm/index.js new file mode 100644 index 00000000000..370245b7ae7 --- /dev/null +++ b/packages/forms/src/UIForm/index.js @@ -0,0 +1,3 @@ +import UIForm from './UIForm.component'; + +export default UIForm; diff --git a/packages/forms/stories/index.js b/packages/forms/stories/index.js index 2f2e790177c..7e0fa2d09c4 100644 --- a/packages/forms/stories/index.js +++ b/packages/forms/stories/index.js @@ -1,30 +1,44 @@ import React from 'react'; import ReactDOM from 'react-dom'; import a11y from 'react-a11y'; - +import { Provider } from 'react-redux'; import { storiesOf, action } from '@kadira/storybook'; import { withKnobs, object } from '@kadira/storybook-addon-knobs'; import Well from 'react-bootstrap/lib/Well'; import IconsProvider from 'react-talend-components/lib/IconsProvider'; -import Form from '../src/Form'; + +import { createStore, combineReducers } from 'redux'; +import { reducer as formReducer } from 'redux-form'; + +const reducers = { + // ... your other reducers here ... + form: formReducer, // <---- Mounted at 'form' +}; + +const reducer = combineReducers(reducers); +const store = createStore(reducer); + +import Form from '../src/UIForm'; a11y(ReactDOM); const decoratedStories = storiesOf('Form', module) .addDecorator(withKnobs) .addDecorator(story => ( -
-
- - {story()} - + +
+
+ + {story()} + +
-
+ )); const capitalizeFirstLetter = diff --git a/packages/forms/yarn.lock b/packages/forms/yarn.lock index cd6edb4052e..98a9021a5e5 100644 --- a/packages/forms/yarn.lock +++ b/packages/forms/yarn.lock @@ -1256,9 +1256,9 @@ bootstrap-sass@^3.3.7: version "3.3.7" resolved "https://registry.yarnpkg.com/bootstrap-sass/-/bootstrap-sass-3.3.7.tgz#6596c7ab40f6637393323ab0bc80d064fc630498" -bootstrap-talend-theme@^0.71.0: - version "0.71.0" - resolved "https://registry.yarnpkg.com/bootstrap-talend-theme/-/bootstrap-talend-theme-0.71.0.tgz#b6946f3d5f9742cbefd7f71d3542c341c887ec7f" +bootstrap-talend-theme@^0.72.2: + version "0.72.2" + resolved "https://registry.yarnpkg.com/bootstrap-talend-theme/-/bootstrap-talend-theme-0.72.2.tgz#d164a2d5cc39538b40bf3918b9e0738184ae9a0b" dependencies: bootstrap-sass "^3.3.7" @@ -1692,6 +1692,13 @@ cpx@^1.5.0: shell-quote "^1.6.1" subarg "^1.0.0" +create-react-class@^15.5.1: + version "15.5.2" + resolved "https://registry.yarnpkg.com/create-react-class/-/create-react-class-15.5.2.tgz#6a8758348df660b88326a0e764d569f274aad681" + dependencies: + fbjs "^0.8.9" + object-assign "^4.1.1" + cross-spawn@^3.0.0: version "3.0.1" resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-3.0.1.tgz#1256037ecb9f0c5f79e3d6ef135e30770184b982" @@ -2101,6 +2108,10 @@ es5-shim@^4.5.9: version "4.5.9" resolved "https://registry.yarnpkg.com/es5-shim/-/es5-shim-4.5.9.tgz#2a1e2b9e583ff5fed0c20a3ee2cbf3f75230a5c0" +es6-error@^4.0.0: + version "4.0.2" + resolved "https://registry.yarnpkg.com/es6-error/-/es6-error-4.0.2.tgz#eec5c726eacef51b7f6b73c20db6e1b13b069c98" + es6-iterator@2, es6-iterator@^2.0.1, es6-iterator@~2.0.1: version "2.0.1" resolved "https://registry.yarnpkg.com/es6-iterator/-/es6-iterator-2.0.1.tgz#8e319c9f0453bf575d374940a655920e59ca5512" @@ -2469,7 +2480,7 @@ fb-watchman@^2.0.0: dependencies: bser "^2.0.0" -fbjs@^0.8.1, fbjs@^0.8.4: +fbjs@^0.8.1, fbjs@^0.8.4, fbjs@^0.8.9: version "0.8.12" resolved "https://registry.yarnpkg.com/fbjs/-/fbjs-0.8.12.tgz#10b5d92f76d45575fd63a217d4ea02bea2f8ed04" dependencies: @@ -2861,7 +2872,7 @@ hoek@2.x.x: version "2.16.3" resolved "https://registry.yarnpkg.com/hoek/-/hoek-2.16.3.tgz#20bb7403d3cea398e91dc4710a8ff1b8274a25ed" -hoist-non-react-statics@1.x.x, hoist-non-react-statics@^1.2.0: +hoist-non-react-statics@1.x.x, hoist-non-react-statics@^1.0.3, hoist-non-react-statics@^1.2.0: version "1.2.0" resolved "https://registry.yarnpkg.com/hoist-non-react-statics/-/hoist-non-react-statics-1.2.0.tgz#aa448cf0986d55cc40773b17174b7dd066cb7cfb" @@ -3013,7 +3024,7 @@ interpret@^1.0.0: version "1.0.2" resolved "https://registry.yarnpkg.com/interpret/-/interpret-1.0.2.tgz#f4f623f0bb7122f15f5717c8e254b8161b5c5b2d" -invariant@2.x.x, invariant@^2.1.0, invariant@^2.2.0, invariant@^2.2.1: +invariant@2.x.x, invariant@^2.0.0, invariant@^2.1.0, invariant@^2.2.0, invariant@^2.2.1, invariant@^2.2.2: version "2.2.2" resolved "https://registry.yarnpkg.com/invariant/-/invariant-2.2.2.tgz#9e1f56ac0acdb6bf303306f338be3b204ae60360" dependencies: @@ -3156,6 +3167,10 @@ is-primitive@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/is-primitive/-/is-primitive-2.0.0.tgz#207bab91638499c07b2adf240a41a87210034575" +is-promise@^2.1.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/is-promise/-/is-promise-2.1.0.tgz#79a2a9ece7f096e80f36d2b2f3bc16c1ff4bf3fa" + is-property@^1.0.0: version "1.0.2" resolved "https://registry.yarnpkg.com/is-property/-/is-property-1.0.2.tgz#57fe1c4e48474edd65b09911f26b1cd4095dda84" @@ -3749,6 +3764,10 @@ json-loader@^0.5.4: version "0.5.4" resolved "https://registry.yarnpkg.com/json-loader/-/json-loader-0.5.4.tgz#8baa1365a632f58a3c46d20175fc6002c96e37de" +json-schema-form-core@^1.0.0-alpha.2: + version "1.0.0-alpha.2" + resolved "https://registry.yarnpkg.com/json-schema-form-core/-/json-schema-form-core-1.0.0-alpha.2.tgz#60566287e5f3fb8d2ccb1337dca5d3b80c3391c9" + json-schema@0.2.3: version "0.2.3" resolved "https://registry.yarnpkg.com/json-schema/-/json-schema-0.2.3.tgz#b480c892e59a2f05954ce727bd3f2a4e882f9e13" @@ -3871,7 +3890,7 @@ locate-path@^2.0.0: p-locate "^2.0.0" path-exists "^3.0.0" -lodash-es@^4.2.1: +lodash-es@^4.17.3, lodash-es@^4.2.0, lodash-es@^4.2.1: version "4.17.4" resolved "https://registry.yarnpkg.com/lodash-es/-/lodash-es-4.17.4.tgz#dcc1d7552e150a0640073ba9cb31d70f032950e7" @@ -4068,7 +4087,7 @@ lodash.uniq@^4.3.0: version "4.5.0" resolved "https://registry.yarnpkg.com/lodash.uniq/-/lodash.uniq-4.5.0.tgz#d0225373aeb652adc1bc82e4945339a842754773" -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: +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: version "4.17.4" resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.4.tgz#78203a4d1c328ae1d86dca6460e369b57f4055ae" @@ -4500,7 +4519,7 @@ object-assign@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/object-assign/-/object-assign-3.0.0.tgz#9bedd5ca0897949bca47e7ff408062d549f587f2" -object-assign@^4.0.1, object-assign@^4.1.0: +object-assign@^4.0.1, object-assign@^4.1.0, object-assign@^4.1.1: version "4.1.1" resolved "https://registry.yarnpkg.com/object-assign/-/object-assign-4.1.1.tgz#2109adc7965887cfc05cbbd442cac8bfbb360863" @@ -5057,6 +5076,12 @@ promise@^7.1.1: dependencies: asap "~2.0.3" +prop-types@^15.0.0, prop-types@^15.5.6: + version "15.5.8" + resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.5.8.tgz#6b7b2e141083be38c8595aa51fc55775c7199394" + dependencies: + fbjs "^0.8.9" + proxy-addr@~1.1.3: version "1.1.4" resolved "https://registry.yarnpkg.com/proxy-addr/-/proxy-addr-1.1.4.tgz#27e545f6960a44a627d9b44467e35c1b6b4ce2f3" @@ -5283,6 +5308,18 @@ react-prop-types@^0.4.0: dependencies: warning "^3.0.0" +react-redux@^5.0.4: + version "5.0.4" + resolved "https://registry.yarnpkg.com/react-redux/-/react-redux-5.0.4.tgz#1563babadcfb2672f57f9ceaa439fb16bf85d55b" + dependencies: + create-react-class "^15.5.1" + hoist-non-react-statics "^1.0.3" + invariant "^2.0.0" + lodash "^4.2.0" + lodash-es "^4.2.0" + loose-envify "^1.1.0" + prop-types "^15.0.0" + react-simple-di@^1.2.0: version "1.2.0" 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: dependencies: babel-runtime "^6.5.0" -react-talend-components@^0.71.0: - version "0.71.0" - resolved "https://registry.yarnpkg.com/react-talend-components/-/react-talend-components-0.71.0.tgz#dec2f1d5c14669e89460a1dbf56821124d340f9b" +react-talend-components@^0.72.2: + version "0.72.2" + resolved "https://registry.yarnpkg.com/react-talend-components/-/react-talend-components-0.72.2.tgz#9426e165996359ecc82697ce1083157804e98cb1" dependencies: lodash "^4.17.4" react-autowhatever "^7.0.0" @@ -5428,6 +5465,19 @@ reduce-function-call@^1.0.1: dependencies: balanced-match "^0.4.2" +redux-form@^6.6.3: + version "6.6.3" + resolved "https://registry.yarnpkg.com/redux-form/-/redux-form-6.6.3.tgz#62362654f2214c83a8f9fcb8313702bb46f92205" + dependencies: + deep-equal "^1.0.1" + es6-error "^4.0.0" + hoist-non-react-statics "^1.2.0" + invariant "^2.2.2" + is-promise "^2.1.0" + lodash "^4.17.3" + lodash-es "^4.17.3" + prop-types "^15.5.6" + redux@^3.5.2: version "3.6.0" resolved "https://registry.yarnpkg.com/redux/-/redux-3.6.0.tgz#887c2b3d0b9bd86eca2be70571c27654c19e188d" @@ -6011,9 +6061,9 @@ table@^3.7.8: slice-ansi "0.0.4" string-width "^2.0.0" -talend-icons@^0.71.0: - version "0.71.0" - resolved "https://registry.yarnpkg.com/talend-icons/-/talend-icons-0.71.0.tgz#d52c632180d35385a6ae382dfb59e7f56ccb9ac2" +talend-icons@^0.72.2: + version "0.72.2" + resolved "https://registry.yarnpkg.com/talend-icons/-/talend-icons-0.72.2.tgz#4bdabf0091695c6ede2ecdb218c4fb0cb66b8da9" tapable@^0.1.8, tapable@~0.1.8: version "0.1.10" @@ -6126,6 +6176,10 @@ tunnel-agent@^0.6.0: dependencies: safe-buffer "^5.0.1" +tv4@^1.3.0: + version "1.3.0" + resolved "https://registry.yarnpkg.com/tv4/-/tv4-1.3.0.tgz#d020c846fadd50c855abb25ebaecc68fc10f7963" + tweetnacl@^0.14.3, tweetnacl@~0.14.0: version "0.14.5" resolved "https://registry.yarnpkg.com/tweetnacl/-/tweetnacl-0.14.5.tgz#5ae68177f192d4456269d108afa93ff8743f4f64"