diff --git a/admin/client/src/boot/index.js b/admin/client/src/boot/index.js index a2e5c84b6..b5b389bf7 100644 --- a/admin/client/src/boot/index.js +++ b/admin/client/src/boot/index.js @@ -6,7 +6,7 @@ import reducerRegister from 'lib/ReducerRegister'; import * as configActions from 'state/config/ConfigActions'; import ConfigReducer from 'state/config/ConfigReducer'; -import FormsReducer from 'state/forms/FormsReducer'; +import FormReducer from 'state/form/FormReducer'; import SchemaReducer from 'state/schema/SchemaReducer'; import RecordsReducer from 'state/records/RecordsReducer'; import CampaignReducer from 'state/campaign/CampaignReducer'; @@ -17,7 +17,7 @@ import CampaignAdmin from 'containers/CampaignAdmin/index'; function appBoot() { reducerRegister.add('config', ConfigReducer); - reducerRegister.add('forms', FormsReducer); + reducerRegister.add('form', FormReducer); reducerRegister.add('schemas', SchemaReducer); reducerRegister.add('records', RecordsReducer); reducerRegister.add('campaign', CampaignReducer); diff --git a/admin/client/src/components/FormBuilder/FormBuilder.js b/admin/client/src/components/FormBuilder/FormBuilder.js index 68b8c70f1..12ef56d87 100644 --- a/admin/client/src/components/FormBuilder/FormBuilder.js +++ b/admin/client/src/components/FormBuilder/FormBuilder.js @@ -1,7 +1,7 @@ import React from 'react'; import { connect } from 'react-redux'; import { bindActionCreators } from 'redux'; -import * as formsActions from 'state/forms/FormsActions'; +import * as formActions from 'state/form/FormActions'; import * as schemaActions from 'state/schema/SchemaActions'; import SilverStripeComponent from 'lib/SilverStripeComponent'; import FormComponent from 'components/Form/Form'; @@ -161,7 +161,7 @@ export class FormBuilderComponent extends SilverStripeComponent { } if (typeof formState.id !== 'undefined') { - this.props.formsActions.addForm(formState); + this.props.formActions.addForm(formState); } }); @@ -209,9 +209,9 @@ export class FormBuilderComponent extends SilverStripeComponent { */ handleFieldUpdate(event, updates, fn) { if (typeof fn !== 'undefined') { - fn(this.getFormId(), this.props.formsActions.updateField); + fn(this.getFormId(), this.props.formActions.updateField); } else { - this.props.formsActions.updateField(this.getFormId(), updates); + this.props.formActions.updateField(this.getFormId(), updates); } } @@ -248,13 +248,13 @@ export class FormBuilderComponent extends SilverStripeComponent { */ handleSubmit(event) { const schemaFields = this.props.schemas[this.props.schemaUrl].schema.fields; - const fieldValues = this.props.forms[this.getFormId()].fields + const fieldValues = this.props.form[this.getFormId()].fields .reduce((prev, curr) => Object.assign({}, prev, { [schemaFields.find(schemaField => schemaField.id === curr.id).name]: curr.value, }), {}); const submitFn = () => { - this.props.formsActions.submitForm( + this.props.formActions.submitForm( this.submitApi, this.getFormId(), fieldValues @@ -372,7 +372,7 @@ export class FormBuilderComponent extends SilverStripeComponent { * @param {string} formId - ID of the form to clean up. */ removeForm(formId) { - this.props.formsActions.removeForm(formId); + this.props.formActions.removeForm(formId); } render() { @@ -381,7 +381,7 @@ export class FormBuilderComponent extends SilverStripeComponent { return null; } const formSchema = this.getFormSchema(); - const formState = this.props.forms[formId]; + const formState = this.props.form[formId]; // If the response from fetching the initial data // hasn't come back yet, don't render anything. @@ -423,8 +423,8 @@ export class FormBuilderComponent extends SilverStripeComponent { FormBuilderComponent.propTypes = { config: React.PropTypes.object, createFn: React.PropTypes.func, - forms: React.PropTypes.object.isRequired, - formsActions: React.PropTypes.object.isRequired, + form: React.PropTypes.object.isRequired, + formActions: React.PropTypes.object.isRequired, handleSubmit: React.PropTypes.func, schemas: React.PropTypes.object.isRequired, schemaActions: React.PropTypes.object.isRequired, @@ -434,14 +434,14 @@ FormBuilderComponent.propTypes = { function mapStateToProps(state) { return { config: state.config, - forms: state.forms, + form: state.form, schemas: state.schemas, }; } function mapDispatchToProps(dispatch) { return { - formsActions: bindActionCreators(formsActions, dispatch), + formActions: bindActionCreators(formActions, dispatch), schemaActions: bindActionCreators(schemaActions, dispatch), }; } diff --git a/admin/client/src/components/FormBuilder/tests/FormBuilder-test.js b/admin/client/src/components/FormBuilder/tests/FormBuilder-test.js index 72427ab97..af1ed44f0 100644 --- a/admin/client/src/components/FormBuilder/tests/FormBuilder-test.js +++ b/admin/client/src/components/FormBuilder/tests/FormBuilder-test.js @@ -12,8 +12,8 @@ describe('FormBuilderComponent', () => { beforeEach(() => { const props = { - forms: {}, - formsActions: {}, + form: {}, + formActions: {}, schemas: {}, schemaActions: {}, schemaUrl: 'admin/assets/schema/1', diff --git a/admin/client/src/containers/CampaignAdmin/CampaignAdmin.js b/admin/client/src/containers/CampaignAdmin/CampaignAdmin.js index 87ed94221..81a279e06 100644 --- a/admin/client/src/containers/CampaignAdmin/CampaignAdmin.js +++ b/admin/client/src/containers/CampaignAdmin/CampaignAdmin.js @@ -84,7 +84,7 @@ class CampaignAdmin extends SilverStripeComponent { * @return object */ renderIndexView() { - const schemaUrl = this.props.sectionConfig.forms.EditForm.schemaUrl; + const schemaUrl = this.props.sectionConfig.form.EditForm.schemaUrl; const formActionProps = { label: i18n._t('Campaigns.ADDCAMPAIGN'), icon: 'plus', @@ -138,7 +138,7 @@ class CampaignAdmin extends SilverStripeComponent { * Renders the Detail Edit Form for a Campaign. */ renderDetailEditView() { - const baseSchemaUrl = this.props.sectionConfig.forms.DetailEditForm.schemaUrl; + const baseSchemaUrl = this.props.sectionConfig.form.DetailEditForm.schemaUrl; const schemaUrl = `${baseSchemaUrl}/ChangeSet/${this.props.campaignId}`; return ( @@ -159,7 +159,7 @@ class CampaignAdmin extends SilverStripeComponent { * Render the view for creating a new Campaign. */ renderCreateView() { - const baseSchemaUrl = this.props.sectionConfig.forms.DetailEditForm.schemaUrl; + const baseSchemaUrl = this.props.sectionConfig.form.DetailEditForm.schemaUrl; const formBuilderProps = { createFn: this.campaignCreationView, schemaUrl: `${baseSchemaUrl}/ChangeSet`, @@ -294,7 +294,7 @@ CampaignAdmin.propTypes = { actions: React.PropTypes.object.isRequired, campaignId: React.PropTypes.string, config: React.PropTypes.shape({ - forms: React.PropTypes.shape({ + form: React.PropTypes.shape({ editForm: React.PropTypes.shape({ schemaUrl: React.PropTypes.string, }), diff --git a/admin/client/src/lib/config.js b/admin/client/src/lib/Config.js similarity index 100% rename from admin/client/src/lib/config.js rename to admin/client/src/lib/Config.js diff --git a/admin/client/src/state/forms/FormsActionTypes.js b/admin/client/src/state/form/FormActionTypes.js similarity index 100% rename from admin/client/src/state/forms/FormsActionTypes.js rename to admin/client/src/state/form/FormActionTypes.js diff --git a/admin/client/src/state/forms/FormsActions.js b/admin/client/src/state/form/FormActions.js similarity index 97% rename from admin/client/src/state/forms/FormsActions.js rename to admin/client/src/state/form/FormActions.js index 9595a9aaf..dd2034df2 100644 --- a/admin/client/src/state/forms/FormsActions.js +++ b/admin/client/src/state/form/FormActions.js @@ -1,4 +1,4 @@ -import { ACTION_TYPES } from './FormsActionTypes'; +import { ACTION_TYPES } from './FormActionTypes'; /** * Removes a form from state. diff --git a/admin/client/src/state/forms/FormsReducer.js b/admin/client/src/state/form/FormReducer.js similarity index 90% rename from admin/client/src/state/forms/FormsReducer.js rename to admin/client/src/state/form/FormReducer.js index 70a46f5a7..5d1cffa7f 100644 --- a/admin/client/src/state/forms/FormsReducer.js +++ b/admin/client/src/state/form/FormReducer.js @@ -1,9 +1,9 @@ import deepFreeze from 'deep-freeze'; -import { ACTION_TYPES } from './FormsActionTypes'; +import { ACTION_TYPES } from './FormActionTypes'; const initialState = deepFreeze({}); -function formsReducer(state = initialState, action) { +function formReducer(state = initialState, action) { switch (action.type) { case ACTION_TYPES.REMOVE_FORM: @@ -47,4 +47,4 @@ function formsReducer(state = initialState, action) { } } -export default formsReducer; +export default formReducer; diff --git a/admin/client/src/state/forms/README.md b/admin/client/src/state/form/README.md similarity index 79% rename from admin/client/src/state/forms/README.md rename to admin/client/src/state/form/README.md index 1b542e846..03448d5d8 100644 --- a/admin/client/src/state/forms/README.md +++ b/admin/client/src/state/form/README.md @@ -1,11 +1,11 @@ -# forms +# form This state key holds form and form field data. Forms built using the `FormBuilder` component -have their state stored in child keys of `forms` (keyed by form ID) automatically. +have their state stored in child keys of `form` (keyed by form ID) automatically. ```js { - forms: { + form: { DetailEditForm: { fields: [ { diff --git a/admin/client/src/state/forms/tests/FormsReducer-test.js b/admin/client/src/state/form/tests/FormsReducer-test.js similarity index 90% rename from admin/client/src/state/forms/tests/FormsReducer-test.js rename to admin/client/src/state/form/tests/FormsReducer-test.js index 7131aeaa6..c003c4530 100644 --- a/admin/client/src/state/forms/tests/FormsReducer-test.js +++ b/admin/client/src/state/form/tests/FormsReducer-test.js @@ -1,13 +1,14 @@ +/* global jest, describe, expect, it, beforeEach */ + jest.unmock('deep-freeze'); -jest.unmock('../FormsReducer'); -jest.unmock('../FormsActionTypes'); +jest.unmock('../FormReducer'); +jest.unmock('../FormActionTypes'); import deepFreeze from 'deep-freeze'; -import { ACTION_TYPES } from '../FormsActionTypes'; -import formsReducer from '../FormsReducer'; - -describe('formsReducer', () => { +import { ACTION_TYPES } from '../FormActionTypes'; +import formReducer from '../FormReducer'; +describe('formReducer', () => { describe('ADD_FORM', () => { const initialState = deepFreeze({ DetailEditForm: { @@ -40,7 +41,7 @@ describe('formsReducer', () => { }, }; - const nextState = formsReducer(initialState, { + const nextState = formReducer(initialState, { type: ACTION_TYPES.ADD_FORM, payload, }); @@ -83,7 +84,7 @@ describe('formsReducer', () => { }); it('should remove the form', () => { - const nextState = formsReducer(initialState, { + const nextState = formReducer(initialState, { type: ACTION_TYPES.REMOVE_FORM, payload: { formId: 'DetailEditForm' }, }); @@ -109,7 +110,7 @@ describe('formsReducer', () => { }); it('should update properties of a form field', () => { - const nextState = formsReducer(initialState, { + const nextState = formReducer(initialState, { type: ACTION_TYPES.UPDATE_FIELD, payload: { formId: 'DetailEditForm', @@ -140,7 +141,7 @@ describe('formsReducer', () => { }); it('should add top level form messages', () => { - const nextState = formsReducer(initialState, { + const nextState = formReducer(initialState, { type: ACTION_TYPES.SUBMIT_FORM_SUCCESS, payload: { id: 'DetailEditForm', diff --git a/admin/client/src/state/schema/README.md b/admin/client/src/state/schema/README.md index ca9a360b0..dd903cec8 100644 --- a/admin/client/src/state/schema/README.md +++ b/admin/client/src/state/schema/README.md @@ -5,4 +5,4 @@ Manages state associated with the FormFieldSchema. When dependency injection is implemented, this will be moved into either Framework or CMS. We can't move it sooner because there's no way of extending state. -Note form state is stored under the `forms` _not_ the `schema` key. +Note form state is stored under the `form` _not_ the `schema` key. diff --git a/admin/code/CampaignAdmin.php b/admin/code/CampaignAdmin.php index 331239239..2f0b54666 100644 --- a/admin/code/CampaignAdmin.php +++ b/admin/code/CampaignAdmin.php @@ -52,7 +52,7 @@ class CampaignAdmin extends LeftAndMain implements PermissionProvider { public function getClientConfig() { return array_merge(parent::getClientConfig(), [ - 'forms' => [ + 'form' => [ // TODO Use schemaUrl instead 'EditForm' => [ 'schemaUrl' => $this->Link('schema/EditForm')