From 1664d449ac8e0fa1073ad20c05fd43f00a5013f4 Mon Sep 17 00:00:00 2001 From: Richard Vsiansky Date: Wed, 15 Jan 2020 13:02:56 +0100 Subject: [PATCH 1/5] Removed unused formType prop --- packages/react-form-renderer/src/form-renderer/index.js | 2 -- .../form-renderer/__snapshots__/form-information.test.js.snap | 3 --- .../form-renderer/__snapshots__/form-renderer.test.js.snap | 2 -- 3 files changed, 7 deletions(-) diff --git a/packages/react-form-renderer/src/form-renderer/index.js b/packages/react-form-renderer/src/form-renderer/index.js index 784c59e78..eae4cc5fe 100644 --- a/packages/react-form-renderer/src/form-renderer/index.js +++ b/packages/react-form-renderer/src/form-renderer/index.js @@ -122,7 +122,6 @@ const FormRenderer = ({ export default FormRenderer; FormRenderer.propTypes = { - formType: PropTypes.oneOf([ 'pf3', 'pf4' ]), onSubmit: PropTypes.func.isRequired, onCancel: PropTypes.func, onReset: PropTypes.func, @@ -145,7 +144,6 @@ FormRenderer.propTypes = { }; FormRenderer.defaultProps = { - formType: 'pf3', resetAble: false, schemaType: 'default', buttonsLabels: {}, diff --git a/packages/react-form-renderer/src/tests/form-renderer/__snapshots__/form-information.test.js.snap b/packages/react-form-renderer/src/tests/form-renderer/__snapshots__/form-information.test.js.snap index 244737f00..97e0165ba 100644 --- a/packages/react-form-renderer/src/tests/form-renderer/__snapshots__/form-information.test.js.snap +++ b/packages/react-form-renderer/src/tests/form-renderer/__snapshots__/form-information.test.js.snap @@ -8,7 +8,6 @@ exports[` should render with description 1`] = ` clearOnUnmount={false} disableSubmit={Array []} formFieldsMapper={Object {}} - formType="pf3" initialValues={Object {}} layoutMapper={ Object { @@ -167,7 +166,6 @@ exports[` should render with title and description 1`] = ` clearOnUnmount={false} disableSubmit={Array []} formFieldsMapper={Object {}} - formType="pf3" initialValues={Object {}} layoutMapper={ Object { @@ -332,7 +330,6 @@ exports[` should render without title and description 1`] = ` clearOnUnmount={false} disableSubmit={Array []} formFieldsMapper={Object {}} - formType="pf3" initialValues={Object {}} layoutMapper={ Object { diff --git a/packages/react-form-renderer/src/tests/form-renderer/__snapshots__/form-renderer.test.js.snap b/packages/react-form-renderer/src/tests/form-renderer/__snapshots__/form-renderer.test.js.snap index 7d75da9ca..ea0c9c0be 100644 --- a/packages/react-form-renderer/src/tests/form-renderer/__snapshots__/form-renderer.test.js.snap +++ b/packages/react-form-renderer/src/tests/form-renderer/__snapshots__/form-renderer.test.js.snap @@ -19,7 +19,6 @@ exports[` should render form from schema 1`] = ` "time-picker": [Function], } } - formType="pf3" initialValues={Object {}} layoutMapper={ Object { @@ -2779,7 +2778,6 @@ exports[` should render hidden field 1`] = ` "time-picker": [Function], } } - formType="pf3" initialValues={Object {}} layoutMapper={ Object { From 103fc4474eacabe749d787bb139bf678e12796f7 Mon Sep 17 00:00:00 2001 From: Richard Vsiansky Date: Wed, 15 Jan 2020 13:22:41 +0100 Subject: [PATCH 2/5] feat(renderer): remove parsers from renderer --- packages/pf3-component-mapper/demo/index.js | 1 - .../src/tests/wizard.test.js | 1 - packages/pf4-component-mapper/demo/index.js | 16 +- packages/react-form-renderer/demo/index.js | 1 - .../src/form-renderer/index.js | 30 +- .../form-information.test.js.snap | 6 - .../__snapshots__/form-renderer.test.js.snap | 2120 +---------------- .../tests/form-renderer/form-renderer.test.js | 49 +- .../src/app/pages/renderer/renderer-api.md | 2 - .../app/src/components/navigation/schema.js | 4 - 10 files changed, 104 insertions(+), 2126 deletions(-) diff --git a/packages/pf3-component-mapper/demo/index.js b/packages/pf3-component-mapper/demo/index.js index 9bc463072..2da6fdf65 100644 --- a/packages/pf3-component-mapper/demo/index.js +++ b/packages/pf3-component-mapper/demo/index.js @@ -111,7 +111,6 @@ class App extends React.Component { ', () => { onCancel={ () => {} } showFormControls={ false } onSubmit={ jest.fn() } - schemaType="default" initialValues={{ 'source-type': 'google' }} /> ); diff --git a/packages/pf4-component-mapper/demo/index.js b/packages/pf4-component-mapper/demo/index.js index 24500baa3..e0613c075 100644 --- a/packages/pf4-component-mapper/demo/index.js +++ b/packages/pf4-component-mapper/demo/index.js @@ -11,7 +11,7 @@ import sandboxSchema from './demo-schemas/sandbox'; const Summary = props =>
Custom summary component.
; -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] @@ -30,27 +30,17 @@ class App extends React.Component { Pf4 component mapper - + - - - - - - - - - - + ( onCancel={console.log} canReset onReset={() => console.log('i am resseting')} - schemaType="default" schema={sandboxSchema} buttonOrder={['cancel', 'reset', 'submit']} buttonClassName="Foo" diff --git a/packages/react-form-renderer/src/form-renderer/index.js b/packages/react-form-renderer/src/form-renderer/index.js index eae4cc5fe..bfabee0f6 100644 --- a/packages/react-form-renderer/src/form-renderer/index.js +++ b/packages/react-form-renderer/src/form-renderer/index.js @@ -4,8 +4,6 @@ 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'; @@ -13,12 +11,6 @@ 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 = ({ @@ -28,12 +20,9 @@ const FormRenderer = ({ onCancel, canReset, onReset, - schema, - schemaType, buttonsLabels, disableSubmit, initialValues, - uiSchema, showFormControls, buttonOrder, buttonClassName, @@ -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); @@ -58,17 +47,14 @@ const FormRenderer = ({ return ; } - const label = inputSchema.schema.title || inputSchema.schema.label; + const label = schema.title || schema.label; return (
( @@ -95,8 +81,8 @@ const FormRenderer = ({ { ({ layoutMapper: { FormWrapper }}) => ( { label && renderTitle(label) } - { inputSchema.schema.description && renderDescription(inputSchema.schema.description) } - { renderForm(inputSchema.schema.fields) } + { schema.description && renderDescription(schema.description) } + { renderForm(schema.fields) } { onStateUpdate && } { showFormControls && ( should render with description 1`] = ` "fields": Array [], } } - schemaType="default" showFormControls={true} - uiSchema={Object {}} > should render with title and description 1`] = ` "title": "Title", } } - schemaType="default" showFormControls={true} - uiSchema={Object {}} > should render without title and description 1`] = ` "fields": Array [], } } - schemaType="default" showFormControls={true} - uiSchema={Object {}} > should render form from schema 1`] = ` resetAble={false} schema={ Object { - "properties": Object { - "boolean": Object { - "properties": Object { - "defaultCheckbox": Object { - "description": "This is the checkbox-description", - "title": "checkbox (default)", - "type": "boolean", - }, - "radio": Object { - "description": "This is the radio-description", - "title": "radio buttons", - "type": "boolean", - }, - "select": Object { - "description": "This is the select-description", - "title": "select box", - "type": "boolean", - }, - }, - "title": "Boolean field", - "type": "object", - }, - "disabled": Object { - "default": "I am disabled.", - "title": "A disabled field", - "type": "string", - }, - "readonly": Object { - "default": "I am read-only.", - "title": "A readonly field", - "type": "string", - }, - "secret": Object { - "default": "I'm a hidden string.", - "type": "string", - }, - "selectWidgetOptions": Object { - "enum": Array [ - "foo", - "bar", - ], - "enumNames": Array [ - "Foo", - "Bar", - ], - "title": "Custom select widget with options", - "type": "string", - }, - "string": Object { - "properties": Object { - "color": Object { - "default": "#151ce6", - "title": "color picker", - "type": "string", - }, - "defaultInput": Object { - "title": "text input (default)", - "type": "string", - }, - "textarea": Object { - "title": "textarea", - "type": "string", - }, - }, - "title": "String field", - "type": "object", - }, - "stringFormats": Object { - "properties": Object { - "email": Object { - "format": "email", - "type": "string", - }, - "uri": Object { - "format": "uri", - "type": "string", - }, - }, - "title": "String formats", - "type": "object", - }, - "widgetOptions": Object { - "default": "I am yellow", - "title": "Custom widget with options", - "type": "string", - }, - }, - "title": "Widgets", - "type": "object", - } - } - schemaType="mozilla" - showFormControls={true} - uiSchema={Object {}} - uischema={ - Object { - "boolean": Object { - "radio": Object { - "ui:widget": "radio", - }, - "select": Object { - "ui:widget": "select", - }, - }, - "disabled": Object { - "ui:disabled": true, - }, - "readonly": Object { - "ui:readonly": true, - }, - "secret": Object { - "ui:widget": "hidden", - }, - "selectWidgetOptions": Object { - "ui:options": Object { - "backgroundColor": "pink", - }, - }, - "string": Object { - "color": Object { - "ui:widget": "color", - }, - "textarea": Object { - "ui:options": Object { - "rows": 5, - }, - "ui:widget": "textarea", - }, - }, - "widgetOptions": Object { - "ui:options": Object { - "backgroundColor": "yellow", - }, - }, - } - } -> -