mirror of
https://github.com/strapi/strapi.git
synced 2025-10-24 14:29:58 +00:00
Edit content type in all views
This commit is contained in:
parent
2d98f42b24
commit
3d03119897
@ -12,8 +12,13 @@ import { createStructuredSelector } from 'reselect';
|
||||
import { map } from 'lodash';
|
||||
import { pluginId } from 'app';
|
||||
import { define } from 'i18n';
|
||||
|
||||
import { makeSelectShouldRefetchContentType } from 'containers/Form/selectors';
|
||||
|
||||
import { storeData } from '../../utils/storeData';
|
||||
import messages from '../../translations/en.json';
|
||||
|
||||
|
||||
import styles from './styles.scss';
|
||||
import { modelsFetch } from './actions';
|
||||
|
||||
@ -28,6 +33,12 @@ class App extends React.Component {
|
||||
this.props.modelsFetch();
|
||||
}
|
||||
|
||||
componentWillReceiveProps(nextProps) {
|
||||
if (nextProps.shouldRefetchContentType !== this.props.shouldRefetchContentType) {
|
||||
this.props.modelsFetch();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
componentWillUnmount() {
|
||||
// Empty the app localStorage
|
||||
@ -58,6 +69,7 @@ App.propTypes = {
|
||||
children: React.PropTypes.node,
|
||||
exposedComponents: React.PropTypes.object.isRequired,
|
||||
modelsFetch: React.PropTypes.func,
|
||||
shouldRefetchContentType: React.PropTypes.bool,
|
||||
};
|
||||
|
||||
export function mapDispatchToProps(dispatch) {
|
||||
@ -69,7 +81,9 @@ export function mapDispatchToProps(dispatch) {
|
||||
)
|
||||
}
|
||||
|
||||
const mapStateToProps = createStructuredSelector({});
|
||||
const mapStateToProps = createStructuredSelector({
|
||||
shouldRefetchContentType: makeSelectShouldRefetchContentType(),
|
||||
});
|
||||
|
||||
// Wrap the component to inject dispatch and state into it
|
||||
export default connect(mapStateToProps, mapDispatchToProps)(App);
|
||||
|
||||
@ -37,7 +37,7 @@ function appReducer(state = initialState, action) {
|
||||
const modelsSize = size(state.get('models').toJS())
|
||||
return state
|
||||
.updateIn(['menu', '0', 'items'], (list) => list.splice(action.position, action.nbElementToRemove, action.newLink))
|
||||
.update('models', array => array.splice(action.nbElementToRemove === 0 ? modelsSize : modelsSize -1 , 1, action.newModel));
|
||||
.update('models', array => array.splice(action.nbElementToRemove === 0 ? modelsSize : modelsSize - 1 , 1, action.newModel));
|
||||
}
|
||||
default:
|
||||
return state;
|
||||
|
||||
@ -116,7 +116,29 @@ export class Form extends React.Component { // eslint-disable-line react/prefer-
|
||||
} else {
|
||||
this.setState({ showModal: false });
|
||||
}
|
||||
}
|
||||
|
||||
// Close modal when updating a content type && success updating
|
||||
if (nextProps.shouldRefetchContentType !== this.props.shouldRefetchContentType) {
|
||||
// Check if localStorage because the PluginLeftMenu is based on the localStorage
|
||||
if (storeData.getMenu()) {
|
||||
// Update localStorage
|
||||
const oldMenu = storeData.getMenu();
|
||||
const index = findIndex(oldMenu, ['name', replace(this.props.hash.split('::')[0], '#edit', '')]);
|
||||
const modifiedContentType = {
|
||||
name: this.props.modifiedDataEdit.name,
|
||||
icon: 'fa-caret-square-o-right',
|
||||
};
|
||||
|
||||
oldMenu.splice(index, 1, modifiedContentType);
|
||||
const newMenu = oldMenu;
|
||||
storeData.setMenu(newMenu);
|
||||
}
|
||||
|
||||
// Close Modal
|
||||
router.push(`${this.props.redirectRoute}/${this.props.modifiedDataEdit.name}`);
|
||||
// Reset props
|
||||
this.props.resetDidFetchModelProp();
|
||||
}
|
||||
}
|
||||
|
||||
@ -146,6 +168,8 @@ export class Form extends React.Component { // eslint-disable-line react/prefer-
|
||||
// Store new menu in localStorage and update App leftMenu
|
||||
this.props.storeTemporaryMenu(newMenu, position, index !== -1 ? 1 : 0);
|
||||
|
||||
this.props.resetDidFetchModelProp();
|
||||
|
||||
router.push(`${this.props.redirectRoute}/${data.name}`);
|
||||
}
|
||||
|
||||
@ -258,7 +282,6 @@ export class Form extends React.Component { // eslint-disable-line react/prefer-
|
||||
|
||||
toggle = () => {
|
||||
this.props.toggle();
|
||||
|
||||
// Set the didFetchModel props to false when the modal is closing so the store is emptied
|
||||
// Only for editing
|
||||
if (this.state.showModal && includes(this.props.hash, 'edit')) {
|
||||
@ -349,6 +372,7 @@ Form.propTypes = {
|
||||
selectOptionsFetchSucceeded: React.PropTypes.bool,
|
||||
setAttributeForm: React.PropTypes.func,
|
||||
setForm: React.PropTypes.func.isRequired,
|
||||
shouldRefetchContentType: React.PropTypes.bool,
|
||||
storeTemporaryMenu: React.PropTypes.func,
|
||||
toggle: React.PropTypes.func.isRequired,
|
||||
};
|
||||
|
||||
@ -9,6 +9,7 @@ import {
|
||||
CHANGE_INPUT,
|
||||
CHANGE_INPUT_ATTRIBUTE,
|
||||
CONNECTIONS_FETCH_SUCCEEDED,
|
||||
CONTENT_TYPE_ACTION_SUCCEEDED,
|
||||
CONTENT_TYPE_FETCH_SUCCEEDED,
|
||||
RESET_DID_FETCH_MODEL_PROP,
|
||||
SET_ATTRIBUTE_FORM,
|
||||
@ -28,6 +29,7 @@ const initialState = fromJS({
|
||||
modifiedDataEdit: Map(),
|
||||
isFormSet: false,
|
||||
didFetchModel: false,
|
||||
shouldRefetchContentType: false,
|
||||
});
|
||||
|
||||
function formReducer(state = initialState, action) {
|
||||
@ -41,6 +43,10 @@ function formReducer(state = initialState, action) {
|
||||
return state
|
||||
.set('selectOptions', List(action.connections))
|
||||
.set('selectOptionsFetchSucceeded', !state.get('selectOptionsFetchSucceeded'));
|
||||
case CONTENT_TYPE_ACTION_SUCCEEDED:
|
||||
return state
|
||||
.set('shouldRefetchContentType', !state.get('shouldRefetchContentType'))
|
||||
.set('initialDataEdit', state.get('modifiedDataEdit'));
|
||||
case CONTENT_TYPE_FETCH_SUCCEEDED:
|
||||
return state
|
||||
.set('didFetchModel', true)
|
||||
@ -48,12 +54,13 @@ function formReducer(state = initialState, action) {
|
||||
.set('modifiedDataEdit', action.data);
|
||||
case RESET_DID_FETCH_MODEL_PROP:
|
||||
return state
|
||||
.set('didFetchModel', false);
|
||||
.set('didFetchModel', false)
|
||||
.set('isFormSet', false);
|
||||
case SET_ATTRIBUTE_FORM: {
|
||||
if (state.get('isFormSet')) {
|
||||
return state.set('form', Map(action.form));
|
||||
}
|
||||
|
||||
|
||||
return state
|
||||
.set('isFormSet', true)
|
||||
.set('form', Map(action.form))
|
||||
|
||||
@ -34,6 +34,12 @@ export function* editContentType() {
|
||||
const requestUrl = `/content-type-builder/models/${initialContentType.name}`;
|
||||
|
||||
yield call(request, requestUrl, opts);
|
||||
|
||||
yield new Promise(resolve => {
|
||||
setTimeout(() => {
|
||||
resolve();
|
||||
}, 5000);
|
||||
});
|
||||
yield put(contentTypeActionSucceeded());
|
||||
|
||||
} catch(error) {
|
||||
|
||||
@ -39,6 +39,11 @@ const makeSelectDidFetchModel = () => createSelector(
|
||||
(substate) => substate.get('didFetchModel'),
|
||||
);
|
||||
|
||||
const makeSelectShouldRefetchContentType = () => createSelector(
|
||||
selectFormDomain(),
|
||||
(substate) => substate.get('shouldRefetchContentType'),
|
||||
);
|
||||
|
||||
export default selectForm;
|
||||
export {
|
||||
selectFormDomain,
|
||||
@ -46,4 +51,5 @@ export {
|
||||
makeSelectInitialDataEdit,
|
||||
makeSelectModifiedData,
|
||||
makeSelectModifiedDataEdit,
|
||||
makeSelectShouldRefetchContentType,
|
||||
};
|
||||
|
||||
@ -85,7 +85,7 @@ module.exports = {
|
||||
|
||||
if (!name) return ctx.badRequest(null, [{ messages: [{ id: 'request.error.name.missing' }] }]);
|
||||
if (!_.includes(Service.getConnections(), connection)) return ctx.badRequest(null, [{ messages: [{ id: 'request.error.connection.unknow' }] }]);
|
||||
if (strapi.models[name]) return ctx.badRequest(null, [{ messages: [{ id: 'request.error.model.exist' }] }]);
|
||||
if (strapi.models[name] && name !== model) return ctx.badRequest(null, [{ messages: [{ id: 'request.error.model.exist' }] }]);
|
||||
if (!strapi.models[model]) return ctx.badRequest(null, [{ messages: [{ id: 'request.error.model.unknow' }] }]);
|
||||
if (!_.isNaN(parseFloat(name[0]))) return ctx.badRequest(null, [{ messages: [{ id: 'request.error.model.name' }] }]);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user