Skip to content

Commit

Permalink
FIX Use new API for form names
Browse files Browse the repository at this point in the history
  • Loading branch information
ScopeyNZ committed Oct 16, 2018
1 parent d254223 commit 606ccab
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 39 deletions.
8 changes: 4 additions & 4 deletions client/src/components/ElementActions/SaveAction.js
Expand Up @@ -6,6 +6,7 @@ import AbstractAction from 'components/ElementActions/AbstractAction';
import backend from 'lib/Backend';
import i18n from 'i18n';
import { loadElementSchemaValue } from 'state/editor/loadElementSchemaValue';
import { loadElementFormStateName } from 'state/editor/loadElementFormStateName';

/**
* Using a REST backend, serialize the current form data and post it to the backend endpoint to save
Expand Down Expand Up @@ -79,13 +80,12 @@ const SaveAction = (MenuComponent) => (props) => {
};

function mapStateToProps(state, ownProps) {
// TODO Use `loadElementFormStateName` when Raissa's PR is merged
const formNamePattern = ('ElementForm_%s').replace('%s', ownProps.id);
const formName = loadElementFormStateName(ownProps.id);

let formData = null;

if (state.form.formState.element && state.form.formState.element[formNamePattern]) {
formData = state.form.formState.element[formNamePattern].values;
if (state.form.formState.element && state.form.formState.element[formName]) {
formData = state.form.formState.element[formName].values;
}

return {
Expand Down
4 changes: 2 additions & 2 deletions client/src/components/ElementEditor/Element.js
Expand Up @@ -60,7 +60,7 @@ class Element extends Component {
const { element, actions } = this.props;
const { initialTab } = this.state;

const formStateName = loadElementFormStateName(element.ID);
const formStateName = `element.${loadElementFormStateName(element.ID)}`;

if (!initialTab) {
this.setState({
Expand Down Expand Up @@ -209,7 +209,7 @@ class Element extends Component {
}

function mapStateToProps(state, ownProps) {
const elementName = loadElementFormStateName(ownProps.element.ID).split('.')[1];
const elementName = loadElementFormStateName(ownProps.element.ID);

// InlineEditForm will neither have been rendered nor wrapped in redux-form
if (!state.form.formState.element || !state.form.formState.element[elementName]) {
Expand Down
4 changes: 2 additions & 2 deletions client/src/components/ElementEditor/ElementEditor.js
Expand Up @@ -3,6 +3,7 @@ import { inject } from 'lib/Injector';
import { elementTypeType } from 'types/elementTypeType';
import { connect } from 'react-redux';
import { compose } from 'redux';
import { loadElementFormStateName } from 'state/editor/loadElementFormStateName';

/**
* The ElementEditor is used in the CMS to manage a list or nested lists of
Expand Down Expand Up @@ -35,8 +36,7 @@ ElementEditor.propTypes = {
ElementEditor.defaultProps = {};

function mapStateToProps(state) {
// TODO Use `loadElementFormStateName` when Raissa's PR is merged
const formNamePattern = ('ElementForm_%s').replace('%s', '[0-9]+');
const formNamePattern = loadElementFormStateName('[0-9]+');
const elementFormState = state.form.formState.element;

if (!elementFormState) {
Expand Down
2 changes: 1 addition & 1 deletion client/src/legacy/ElementEditor/entwine.js
Expand Up @@ -34,7 +34,7 @@ jQuery.entwine('ss', ($) => {
},

/**
* Make sure the editor has flushed all it's buffers before the form is submitted.
* Invalidate cache after the form is submitted to force apollo to re-fetch.
*/
'from .cms-edit-form': {
onaftersubmitform() {
Expand Down
28 changes: 0 additions & 28 deletions client/src/state/editor/getSerializedFormData.js

This file was deleted.

2 changes: 1 addition & 1 deletion client/src/state/editor/loadElementFormStateName.js
Expand Up @@ -12,7 +12,7 @@ export const loadElementFormStateName = (elementId = null) => {
const formNameTemplate = section.form.elementForm.formNameTemplate;

if (elementId) {
return `element.${formNameTemplate.replace('{id}', elementId)}`;
return formNameTemplate.replace('{id}', elementId);
}
return formNameTemplate;
};
2 changes: 1 addition & 1 deletion src/Forms/ElementalAreaField.php
Expand Up @@ -242,7 +242,7 @@ public function saveInto(DataObjectInterface $dataObject)
$fieldNamePrefix = sprintf(EditFormFactory::FIELD_NAMESPACE_TEMPLATE, $elementId, '');
$prefixLength = strlen($fieldNamePrefix);

foreach($data as $field => $datum) {
foreach ($data as $field => $datum) {
// Check that the field starts with a valid name
if (strpos($field, $fieldNamePrefix) !== 0) {
continue;
Expand Down

0 comments on commit 606ccab

Please sign in to comment.