Handle ctb post/put actions for plugin s models

This commit is contained in:
cyril lopez 2017-12-15 17:30:23 +01:00
parent d87a273196
commit a4638c26ad
5 changed files with 21 additions and 7 deletions

View File

@ -161,7 +161,7 @@ class PopUpRelations extends React.Component { // eslint-disable-line react/pref
const modalBody = this.props.showRelation ? this.renderModalBodyRelations(): this.renderModalBodyAdvanced();
const handleToggle = this.props.toggle;
return (
<div className={styles.popUpRelations}>
<Modal isOpen={this.props.isOpen} toggle={this.props.toggle} className={`${styles.modalPosition}`}>

View File

@ -530,6 +530,9 @@ export class Form extends React.Component { // eslint-disable-line react/prefer-
const selectOptions = includes(this.props.hash, 'attributenumber') ? get(this.props.form, ['items', '1', 'items']) : this.props.selectOptions;
if (includes(popUpFormType, 'relation')) {
const contentType = this.props.modelName.split('&source=');
const contentTypeIndex = contentType.length === 2 ? { name: contentType[0], source: contentType[1] } : { name: contentType[0] };
return (
<PopUpRelations
isOpen={this.state.showModal}
@ -537,7 +540,7 @@ export class Form extends React.Component { // eslint-disable-line react/prefer-
renderCustomPopUpHeader={renderCustomPopUpHeader}
popUpTitle={popUpTitle}
routePath={`${this.props.routePath}/${this.props.hash}`}
contentType={get(dropDownItems, [findIndex(dropDownItems, ['name', this.props.modelName])])}
contentType={get(dropDownItems, [findIndex(dropDownItems, contentTypeIndex)])}
form={this.props.form}
showRelation={includes(this.props.hash, 'defineRelation')}
onChange={this.handleChange}

View File

@ -155,10 +155,11 @@ export function setButtonLoader() {
};
}
export function submit(context) {
export function submit(context, modelName) {
return {
type: SUBMIT,
context,
modelName,
};
}

View File

@ -199,7 +199,7 @@ export class ModelPage extends React.Component { // eslint-disable-line react/pr
}
handleSubmit = () => {
this.props.submit(this.context);
this.props.submit(this.context, this.props.match.params.modelName);
}
toggleModal = () => {

View File

@ -1,6 +1,7 @@
import { LOCATION_CHANGE } from 'react-router-redux';
import {
capitalize,
cloneDeep,
forEach,
get,
includes,
@ -75,8 +76,8 @@ export function* submitChanges(action) {
yield put(setButtonLoader());
const modelName = get(storeData.getContentType(), 'name');
const body = yield select(makeSelectModel());
const data = yield select(makeSelectModel());
const body = cloneDeep(data);
map(body.attributes, (attribute, index) => {
// Remove the connection key from attributes
@ -89,18 +90,27 @@ export function* submitChanges(action) {
delete body.attributes[index].params.dominant;
}
if (includes(key, 'Value')) {
if (includes(key, 'Value') && key !== 'pluginValue') {
// Remove and set needed keys for params
set(body.attributes[index].params, replace(key, 'Value', ''), value);
unset(body.attributes[index].params, key);
}
if (key === 'pluginValue' && value) {
set(body.attributes[index].params, 'plugin', true);
}
if (!value) {
const paramsKey = includes(key, 'Value') ? replace(key,'Value', '') : key;
unset(body.attributes[index].params, paramsKey);
}
});
});
const pluginModel = action.modelName.split('&source=')[1];
if (pluginModel) {
set(body, 'plugin', pluginModel);
}
const method = modelName === body.name ? 'POST' : 'PUT';
const baseUrl = '/content-type-builder/models/';