Skip to content

Commit

Permalink
Merge pull request #281 from rvsia/cleanObsoleteThings
Browse files Browse the repository at this point in the history
Clean obsolete props in formRenderer
  • Loading branch information
Hyperkid123 authored Jan 15, 2020
2 parents fcb9ab5 + 2b56b3d commit 2e0ca1b
Show file tree
Hide file tree
Showing 13 changed files with 104 additions and 2,145 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ Data Driven Forms is a React library used for rendering and managing forms with
- Cross-field validation!
- Asynchronous validation supported!
- Supporting Wizard forms!
- Supporting Mozzila form schema!
- Supporting [Final Form Field Array](https://github.com/final-form/react-final-form-arrays)!
- ... and a lot more!

Expand Down
1 change: 0 additions & 1 deletion packages/pf3-component-mapper/demo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ class App extends React.Component {
<FormRenderer
initialValues={{}}
onSubmit={console.log}
schemaType="default"
formFieldsMapper={formFieldsMapper}
layoutMapper={layoutMapper}
schema={sandbox}
Expand Down
1 change: 0 additions & 1 deletion packages/pf3-component-mapper/src/tests/wizard.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,6 @@ describe('<Wizard />', () => {
onCancel={ () => {} }
showFormControls={ false }
onSubmit={ jest.fn() }
schemaType="default"
initialValues={{ 'source-type': 'google' }}
/>
);
Expand Down
16 changes: 3 additions & 13 deletions packages/pf4-component-mapper/demo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import sandboxSchema from './demo-schemas/sandbox';

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

const fieldArrayState = { schema: arraySchemaDDF, schemaString: 'default', ui: uiArraySchema, additionalOptions: {
const fieldArrayState = { schema: arraySchemaDDF, additionalOptions: {
initialValues: {
number: [1,2,3,4],
minMax: [null, null, null, null]
Expand All @@ -30,27 +30,17 @@ class App extends React.Component {
<Title size="4xl">Pf4 component mapper</Title>
<Toolbar style={{ marginBottom: 20, marginTop: 20 }}>
<ToolbarGroup>
<Button onClick={() => this.setState(state => ({ schema: wizardSchema, schemaString: 'default', additionalOptions: { showFormControls: false, wizard: true } }))}>Wizard</Button>
<Button onClick={() => this.setState(state => ({ schema: wizardSchema, additionalOptions: { showFormControls: false, wizard: true } }))}>Wizard</Button>
</ToolbarGroup>
<ToolbarGroup>
<Button onClick={() => this.setState(state => fieldArrayState)}>arraySchema</Button>
</ToolbarGroup>
<ToolbarGroup>
<Button onClick={() => this.setState(state => ({ schema: schema, schemaString: 'mozilla', ui: uiSchema, additionalOptions: {}}))}>schema</Button>
</ToolbarGroup>
<ToolbarGroup>
<Button onClick={() => this.setState(state => ({ schema: miqSchema, schemaString: 'miq', additionalOptions: {}}))}>miq</Button>
</ToolbarGroup>
<ToolbarGroup>
<Button onClick={() => this.setState(state => ({ schema: conditionalSchema, schemaString: 'mozilla', ui: uiSchema, additionalOptions: {}}))}>conditional</Button>
</ToolbarGroup>
<ToolbarGroup>
<Button onClick={() => this.setState(state => ({ schema: sandboxSchema, schemaString: 'default', additionalOptions: {}}))}>Sandbox</Button>
<Button onClick={() => this.setState(state => ({ schema: sandboxSchema, additionalOptions: {}}))}>Sandbox</Button>
</ToolbarGroup>
</Toolbar>
<FormRenderer
onSubmit={console.log}
schemaType={this.state.schemaString}
formFieldsMapper={{
...formFieldsMapper,
summary: Summary
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ exports[`FieldArray should render array field correctly 1`] = `
"wizard": [Function],
}
}
formType="pf3"
initialValues={Object {}}
layoutMapper={
Object {
Expand All @@ -54,7 +53,6 @@ exports[`FieldArray should render array field correctly 1`] = `
}
}
onSubmit={[MockFunction]}
resetAble={false}
schema={
Object {
"fields": Array [
Expand All @@ -72,9 +70,7 @@ exports[`FieldArray should render array field correctly 1`] = `
],
}
}
schemaType="default"
showFormControls={true}
uiSchema={Object {}}
>
<ReactFinalForm
decorators={
Expand Down
1 change: 0 additions & 1 deletion packages/react-form-renderer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ Data Driven Forms is a React library used for rendering and managing forms with
- Cross-field validation!
- Asynchronous validation supported!
- Supporting Wizard forms!
- Supporting Mozzila form schema!
- Supporting [Final Form Field Array](https://github.com/final-form/react-final-form-arrays)!
- ... and a lot more!

Expand Down
1 change: 0 additions & 1 deletion packages/react-form-renderer/demo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ const App = () => (
onCancel={console.log}
canReset
onReset={() => console.log('i am resseting')}
schemaType="default"
schema={sandboxSchema}
buttonOrder={['cancel', 'reset', 'submit']}
buttonClassName="Foo"
Expand Down
33 changes: 6 additions & 27 deletions packages/react-form-renderer/src/form-renderer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,13 @@ import arrayMutators from 'final-form-arrays';
import PropTypes from 'prop-types';
import createFocusDecorator from 'final-form-focus';

import miqParser from '../parsers/miq-parser/miq-parser';
import mozillaParser from '../parsers/mozilla-parser/mozilla-schema-parser';
import RendererContext from './renderer-context';
import FormControls from './form-controls';
import renderForm from './render-form';
import defaultSchemaValidator from '../parsers/default-schema-validator';
import SchemaErrorComponent from './schema-error-component';
import { renderTitle, renderDescription } from './form-information';

const schemaMapper = type => ({
mozilla: (schema, uiSchema) => mozillaParser(schema, uiSchema),
miq: schema => miqParser(schema),
default: schema => ({ schema }),
})[type];

const isDisabled = (disableStates, getState) => disableStates.map(item => getState()[item]).find(item => !!item);

const FormRenderer = ({
Expand All @@ -28,12 +20,9 @@ const FormRenderer = ({
onCancel,
canReset,
onReset,
schema,
schemaType,
buttonsLabels,
disableSubmit,
initialValues,
uiSchema,
showFormControls,
buttonOrder,
buttonClassName,
Expand All @@ -43,11 +32,11 @@ const FormRenderer = ({
renderFormButtons,
subscription,
clearedValue,
schema,
}) => {
const inputSchema = schemaMapper(schemaType)(schema, uiSchema);
let schemaError;
try {
defaultSchemaValidator(inputSchema.schema, formFieldsMapper, layoutMapper);
defaultSchemaValidator(schema, formFieldsMapper, layoutMapper);
} catch (error) {
schemaError = error;
console.error(error);
Expand All @@ -58,17 +47,14 @@ const FormRenderer = ({
return <SchemaErrorComponent name={ schemaError.name } message={ schemaError.message } />;
}

const label = inputSchema.schema.title || inputSchema.schema.label;
const label = schema.title || schema.label;

return (
<Form
onSubmit={ onSubmit }
mutators={{ ...arrayMutators }}
decorators={ [ createFocusDecorator() ] }
initialValues={{
...inputSchema.defaultValues,
...initialValues,
}}
initialValues={ initialValues }
validate={ validate }
subscription={{ pristine: true, submitting: true, valid: true, ...subscription }}
render={ ({ handleSubmit, pristine, valid, form: { reset, mutators, getState, submit, ...form }, ...state }) => (
Expand All @@ -95,8 +81,8 @@ const FormRenderer = ({
{ ({ layoutMapper: { FormWrapper }}) => (
<FormWrapper onSubmit={ handleSubmit }>
{ label && renderTitle(label) }
{ inputSchema.schema.description && renderDescription(inputSchema.schema.description) }
{ renderForm(inputSchema.schema.fields) }
{ schema.description && renderDescription(schema.description) }
{ renderForm(schema.fields) }
{ onStateUpdate && <FormSpy onChange={ onStateUpdate } /> }
{ showFormControls && (
<FormControls
Expand All @@ -122,17 +108,14 @@ const FormRenderer = ({
export default FormRenderer;

FormRenderer.propTypes = {
formType: PropTypes.oneOf([ 'pf3', 'pf4' ]),
onSubmit: PropTypes.func.isRequired,
onCancel: PropTypes.func,
onReset: PropTypes.func,
canReset: PropTypes.bool,
schema: PropTypes.object.isRequired,
schemaType: PropTypes.oneOf([ 'mozilla', 'miq', 'default' ]),
buttonsLabels: PropTypes.object,
disableSubmit: PropTypes.arrayOf(PropTypes.string),
initialValues: PropTypes.object,
uiSchema: PropTypes.object,
showFormControls: PropTypes.bool,
buttonOrder: PropTypes.arrayOf(PropTypes.string),
buttonClassName: PropTypes.string,
Expand All @@ -145,13 +128,9 @@ FormRenderer.propTypes = {
};

FormRenderer.defaultProps = {
formType: 'pf3',
resetAble: false,
schemaType: 'default',
buttonsLabels: {},
disableSubmit: [],
initialValues: {},
uiSchema: {},
showFormControls: true,
clearOnUnmount: false,
buttonClassName: '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ exports[`<FormControls /> should render with description 1`] = `
clearOnUnmount={false}
disableSubmit={Array []}
formFieldsMapper={Object {}}
formType="pf3"
initialValues={Object {}}
layoutMapper={
Object {
Expand All @@ -20,16 +19,13 @@ exports[`<FormControls /> should render with description 1`] = `
}
}
onSubmit={[MockFunction]}
resetAble={false}
schema={
Object {
"description": "Description",
"fields": Array [],
}
}
schemaType="default"
showFormControls={true}
uiSchema={Object {}}
>
<ReactFinalForm
decorators={
Expand Down Expand Up @@ -167,7 +163,6 @@ exports[`<FormControls /> should render with title and description 1`] = `
clearOnUnmount={false}
disableSubmit={Array []}
formFieldsMapper={Object {}}
formType="pf3"
initialValues={Object {}}
layoutMapper={
Object {
Expand All @@ -179,17 +174,14 @@ exports[`<FormControls /> should render with title and description 1`] = `
}
}
onSubmit={[MockFunction]}
resetAble={false}
schema={
Object {
"description": "Description",
"fields": Array [],
"title": "Title",
}
}
schemaType="default"
showFormControls={true}
uiSchema={Object {}}
>
<ReactFinalForm
decorators={
Expand Down Expand Up @@ -332,7 +324,6 @@ exports[`<FormControls /> should render without title and description 1`] = `
clearOnUnmount={false}
disableSubmit={Array []}
formFieldsMapper={Object {}}
formType="pf3"
initialValues={Object {}}
layoutMapper={
Object {
Expand All @@ -344,15 +335,12 @@ exports[`<FormControls /> should render without title and description 1`] = `
}
}
onSubmit={[MockFunction]}
resetAble={false}
schema={
Object {
"fields": Array [],
}
}
schemaType="default"
showFormControls={true}
uiSchema={Object {}}
>
<ReactFinalForm
decorators={
Expand Down
Loading

0 comments on commit 2e0ca1b

Please sign in to comment.