Skip to content

Commit 103fc44

Browse files
committed
feat(renderer): remove parsers from renderer
1 parent 1664d44 commit 103fc44

File tree

10 files changed

+104
-2126
lines changed

10 files changed

+104
-2126
lines changed

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/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 & 24 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
@@ -127,11 +113,9 @@ FormRenderer.propTypes = {
127113
onReset: PropTypes.func,
128114
canReset: PropTypes.bool,
129115
schema: PropTypes.object.isRequired,
130-
schemaType: PropTypes.oneOf([ 'mozilla', 'miq', 'default' ]),
131116
buttonsLabels: PropTypes.object,
132117
disableSubmit: PropTypes.arrayOf(PropTypes.string),
133118
initialValues: PropTypes.object,
134-
uiSchema: PropTypes.object,
135119
showFormControls: PropTypes.bool,
136120
buttonOrder: PropTypes.arrayOf(PropTypes.string),
137121
buttonClassName: PropTypes.string,
@@ -145,11 +129,9 @@ FormRenderer.propTypes = {
145129

146130
FormRenderer.defaultProps = {
147131
resetAble: false,
148-
schemaType: 'default',
149132
buttonsLabels: {},
150133
disableSubmit: [],
151134
initialValues: {},
152-
uiSchema: {},
153135
showFormControls: true,
154136
clearOnUnmount: false,
155137
buttonClassName: '',

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@ exports[`<FormControls /> should render with description 1`] = `
2626
"fields": Array [],
2727
}
2828
}
29-
schemaType="default"
3029
showFormControls={true}
31-
uiSchema={Object {}}
3230
>
3331
<ReactFinalForm
3432
decorators={
@@ -185,9 +183,7 @@ exports[`<FormControls /> should render with title and description 1`] = `
185183
"title": "Title",
186184
}
187185
}
188-
schemaType="default"
189186
showFormControls={true}
190-
uiSchema={Object {}}
191187
>
192188
<ReactFinalForm
193189
decorators={
@@ -347,9 +343,7 @@ exports[`<FormControls /> should render without title and description 1`] = `
347343
"fields": Array [],
348344
}
349345
}
350-
schemaType="default"
351346
showFormControls={true}
352-
uiSchema={Object {}}
353347
>
354348
<ReactFinalForm
355349
decorators={

0 commit comments

Comments
 (0)