Add show buttons update content type delete dynamic

This commit is contained in:
cyril lopez 2017-08-31 10:28:10 +02:00
parent 2068dc7703
commit 6bfc8475bf
2 changed files with 10 additions and 4 deletions

View File

@ -45,8 +45,8 @@ class AttributeRow extends React.Component { // eslint-disable-line react/prefer
} }
toggleModalWarning = (e) => { toggleModalWarning = (e) => {
e.preventDefault(); // e.preventDefault();
e.stopPropagation() // e.stopPropagation()
this.setState({ showWarning: !this.state.showWarning }); this.setState({ showWarning: !this.state.showWarning });
} }

View File

@ -5,7 +5,7 @@
*/ */
import { fromJS, Map, List } from 'immutable'; import { fromJS, Map, List } from 'immutable';
// import { findIndex, differenceWith, isEqual, filter } from 'lodash'; import { size, differenceBy } from 'lodash';
/* eslint-disable new-cap */ /* eslint-disable new-cap */
import { import {
ADD_ATTRIBUTE_TO_CONTENT_TYPE, ADD_ATTRIBUTE_TO_CONTENT_TYPE,
@ -38,8 +38,14 @@ function modelPageReducer(state = initialState, action) {
.set('showButtons', false) .set('showButtons', false)
.set('model', state.get('initialModel')); .set('model', state.get('initialModel'));
case DELETE_ATTRIBUTE: { case DELETE_ATTRIBUTE: {
const contentTypeAttributes = state.getIn(['model', 'attributes']).toJS();
contentTypeAttributes.splice(action.position, 1);
const updatedContentTypeAttributes = contentTypeAttributes;
const showButtons = size(updatedContentTypeAttributes) !== size(state.getIn(['initialModel', 'attributes']).toJS())
|| size(differenceBy(state.getIn(['initialModel', 'attributes']).toJS(), updatedContentTypeAttributes, 'name')) > 0;
return state return state
.set('showButtons', true) .set('showButtons', showButtons)
.updateIn(['model', 'attributes'], (list) => list.splice(action.position, 1)); .updateIn(['model', 'attributes'], (list) => list.splice(action.position, 1));
} }
case MODEL_FETCH_SUCCEEDED: case MODEL_FETCH_SUCCEEDED: