mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Make 'form' state key singular rather than plural
This commit is contained in:
parent
25f1f992a9
commit
0b9a339b79
@ -6,7 +6,7 @@ import reducerRegister from 'lib/ReducerRegister';
|
|||||||
|
|
||||||
import * as configActions from 'state/config/ConfigActions';
|
import * as configActions from 'state/config/ConfigActions';
|
||||||
import ConfigReducer from 'state/config/ConfigReducer';
|
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 SchemaReducer from 'state/schema/SchemaReducer';
|
||||||
import RecordsReducer from 'state/records/RecordsReducer';
|
import RecordsReducer from 'state/records/RecordsReducer';
|
||||||
import CampaignReducer from 'state/campaign/CampaignReducer';
|
import CampaignReducer from 'state/campaign/CampaignReducer';
|
||||||
@ -17,7 +17,7 @@ import CampaignAdmin from 'containers/CampaignAdmin/index';
|
|||||||
|
|
||||||
function appBoot() {
|
function appBoot() {
|
||||||
reducerRegister.add('config', ConfigReducer);
|
reducerRegister.add('config', ConfigReducer);
|
||||||
reducerRegister.add('forms', FormsReducer);
|
reducerRegister.add('form', FormReducer);
|
||||||
reducerRegister.add('schemas', SchemaReducer);
|
reducerRegister.add('schemas', SchemaReducer);
|
||||||
reducerRegister.add('records', RecordsReducer);
|
reducerRegister.add('records', RecordsReducer);
|
||||||
reducerRegister.add('campaign', CampaignReducer);
|
reducerRegister.add('campaign', CampaignReducer);
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import { bindActionCreators } from '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 * as schemaActions from 'state/schema/SchemaActions';
|
||||||
import SilverStripeComponent from 'lib/SilverStripeComponent';
|
import SilverStripeComponent from 'lib/SilverStripeComponent';
|
||||||
import FormComponent from 'components/Form/Form';
|
import FormComponent from 'components/Form/Form';
|
||||||
@ -161,7 +161,7 @@ export class FormBuilderComponent extends SilverStripeComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (typeof formState.id !== 'undefined') {
|
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) {
|
handleFieldUpdate(event, updates, fn) {
|
||||||
if (typeof fn !== 'undefined') {
|
if (typeof fn !== 'undefined') {
|
||||||
fn(this.getFormId(), this.props.formsActions.updateField);
|
fn(this.getFormId(), this.props.formActions.updateField);
|
||||||
} else {
|
} 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) {
|
handleSubmit(event) {
|
||||||
const schemaFields = this.props.schemas[this.props.schemaUrl].schema.fields;
|
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, {
|
.reduce((prev, curr) => Object.assign({}, prev, {
|
||||||
[schemaFields.find(schemaField => schemaField.id === curr.id).name]: curr.value,
|
[schemaFields.find(schemaField => schemaField.id === curr.id).name]: curr.value,
|
||||||
}), {});
|
}), {});
|
||||||
|
|
||||||
const submitFn = () => {
|
const submitFn = () => {
|
||||||
this.props.formsActions.submitForm(
|
this.props.formActions.submitForm(
|
||||||
this.submitApi,
|
this.submitApi,
|
||||||
this.getFormId(),
|
this.getFormId(),
|
||||||
fieldValues
|
fieldValues
|
||||||
@ -372,7 +372,7 @@ export class FormBuilderComponent extends SilverStripeComponent {
|
|||||||
* @param {string} formId - ID of the form to clean up.
|
* @param {string} formId - ID of the form to clean up.
|
||||||
*/
|
*/
|
||||||
removeForm(formId) {
|
removeForm(formId) {
|
||||||
this.props.formsActions.removeForm(formId);
|
this.props.formActions.removeForm(formId);
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
@ -381,7 +381,7 @@ export class FormBuilderComponent extends SilverStripeComponent {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
const formSchema = this.getFormSchema();
|
const formSchema = this.getFormSchema();
|
||||||
const formState = this.props.forms[formId];
|
const formState = this.props.form[formId];
|
||||||
|
|
||||||
// If the response from fetching the initial data
|
// If the response from fetching the initial data
|
||||||
// hasn't come back yet, don't render anything.
|
// hasn't come back yet, don't render anything.
|
||||||
@ -423,8 +423,8 @@ export class FormBuilderComponent extends SilverStripeComponent {
|
|||||||
FormBuilderComponent.propTypes = {
|
FormBuilderComponent.propTypes = {
|
||||||
config: React.PropTypes.object,
|
config: React.PropTypes.object,
|
||||||
createFn: React.PropTypes.func,
|
createFn: React.PropTypes.func,
|
||||||
forms: React.PropTypes.object.isRequired,
|
form: React.PropTypes.object.isRequired,
|
||||||
formsActions: React.PropTypes.object.isRequired,
|
formActions: React.PropTypes.object.isRequired,
|
||||||
handleSubmit: React.PropTypes.func,
|
handleSubmit: React.PropTypes.func,
|
||||||
schemas: React.PropTypes.object.isRequired,
|
schemas: React.PropTypes.object.isRequired,
|
||||||
schemaActions: React.PropTypes.object.isRequired,
|
schemaActions: React.PropTypes.object.isRequired,
|
||||||
@ -434,14 +434,14 @@ FormBuilderComponent.propTypes = {
|
|||||||
function mapStateToProps(state) {
|
function mapStateToProps(state) {
|
||||||
return {
|
return {
|
||||||
config: state.config,
|
config: state.config,
|
||||||
forms: state.forms,
|
form: state.form,
|
||||||
schemas: state.schemas,
|
schemas: state.schemas,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function mapDispatchToProps(dispatch) {
|
function mapDispatchToProps(dispatch) {
|
||||||
return {
|
return {
|
||||||
formsActions: bindActionCreators(formsActions, dispatch),
|
formActions: bindActionCreators(formActions, dispatch),
|
||||||
schemaActions: bindActionCreators(schemaActions, dispatch),
|
schemaActions: bindActionCreators(schemaActions, dispatch),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -12,8 +12,8 @@ describe('FormBuilderComponent', () => {
|
|||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
const props = {
|
const props = {
|
||||||
forms: {},
|
form: {},
|
||||||
formsActions: {},
|
formActions: {},
|
||||||
schemas: {},
|
schemas: {},
|
||||||
schemaActions: {},
|
schemaActions: {},
|
||||||
schemaUrl: 'admin/assets/schema/1',
|
schemaUrl: 'admin/assets/schema/1',
|
||||||
|
@ -84,7 +84,7 @@ class CampaignAdmin extends SilverStripeComponent {
|
|||||||
* @return object
|
* @return object
|
||||||
*/
|
*/
|
||||||
renderIndexView() {
|
renderIndexView() {
|
||||||
const schemaUrl = this.props.sectionConfig.forms.EditForm.schemaUrl;
|
const schemaUrl = this.props.sectionConfig.form.EditForm.schemaUrl;
|
||||||
const formActionProps = {
|
const formActionProps = {
|
||||||
label: i18n._t('Campaigns.ADDCAMPAIGN'),
|
label: i18n._t('Campaigns.ADDCAMPAIGN'),
|
||||||
icon: 'plus',
|
icon: 'plus',
|
||||||
@ -138,7 +138,7 @@ class CampaignAdmin extends SilverStripeComponent {
|
|||||||
* Renders the Detail Edit Form for a Campaign.
|
* Renders the Detail Edit Form for a Campaign.
|
||||||
*/
|
*/
|
||||||
renderDetailEditView() {
|
renderDetailEditView() {
|
||||||
const baseSchemaUrl = this.props.sectionConfig.forms.DetailEditForm.schemaUrl;
|
const baseSchemaUrl = this.props.sectionConfig.form.DetailEditForm.schemaUrl;
|
||||||
const schemaUrl = `${baseSchemaUrl}/ChangeSet/${this.props.campaignId}`;
|
const schemaUrl = `${baseSchemaUrl}/ChangeSet/${this.props.campaignId}`;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -159,7 +159,7 @@ class CampaignAdmin extends SilverStripeComponent {
|
|||||||
* Render the view for creating a new Campaign.
|
* Render the view for creating a new Campaign.
|
||||||
*/
|
*/
|
||||||
renderCreateView() {
|
renderCreateView() {
|
||||||
const baseSchemaUrl = this.props.sectionConfig.forms.DetailEditForm.schemaUrl;
|
const baseSchemaUrl = this.props.sectionConfig.form.DetailEditForm.schemaUrl;
|
||||||
const formBuilderProps = {
|
const formBuilderProps = {
|
||||||
createFn: this.campaignCreationView,
|
createFn: this.campaignCreationView,
|
||||||
schemaUrl: `${baseSchemaUrl}/ChangeSet`,
|
schemaUrl: `${baseSchemaUrl}/ChangeSet`,
|
||||||
@ -294,7 +294,7 @@ CampaignAdmin.propTypes = {
|
|||||||
actions: React.PropTypes.object.isRequired,
|
actions: React.PropTypes.object.isRequired,
|
||||||
campaignId: React.PropTypes.string,
|
campaignId: React.PropTypes.string,
|
||||||
config: React.PropTypes.shape({
|
config: React.PropTypes.shape({
|
||||||
forms: React.PropTypes.shape({
|
form: React.PropTypes.shape({
|
||||||
editForm: React.PropTypes.shape({
|
editForm: React.PropTypes.shape({
|
||||||
schemaUrl: React.PropTypes.string,
|
schemaUrl: React.PropTypes.string,
|
||||||
}),
|
}),
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { ACTION_TYPES } from './FormsActionTypes';
|
import { ACTION_TYPES } from './FormActionTypes';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes a form from state.
|
* Removes a form from state.
|
@ -1,9 +1,9 @@
|
|||||||
import deepFreeze from 'deep-freeze';
|
import deepFreeze from 'deep-freeze';
|
||||||
import { ACTION_TYPES } from './FormsActionTypes';
|
import { ACTION_TYPES } from './FormActionTypes';
|
||||||
|
|
||||||
const initialState = deepFreeze({});
|
const initialState = deepFreeze({});
|
||||||
|
|
||||||
function formsReducer(state = initialState, action) {
|
function formReducer(state = initialState, action) {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
|
|
||||||
case ACTION_TYPES.REMOVE_FORM:
|
case ACTION_TYPES.REMOVE_FORM:
|
||||||
@ -47,4 +47,4 @@ function formsReducer(state = initialState, action) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default formsReducer;
|
export default formReducer;
|
@ -1,11 +1,11 @@
|
|||||||
# forms
|
# form
|
||||||
|
|
||||||
This state key holds form and form field data. Forms built using the `FormBuilder` component
|
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
|
```js
|
||||||
{
|
{
|
||||||
forms: {
|
form: {
|
||||||
DetailEditForm: {
|
DetailEditForm: {
|
||||||
fields: [
|
fields: [
|
||||||
{
|
{
|
@ -1,13 +1,14 @@
|
|||||||
|
/* global jest, describe, expect, it, beforeEach */
|
||||||
|
|
||||||
jest.unmock('deep-freeze');
|
jest.unmock('deep-freeze');
|
||||||
jest.unmock('../FormsReducer');
|
jest.unmock('../FormReducer');
|
||||||
jest.unmock('../FormsActionTypes');
|
jest.unmock('../FormActionTypes');
|
||||||
|
|
||||||
import deepFreeze from 'deep-freeze';
|
import deepFreeze from 'deep-freeze';
|
||||||
import { ACTION_TYPES } from '../FormsActionTypes';
|
import { ACTION_TYPES } from '../FormActionTypes';
|
||||||
import formsReducer from '../FormsReducer';
|
import formReducer from '../FormReducer';
|
||||||
|
|
||||||
describe('formsReducer', () => {
|
|
||||||
|
|
||||||
|
describe('formReducer', () => {
|
||||||
describe('ADD_FORM', () => {
|
describe('ADD_FORM', () => {
|
||||||
const initialState = deepFreeze({
|
const initialState = deepFreeze({
|
||||||
DetailEditForm: {
|
DetailEditForm: {
|
||||||
@ -40,7 +41,7 @@ describe('formsReducer', () => {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const nextState = formsReducer(initialState, {
|
const nextState = formReducer(initialState, {
|
||||||
type: ACTION_TYPES.ADD_FORM,
|
type: ACTION_TYPES.ADD_FORM,
|
||||||
payload,
|
payload,
|
||||||
});
|
});
|
||||||
@ -83,7 +84,7 @@ describe('formsReducer', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should remove the form', () => {
|
it('should remove the form', () => {
|
||||||
const nextState = formsReducer(initialState, {
|
const nextState = formReducer(initialState, {
|
||||||
type: ACTION_TYPES.REMOVE_FORM,
|
type: ACTION_TYPES.REMOVE_FORM,
|
||||||
payload: { formId: 'DetailEditForm' },
|
payload: { formId: 'DetailEditForm' },
|
||||||
});
|
});
|
||||||
@ -109,7 +110,7 @@ describe('formsReducer', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should update properties of a form field', () => {
|
it('should update properties of a form field', () => {
|
||||||
const nextState = formsReducer(initialState, {
|
const nextState = formReducer(initialState, {
|
||||||
type: ACTION_TYPES.UPDATE_FIELD,
|
type: ACTION_TYPES.UPDATE_FIELD,
|
||||||
payload: {
|
payload: {
|
||||||
formId: 'DetailEditForm',
|
formId: 'DetailEditForm',
|
||||||
@ -140,7 +141,7 @@ describe('formsReducer', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should add top level form messages', () => {
|
it('should add top level form messages', () => {
|
||||||
const nextState = formsReducer(initialState, {
|
const nextState = formReducer(initialState, {
|
||||||
type: ACTION_TYPES.SUBMIT_FORM_SUCCESS,
|
type: ACTION_TYPES.SUBMIT_FORM_SUCCESS,
|
||||||
payload: {
|
payload: {
|
||||||
id: 'DetailEditForm',
|
id: 'DetailEditForm',
|
@ -5,4 +5,4 @@ Manages state associated with the FormFieldSchema.
|
|||||||
When dependency injection is implemented, this will be moved into either Framework or CMS.
|
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.
|
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.
|
||||||
|
@ -52,7 +52,7 @@ class CampaignAdmin extends LeftAndMain implements PermissionProvider {
|
|||||||
|
|
||||||
public function getClientConfig() {
|
public function getClientConfig() {
|
||||||
return array_merge(parent::getClientConfig(), [
|
return array_merge(parent::getClientConfig(), [
|
||||||
'forms' => [
|
'form' => [
|
||||||
// TODO Use schemaUrl instead
|
// TODO Use schemaUrl instead
|
||||||
'EditForm' => [
|
'EditForm' => [
|
||||||
'schemaUrl' => $this->Link('schema/EditForm')
|
'schemaUrl' => $this->Link('schema/EditForm')
|
||||||
|
Loading…
Reference in New Issue
Block a user