mirror of
https://github.com/strapi/strapi.git
synced 2025-08-09 17:26:11 +00:00
Format model data to match inputs requirements
This commit is contained in:
parent
6bfc8475bf
commit
11d51c99e9
@ -44,7 +44,7 @@ class AttributeRow extends React.Component { // eslint-disable-line react/prefer
|
|||||||
this.setState({ showWarning: false });
|
this.setState({ showWarning: false });
|
||||||
}
|
}
|
||||||
|
|
||||||
toggleModalWarning = (e) => {
|
toggleModalWarning = () => {
|
||||||
// e.preventDefault();
|
// e.preventDefault();
|
||||||
// e.stopPropagation()
|
// e.stopPropagation()
|
||||||
this.setState({ showWarning: !this.state.showWarning });
|
this.setState({ showWarning: !this.state.showWarning });
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { FormattedMessage } from 'react-intl';
|
import { FormattedMessage } from 'react-intl';
|
||||||
import { map, includes, split } from 'lodash';
|
import { map, includes, split, isEmpty } from 'lodash';
|
||||||
import { Button, Modal, ModalHeader, ModalBody, ModalFooter } from 'reactstrap';
|
import { Button, Modal, ModalHeader, ModalBody, ModalFooter } from 'reactstrap';
|
||||||
import Input from 'components/Input';
|
import Input from 'components/Input';
|
||||||
import PopUpHeaderNavLink from 'components/PopUpHeaderNavLink';
|
import PopUpHeaderNavLink from 'components/PopUpHeaderNavLink';
|
||||||
@ -20,7 +20,7 @@ class PopUpForm extends React.Component { // eslint-disable-line react/prefer-st
|
|||||||
|
|
||||||
const shouldOverrideRendering = this.props.overrideRenderInputCondition ? this.props.overrideRenderInputCondition(item) : false;
|
const shouldOverrideRendering = this.props.overrideRenderInputCondition ? this.props.overrideRenderInputCondition(item) : false;
|
||||||
|
|
||||||
const value = this.props.values[item.target] && includes(item.target, '.') ? this.props.values[split(item.target, '.')[0]][split(item.target, '.')[1]] : this.props.values[item.target];
|
const value = !isEmpty(this.props.values) && includes(item.target, '.') ? this.props.values[split(item.target, '.')[0]][split(item.target, '.')[1]] : this.props.values[item.target];
|
||||||
|
|
||||||
if (shouldOverrideRendering) {
|
if (shouldOverrideRendering) {
|
||||||
return this.props.overrideRenderInput(item, key);
|
return this.props.overrideRenderInput(item, key);
|
||||||
|
@ -131,7 +131,7 @@ export function setAttributeForm(hash) {
|
|||||||
type: formType,
|
type: formType,
|
||||||
required: true,
|
required: true,
|
||||||
// TODO remove with correct value
|
// TODO remove with correct value
|
||||||
// minLength: true,
|
minLength: true,
|
||||||
// minLengthValue: 0,
|
// minLengthValue: 0,
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
* ModelPage actions
|
* ModelPage actions
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
import { get } from 'lodash';
|
import { forEach, get, includes, map, set } from 'lodash';
|
||||||
import { storeData } from '../../utils/storeData';
|
import { storeData } from '../../utils/storeData';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@ -62,7 +62,19 @@ export function modelFetch(modelName) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function modelFetchSucceeded(model) {
|
export function modelFetchSucceeded(data) {
|
||||||
|
const model = data;
|
||||||
|
const defaultKeys = ['required', 'unique', 'type'];
|
||||||
|
|
||||||
|
forEach(model.model.attributes, (attribute, index) => {
|
||||||
|
map(attribute.params, (value, key) => {
|
||||||
|
if (!includes(defaultKeys, key) && value) {
|
||||||
|
set(model.model.attributes[index].params, `${key}Value`, value);
|
||||||
|
set(model.model.attributes[index].params, key, true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
type: MODEL_FETCH_SUCCEEDED,
|
type: MODEL_FETCH_SUCCEEDED,
|
||||||
model,
|
model,
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { LOCATION_CHANGE } from 'react-router-redux';
|
import { LOCATION_CHANGE } from 'react-router-redux';
|
||||||
import { get } from 'lodash';
|
import { forEach, get, includes, map, replace, set, unset } from 'lodash';
|
||||||
import { takeLatest } from 'redux-saga';
|
import { takeLatest } from 'redux-saga';
|
||||||
import { call, take, put, fork, cancel, select } from 'redux-saga/effects';
|
import { call, take, put, fork, cancel, select } from 'redux-saga/effects';
|
||||||
|
|
||||||
@ -13,24 +13,6 @@ import { MODEL_FETCH, SUBMIT } from './constants';
|
|||||||
import { modelFetchSucceeded, postContentTypeSucceeded } from './actions';
|
import { modelFetchSucceeded, postContentTypeSucceeded } from './actions';
|
||||||
import { makeSelectModel } from './selectors';
|
import { makeSelectModel } from './selectors';
|
||||||
|
|
||||||
// Individual exports for testing
|
|
||||||
// export function* attributeDelete(action) {
|
|
||||||
// try {
|
|
||||||
// if (action.sendRequest) {
|
|
||||||
// const body = yield select(makeSelectModel());
|
|
||||||
// const requestUrl = `/content-type-builder/models/${action.modelName}`;
|
|
||||||
// const opts = {
|
|
||||||
// method: 'PUT',
|
|
||||||
// body,
|
|
||||||
// };
|
|
||||||
//
|
|
||||||
// yield call(request, requestUrl, opts);
|
|
||||||
// }
|
|
||||||
// } catch(error) {
|
|
||||||
// window.Strapi.notification.error('An error occured');
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
export function* fetchModel(action) {
|
export function* fetchModel(action) {
|
||||||
try {
|
try {
|
||||||
const requestUrl = `/content-type-builder/models/${action.modelName}`;
|
const requestUrl = `/content-type-builder/models/${action.modelName}`;
|
||||||
@ -49,6 +31,18 @@ export function* submitChanges() {
|
|||||||
const modelName = get(storeData.getContentType(), 'name');
|
const modelName = get(storeData.getContentType(), 'name');
|
||||||
|
|
||||||
const body = yield select(makeSelectModel());
|
const body = yield select(makeSelectModel());
|
||||||
|
map(body.attributes, (attribute, index) => {
|
||||||
|
forEach(attribute.params, (value, key) => {
|
||||||
|
if (includes(key, 'Value')) {
|
||||||
|
set(body.attributes[index].params, replace(key, 'Value', ''), value);
|
||||||
|
unset(body.attributes[index].params, key);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!value) {
|
||||||
|
unset(body.attributes[index].params, key);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})
|
||||||
|
|
||||||
const method = modelName === body.name ? 'POST' : 'PUT';
|
const method = modelName === body.name ? 'POST' : 'PUT';
|
||||||
const baseUrl = '/content-type-builder/models/';
|
const baseUrl = '/content-type-builder/models/';
|
||||||
|
Loading…
x
Reference in New Issue
Block a user