Skip to content

Commit 2e0ca1b

Browse files
authored
Merge pull request #281 from rvsia/cleanObsoleteThings
Clean obsolete props in formRenderer
2 parents fcb9ab5 + 2b56b3d commit 2e0ca1b

File tree

13 files changed

+104
-2145
lines changed

13 files changed

+104
-2145
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ Data Driven Forms is a React library used for rendering and managing forms with
2424
- Cross-field validation!
2525
- Asynchronous validation supported!
2626
- Supporting Wizard forms!
27-
- Supporting Mozzila form schema!
2827
- Supporting [Final Form Field Array](https://github.com/final-form/react-final-form-arrays)!
2928
- ... and a lot more!
3029

packages/pf3-component-mapper/demo/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ class App extends React.Component {
111111
<FormRenderer
112112
initialValues={{}}
113113
onSubmit={console.log}
114-
schemaType="default"
115114
formFieldsMapper={formFieldsMapper}
116115
layoutMapper={layoutMapper}
117116
schema={sandbox}

packages/pf3-component-mapper/src/tests/wizard.test.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,6 @@ describe('<Wizard />', () => {
224224
onCancel={ () => {} }
225225
showFormControls={ false }
226226
onSubmit={ jest.fn() }
227-
schemaType="default"
228227
initialValues={{ 'source-type': 'google' }}
229228
/>
230229
);

packages/pf4-component-mapper/demo/index.js

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import sandboxSchema from './demo-schemas/sandbox';
1111

1212
const Summary = props => <div>Custom summary component.</div>;
1313

14-
const fieldArrayState = { schema: arraySchemaDDF, schemaString: 'default', ui: uiArraySchema, additionalOptions: {
14+
const fieldArrayState = { schema: arraySchemaDDF, additionalOptions: {
1515
initialValues: {
1616
number: [1,2,3,4],
1717
minMax: [null, null, null, null]
@@ -30,27 +30,17 @@ class App extends React.Component {
3030
<Title size="4xl">Pf4 component mapper</Title>
3131
<Toolbar style={{ marginBottom: 20, marginTop: 20 }}>
3232
<ToolbarGroup>
33-
<Button onClick={() => this.setState(state => ({ schema: wizardSchema, schemaString: 'default', additionalOptions: { showFormControls: false, wizard: true } }))}>Wizard</Button>
33+
<Button onClick={() => this.setState(state => ({ schema: wizardSchema, additionalOptions: { showFormControls: false, wizard: true } }))}>Wizard</Button>
3434
</ToolbarGroup>
3535
<ToolbarGroup>
3636
<Button onClick={() => this.setState(state => fieldArrayState)}>arraySchema</Button>
3737
</ToolbarGroup>
3838
<ToolbarGroup>
39-
<Button onClick={() => this.setState(state => ({ schema: schema, schemaString: 'mozilla', ui: uiSchema, additionalOptions: {}}))}>schema</Button>
40-
</ToolbarGroup>
41-
<ToolbarGroup>
42-
<Button onClick={() => this.setState(state => ({ schema: miqSchema, schemaString: 'miq', additionalOptions: {}}))}>miq</Button>
43-
</ToolbarGroup>
44-
<ToolbarGroup>
45-
<Button onClick={() => this.setState(state => ({ schema: conditionalSchema, schemaString: 'mozilla', ui: uiSchema, additionalOptions: {}}))}>conditional</Button>
46-
</ToolbarGroup>
47-
<ToolbarGroup>
48-
<Button onClick={() => this.setState(state => ({ schema: sandboxSchema, schemaString: 'default', additionalOptions: {}}))}>Sandbox</Button>
39+
<Button onClick={() => this.setState(state => ({ schema: sandboxSchema, additionalOptions: {}}))}>Sandbox</Button>
4940
</ToolbarGroup>
5041
</Toolbar>
5142
<FormRenderer
5243
onSubmit={console.log}
53-
schemaType={this.state.schemaString}
5444
formFieldsMapper={{
5545
...formFieldsMapper,
5646
summary: Summary

packages/pf4-component-mapper/src/tests/field-array/__snapshots__/field-array.test.js.snap

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ exports[`FieldArray should render array field correctly 1`] = `
4242
"wizard": [Function],
4343
}
4444
}
45-
formType="pf3"
4645
initialValues={Object {}}
4746
layoutMapper={
4847
Object {
@@ -54,7 +53,6 @@ exports[`FieldArray should render array field correctly 1`] = `
5453
}
5554
}
5655
onSubmit={[MockFunction]}
57-
resetAble={false}
5856
schema={
5957
Object {
6058
"fields": Array [
@@ -72,9 +70,7 @@ exports[`FieldArray should render array field correctly 1`] = `
7270
],
7371
}
7472
}
75-
schemaType="default"
7673
showFormControls={true}
77-
uiSchema={Object {}}
7874
>
7975
<ReactFinalForm
8076
decorators={

packages/react-form-renderer/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ Data Driven Forms is a React library used for rendering and managing forms with
2121
- Cross-field validation!
2222
- Asynchronous validation supported!
2323
- Supporting Wizard forms!
24-
- Supporting Mozzila form schema!
2524
- Supporting [Final Form Field Array](https://github.com/final-form/react-final-form-arrays)!
2625
- ... and a lot more!
2726

packages/react-form-renderer/demo/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ const App = () => (
3535
onCancel={console.log}
3636
canReset
3737
onReset={() => console.log('i am resseting')}
38-
schemaType="default"
3938
schema={sandboxSchema}
4039
buttonOrder={['cancel', 'reset', 'submit']}
4140
buttonClassName="Foo"

packages/react-form-renderer/src/form-renderer/index.js

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,13 @@ import arrayMutators from 'final-form-arrays';
44
import PropTypes from 'prop-types';
55
import 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';
97
import RendererContext from './renderer-context';
108
import FormControls from './form-controls';
119
import renderForm from './render-form';
1210
import defaultSchemaValidator from '../parsers/default-schema-validator';
1311
import SchemaErrorComponent from './schema-error-component';
1412
import { 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-
2214
const isDisabled = (disableStates, getState) => disableStates.map(item => getState()[item]).find(item => !!item);
2315

2416
const 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 = ({
122108
export default FormRenderer;
123109

124110
FormRenderer.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

147130
FormRenderer.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: '',

packages/react-form-renderer/src/tests/form-renderer/__snapshots__/form-information.test.js.snap

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ exports[`<FormControls /> should render with description 1`] = `
88
clearOnUnmount={false}
99
disableSubmit={Array []}
1010
formFieldsMapper={Object {}}
11-
formType="pf3"
1211
initialValues={Object {}}
1312
layoutMapper={
1413
Object {
@@ -20,16 +19,13 @@ exports[`<FormControls /> should render with description 1`] = `
2019
}
2120
}
2221
onSubmit={[MockFunction]}
23-
resetAble={false}
2422
schema={
2523
Object {
2624
"description": "Description",
2725
"fields": Array [],
2826
}
2927
}
30-
schemaType="default"
3128
showFormControls={true}
32-
uiSchema={Object {}}
3329
>
3430
<ReactFinalForm
3531
decorators={
@@ -167,7 +163,6 @@ exports[`<FormControls /> should render with title and description 1`] = `
167163
clearOnUnmount={false}
168164
disableSubmit={Array []}
169165
formFieldsMapper={Object {}}
170-
formType="pf3"
171166
initialValues={Object {}}
172167
layoutMapper={
173168
Object {
@@ -179,17 +174,14 @@ exports[`<FormControls /> should render with title and description 1`] = `
179174
}
180175
}
181176
onSubmit={[MockFunction]}
182-
resetAble={false}
183177
schema={
184178
Object {
185179
"description": "Description",
186180
"fields": Array [],
187181
"title": "Title",
188182
}
189183
}
190-
schemaType="default"
191184
showFormControls={true}
192-
uiSchema={Object {}}
193185
>
194186
<ReactFinalForm
195187
decorators={
@@ -332,7 +324,6 @@ exports[`<FormControls /> should render without title and description 1`] = `
332324
clearOnUnmount={false}
333325
disableSubmit={Array []}
334326
formFieldsMapper={Object {}}
335-
formType="pf3"
336327
initialValues={Object {}}
337328
layoutMapper={
338329
Object {
@@ -344,15 +335,12 @@ exports[`<FormControls /> should render without title and description 1`] = `
344335
}
345336
}
346337
onSubmit={[MockFunction]}
347-
resetAble={false}
348338
schema={
349339
Object {
350340
"fields": Array [],
351341
}
352342
}
353-
schemaType="default"
354343
showFormControls={true}
355-
uiSchema={Object {}}
356344
>
357345
<ReactFinalForm
358346
decorators={

0 commit comments

Comments
 (0)