From 6bfc8475bfd049d98a7c7dbe98f68b31663f23ab Mon Sep 17 00:00:00 2001 From: cyril lopez Date: Thu, 31 Aug 2017 10:28:10 +0200 Subject: [PATCH] Add show buttons update content type delete dynamic --- .../admin/src/components/AttributeRow/index.js | 4 ++-- .../admin/src/containers/ModelPage/reducer.js | 10 ++++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/packages/strapi-plugin-content-type-builder/admin/src/components/AttributeRow/index.js b/packages/strapi-plugin-content-type-builder/admin/src/components/AttributeRow/index.js index 0c4fa6eb1c..6babaf2f96 100644 --- a/packages/strapi-plugin-content-type-builder/admin/src/components/AttributeRow/index.js +++ b/packages/strapi-plugin-content-type-builder/admin/src/components/AttributeRow/index.js @@ -45,8 +45,8 @@ class AttributeRow extends React.Component { // eslint-disable-line react/prefer } toggleModalWarning = (e) => { - e.preventDefault(); - e.stopPropagation() + // e.preventDefault(); + // e.stopPropagation() this.setState({ showWarning: !this.state.showWarning }); } diff --git a/packages/strapi-plugin-content-type-builder/admin/src/containers/ModelPage/reducer.js b/packages/strapi-plugin-content-type-builder/admin/src/containers/ModelPage/reducer.js index 20ed08dc65..58cb0a0fc4 100644 --- a/packages/strapi-plugin-content-type-builder/admin/src/containers/ModelPage/reducer.js +++ b/packages/strapi-plugin-content-type-builder/admin/src/containers/ModelPage/reducer.js @@ -5,7 +5,7 @@ */ import { fromJS, Map, List } from 'immutable'; -// import { findIndex, differenceWith, isEqual, filter } from 'lodash'; +import { size, differenceBy } from 'lodash'; /* eslint-disable new-cap */ import { ADD_ATTRIBUTE_TO_CONTENT_TYPE, @@ -38,8 +38,14 @@ function modelPageReducer(state = initialState, action) { .set('showButtons', false) .set('model', state.get('initialModel')); 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 - .set('showButtons', true) + .set('showButtons', showButtons) .updateIn(['model', 'attributes'], (list) => list.splice(action.position, 1)); } case MODEL_FETCH_SUCCEEDED: