@@ -4,21 +4,13 @@ import arrayMutators from 'final-form-arrays';
44import PropTypes from 'prop-types' ;
55import createFocusDecorator from 'final-form-focus' ;
66
7- import miqParser from '../parsers/miq-parser/miq-parser' ;
8- import mozillaParser from '../parsers/mozilla-parser/mozilla-schema-parser' ;
97import RendererContext from './renderer-context' ;
108import FormControls from './form-controls' ;
119import renderForm from './render-form' ;
1210import defaultSchemaValidator from '../parsers/default-schema-validator' ;
1311import SchemaErrorComponent from './schema-error-component' ;
1412import { renderTitle , renderDescription } from './form-information' ;
1513
16- const schemaMapper = type => ( {
17- mozilla : ( schema , uiSchema ) => mozillaParser ( schema , uiSchema ) ,
18- miq : schema => miqParser ( schema ) ,
19- default : schema => ( { schema } ) ,
20- } ) [ type ] ;
21-
2214const isDisabled = ( disableStates , getState ) => disableStates . map ( item => getState ( ) [ item ] ) . find ( item => ! ! item ) ;
2315
2416const FormRenderer = ( {
@@ -28,12 +20,9 @@ const FormRenderer = ({
2820 onCancel,
2921 canReset,
3022 onReset,
31- schema,
32- schemaType,
3323 buttonsLabels,
3424 disableSubmit,
3525 initialValues,
36- uiSchema,
3726 showFormControls,
3827 buttonOrder,
3928 buttonClassName,
@@ -43,11 +32,11 @@ const FormRenderer = ({
4332 renderFormButtons,
4433 subscription,
4534 clearedValue,
35+ schema,
4636} ) => {
47- const inputSchema = schemaMapper ( schemaType ) ( schema , uiSchema ) ;
4837 let schemaError ;
4938 try {
50- defaultSchemaValidator ( inputSchema . schema , formFieldsMapper , layoutMapper ) ;
39+ defaultSchemaValidator ( schema , formFieldsMapper , layoutMapper ) ;
5140 } catch ( error ) {
5241 schemaError = error ;
5342 console . error ( error ) ;
@@ -58,17 +47,14 @@ const FormRenderer = ({
5847 return < SchemaErrorComponent name = { schemaError . name } message = { schemaError . message } /> ;
5948 }
6049
61- const label = inputSchema . schema . title || inputSchema . schema . label ;
50+ const label = schema . title || schema . label ;
6251
6352 return (
6453 < Form
6554 onSubmit = { onSubmit }
6655 mutators = { { ...arrayMutators } }
6756 decorators = { [ createFocusDecorator ( ) ] }
68- initialValues = { {
69- ...inputSchema . defaultValues ,
70- ...initialValues ,
71- } }
57+ initialValues = { initialValues }
7258 validate = { validate }
7359 subscription = { { pristine : true , submitting : true , valid : true , ...subscription } }
7460 render = { ( { handleSubmit, pristine, valid, form : { reset, mutators, getState, submit, ...form } , ...state } ) => (
@@ -95,8 +81,8 @@ const FormRenderer = ({
9581 { ( { layoutMapper : { FormWrapper } } ) => (
9682 < FormWrapper onSubmit = { handleSubmit } >
9783 { label && renderTitle ( label ) }
98- { inputSchema . schema . description && renderDescription ( inputSchema . schema . description ) }
99- { renderForm ( inputSchema . schema . fields ) }
84+ { schema . description && renderDescription ( schema . description ) }
85+ { renderForm ( schema . fields ) }
10086 { onStateUpdate && < FormSpy onChange = { onStateUpdate } /> }
10187 { showFormControls && (
10288 < FormControls
@@ -122,17 +108,14 @@ const FormRenderer = ({
122108export default FormRenderer ;
123109
124110FormRenderer . propTypes = {
125- formType : PropTypes . oneOf ( [ 'pf3' , 'pf4' ] ) ,
126111 onSubmit : PropTypes . func . isRequired ,
127112 onCancel : PropTypes . func ,
128113 onReset : PropTypes . func ,
129114 canReset : PropTypes . bool ,
130115 schema : PropTypes . object . isRequired ,
131- schemaType : PropTypes . oneOf ( [ 'mozilla' , 'miq' , 'default' ] ) ,
132116 buttonsLabels : PropTypes . object ,
133117 disableSubmit : PropTypes . arrayOf ( PropTypes . string ) ,
134118 initialValues : PropTypes . object ,
135- uiSchema : PropTypes . object ,
136119 showFormControls : PropTypes . bool ,
137120 buttonOrder : PropTypes . arrayOf ( PropTypes . string ) ,
138121 buttonClassName : PropTypes . string ,
@@ -145,13 +128,9 @@ FormRenderer.propTypes = {
145128} ;
146129
147130FormRenderer . defaultProps = {
148- formType : 'pf3' ,
149- resetAble : false ,
150- schemaType : 'default' ,
151131 buttonsLabels : { } ,
152132 disableSubmit : [ ] ,
153133 initialValues : { } ,
154- uiSchema : { } ,
155134 showFormControls : true ,
156135 clearOnUnmount : false ,
157136 buttonClassName : '' ,
0 commit comments