From 28c9339ace187ee1b88de0002851d3598f8e9def Mon Sep 17 00:00:00 2001 From: soupette Date: Thu, 13 Jun 2019 18:18:57 +0200 Subject: [PATCH] Finish Homepage --- .../src/components/Block/tests/index.test.js | 8 +- .../components/ButtonModalSuccess/index.js | 2 + .../components/DocumentationSection/index.js | 1 + .../src/components/Flex/tests/index.test.js | 8 +- .../components/ListTitle/tests/index.test.js | 8 +- .../src/components/Ul/tests/index.test.js | 8 +- .../admin/src/containers/App/actions.js | 2 +- .../admin/src/containers/App/index.js | 15 +- .../src/containers/App/tests/index.test.js | 8 + .../src/containers/AttributeForm/index.js | 3 +- .../admin/src/containers/HomePage/Row.js | 2 +- .../admin/src/containers/HomePage/index.js | 37 +-- .../containers/HomePage/tests/index.test.js | 232 +++++++++++------ .../admin/src/containers/ModelForm/index.js | 6 +- .../admin/src/containers/ModelPage/index.js | 59 +---- .../containers/ModelPage/tests/index.test.js | 11 +- .../containers/RelationForm/NaturePicker.js | 6 +- .../RelationForm/tests/InlineBlock.test.js | 4 +- .../admin/src/containers/HomePage/saga.js | 18 +- .../src/components/WithFormSection/index.js | 244 ++++++++++-------- .../admin/src/components/WithInput/index.js | 28 +- 21 files changed, 390 insertions(+), 320 deletions(-) diff --git a/packages/strapi-plugin-content-type-builder/admin/src/components/Block/tests/index.test.js b/packages/strapi-plugin-content-type-builder/admin/src/components/Block/tests/index.test.js index c0e5b3b349..c465d98f14 100644 --- a/packages/strapi-plugin-content-type-builder/admin/src/components/Block/tests/index.test.js +++ b/packages/strapi-plugin-content-type-builder/admin/src/components/Block/tests/index.test.js @@ -9,8 +9,12 @@ describe('', () => { }); it('should render his children', () => { - const Child = () =>
I'm a child
; - const wrapper = shallow(); + const Child = () =>
I am a child
; + const wrapper = shallow( + + + + ); expect(wrapper.find(Child).exists()).toBe(true); }); diff --git a/packages/strapi-plugin-content-type-builder/admin/src/components/ButtonModalSuccess/index.js b/packages/strapi-plugin-content-type-builder/admin/src/components/ButtonModalSuccess/index.js index 4bc46b2a19..edc0dace0b 100644 --- a/packages/strapi-plugin-content-type-builder/admin/src/components/ButtonModalSuccess/index.js +++ b/packages/strapi-plugin-content-type-builder/admin/src/components/ButtonModalSuccess/index.js @@ -19,11 +19,13 @@ function ButtonModalSuccess({ message, onClick, type }) { } ButtonModalSuccess.defaultProps = { + onClick: () => {}, type: 'button', }; ButtonModalSuccess.propTypes = { message: PropTypes.string.isRequired, + onClick: PropTypes.func, type: PropTypes.string, }; diff --git a/packages/strapi-plugin-content-type-builder/admin/src/components/DocumentationSection/index.js b/packages/strapi-plugin-content-type-builder/admin/src/components/DocumentationSection/index.js index 6c9cbf0751..7ee4cfdf58 100644 --- a/packages/strapi-plugin-content-type-builder/admin/src/components/DocumentationSection/index.js +++ b/packages/strapi-plugin-content-type-builder/admin/src/components/DocumentationSection/index.js @@ -23,6 +23,7 @@ const DocumentationSection = () => ( {message} diff --git a/packages/strapi-plugin-content-type-builder/admin/src/components/Flex/tests/index.test.js b/packages/strapi-plugin-content-type-builder/admin/src/components/Flex/tests/index.test.js index f0424ab39b..da18b7eb1a 100644 --- a/packages/strapi-plugin-content-type-builder/admin/src/components/Flex/tests/index.test.js +++ b/packages/strapi-plugin-content-type-builder/admin/src/components/Flex/tests/index.test.js @@ -9,8 +9,12 @@ describe('', () => { }); it('should render his children', () => { - const Child = () =>
I'm a child
; - const wrapper = shallow(); + const Child = () =>
I am a child
; + const wrapper = shallow( + + + + ); expect(wrapper.find(Child).exists()).toBe(true); }); diff --git a/packages/strapi-plugin-content-type-builder/admin/src/components/ListTitle/tests/index.test.js b/packages/strapi-plugin-content-type-builder/admin/src/components/ListTitle/tests/index.test.js index 264bd3e249..424b5d6da7 100644 --- a/packages/strapi-plugin-content-type-builder/admin/src/components/ListTitle/tests/index.test.js +++ b/packages/strapi-plugin-content-type-builder/admin/src/components/ListTitle/tests/index.test.js @@ -9,8 +9,12 @@ describe('', () => { }); it('should render his children', () => { - const Child = () =>
I'm a child
; - const wrapper = shallow(); + const Child = () =>
I am a child
; + const wrapper = shallow( + + + + ); expect(wrapper.find(Child).exists()).toBe(true); }); diff --git a/packages/strapi-plugin-content-type-builder/admin/src/components/Ul/tests/index.test.js b/packages/strapi-plugin-content-type-builder/admin/src/components/Ul/tests/index.test.js index 6f3c0b3fe1..e71385b990 100644 --- a/packages/strapi-plugin-content-type-builder/admin/src/components/Ul/tests/index.test.js +++ b/packages/strapi-plugin-content-type-builder/admin/src/components/Ul/tests/index.test.js @@ -9,8 +9,12 @@ describe('
    ', () => { }); it('should render its children', () => { - const Child = () =>
    I'm a child
    ; - const wrapper = shallow(
    ); + const Child = () =>
    I am a child
    ; + const wrapper = shallow( +
      + +
    + ); expect(wrapper.find(Child).exists()).toBe(true); }); diff --git a/packages/strapi-plugin-content-type-builder/admin/src/containers/App/actions.js b/packages/strapi-plugin-content-type-builder/admin/src/containers/App/actions.js index 0a709886cd..5c5dc3e9b3 100644 --- a/packages/strapi-plugin-content-type-builder/admin/src/containers/App/actions.js +++ b/packages/strapi-plugin-content-type-builder/admin/src/containers/App/actions.js @@ -170,7 +170,7 @@ export function getDataSucceeded({ allModels, models }, connections, { data }) { return acc; }, {}); - const groups = data.reduce((acc, current, i) => { + const groups = data.reduce((acc, current) => { const { name, schema: { attributes, description }, diff --git a/packages/strapi-plugin-content-type-builder/admin/src/containers/App/index.js b/packages/strapi-plugin-content-type-builder/admin/src/containers/App/index.js index 5ebe68cbaa..a8cc3e610e 100644 --- a/packages/strapi-plugin-content-type-builder/admin/src/containers/App/index.js +++ b/packages/strapi-plugin-content-type-builder/admin/src/containers/App/index.js @@ -9,7 +9,7 @@ import PropTypes from 'prop-types'; import { connect } from 'react-redux'; import { bindActionCreators, compose } from 'redux'; import { Switch, Route } from 'react-router-dom'; -import { get, isEmpty } from 'lodash'; +import { get } from 'lodash'; import { NotFound, getQueryParameters } from 'strapi-helper-plugin'; @@ -184,7 +184,6 @@ export class App extends React.Component { location: { pathname, search }, isLoading, models, - newContentType, newGroup, onChangeExistingContentTypeMainInfos, onChangeNewContentTypeMainInfos, @@ -271,12 +270,19 @@ App.defaultProps = { App.propTypes = { addAttributeRelation: PropTypes.func.isRequired, cancelNewContentType: PropTypes.func.isRequired, + connections: PropTypes.array.isRequired, + createTempContentType: PropTypes.func.isRequired, + createTempGroup: PropTypes.func.isRequired, deleteModel: PropTypes.func.isRequired, getData: PropTypes.func.isRequired, - isLoading: PropTypes.bool.isRequired, groups: PropTypes.array.isRequired, history: PropTypes.object.isRequired, + isLoading: PropTypes.bool.isRequired, + location: PropTypes.object.isRequired, models: PropTypes.array.isRequired, + modifiedData: PropTypes.object.isRequired, + newContentType: PropTypes.object.isRequired, + newGroup: PropTypes.object.isRequired, onChangeExistingContentTypeMainInfos: PropTypes.func.isRequired, onChangeNewContentTypeMainInfos: PropTypes.func.isRequired, onChangeNewGroupMainInfos: PropTypes.func.isRequired, @@ -285,7 +291,10 @@ App.propTypes = { saveEditedAttributeRelation: PropTypes.func.isRequired, setTemporaryAttribute: PropTypes.func.isRequired, setTemporaryAttributeRelation: PropTypes.func.isRequired, + resetExistingContentTypeMainInfos: PropTypes.func.isRequired, + resetNewContentTypeMainInfos: PropTypes.func.isRequired, shouldRefetchData: PropTypes.bool, + updateTempContentType: PropTypes.func.isRequired, }; const mapStateToProps = makeSelectApp(); diff --git a/packages/strapi-plugin-content-type-builder/admin/src/containers/App/tests/index.test.js b/packages/strapi-plugin-content-type-builder/admin/src/containers/App/tests/index.test.js index 382c361695..5f86ed7c4b 100644 --- a/packages/strapi-plugin-content-type-builder/admin/src/containers/App/tests/index.test.js +++ b/packages/strapi-plugin-content-type-builder/admin/src/containers/App/tests/index.test.js @@ -13,6 +13,9 @@ describe('', () => { props = { addAttributeRelation: jest.fn(), cancelNewContentType: jest.fn(), + connections: [], + createTempContentType: jest.fn(), + createTempGroup: jest.fn(), deleteModel: jest.fn(), history: { push: jest.fn(), @@ -76,6 +79,8 @@ describe('', () => { }, ], modifiedData: {}, + newContentType: {}, + newGroup: {}, onChangeExistingContentTypeMainInfos: jest.fn(), onChangeNewContentTypeMainInfos: jest.fn(), onChangeNewGroupMainInfos: jest.fn(), @@ -84,6 +89,9 @@ describe('', () => { setTemporaryAttribute: jest.fn(), setTemporaryAttributeRelation: jest.fn(), resetProps: jest.fn(), + resetExistingContentTypeMainInfos: jest.fn(), + resetNewContentTypeMainInfos: jest.fn(), + updateTempContentType: jest.fn(), }; }); diff --git a/packages/strapi-plugin-content-type-builder/admin/src/containers/AttributeForm/index.js b/packages/strapi-plugin-content-type-builder/admin/src/containers/AttributeForm/index.js index b56b00860e..d00f60fb0a 100644 --- a/packages/strapi-plugin-content-type-builder/admin/src/containers/AttributeForm/index.js +++ b/packages/strapi-plugin-content-type-builder/admin/src/containers/AttributeForm/index.js @@ -311,6 +311,7 @@ AttributeForm.defaultProps = { modifiedData: {}, onCancel: () => {}, onChange: () => {}, + onSubmit: () => {}, push: () => {}, }; @@ -324,7 +325,7 @@ AttributeForm.propTypes = { modifiedData: PropTypes.object, // TODO: Clearly define this object (It's working without it though) onCancel: PropTypes.func, onChange: PropTypes.func, - onChange: PropTypes.func, + onSubmit: PropTypes.func, onSubmitEdit: PropTypes.func.isRequired, push: PropTypes.func, }; diff --git a/packages/strapi-plugin-content-type-builder/admin/src/containers/HomePage/Row.js b/packages/strapi-plugin-content-type-builder/admin/src/containers/HomePage/Row.js index 619c3d94be..03a674b295 100644 --- a/packages/strapi-plugin-content-type-builder/admin/src/containers/HomePage/Row.js +++ b/packages/strapi-plugin-content-type-builder/admin/src/containers/HomePage/Row.js @@ -69,7 +69,7 @@ function Row({ e.stopPropagation(); const to = uid || name; - onClickGoTo(to, source, isTemporary); + onClickGoTo(to, source, canOpenModal || isTemporary); }} > diff --git a/packages/strapi-plugin-content-type-builder/admin/src/containers/HomePage/index.js b/packages/strapi-plugin-content-type-builder/admin/src/containers/HomePage/index.js index 390478f37e..0ab1f3cbf4 100644 --- a/packages/strapi-plugin-content-type-builder/admin/src/containers/HomePage/index.js +++ b/packages/strapi-plugin-content-type-builder/admin/src/containers/HomePage/index.js @@ -6,21 +6,17 @@ import React from 'react'; import PropTypes from 'prop-types'; -import { isEmpty } from 'lodash'; - import { HeaderNav, ListWrapper, ListHeader, List, PluginHeader, - getQueryParameters, routerPropTypes, } from 'strapi-helper-plugin'; import EmptyContentTypeView from '../../components/EmptyContentTypeView'; import pluginId from '../../pluginId'; -import ModelForm from '../ModelForm'; import Row from './Row'; import styles from './styles.scss'; @@ -77,7 +73,6 @@ class HomePage extends React.Component { handleGoTo = (to, source, shouldEdit = false) => { const { - canOpenModal, history: { push }, match: { params: { type }, @@ -85,10 +80,9 @@ class HomePage extends React.Component { } = this.props; const modalType = type === 'models' ? 'model' : 'group'; - const search = - shouldEdit || canOpenModal - ? `?modalType=${modalType}&settingType=base&actionType=edit&modelName=${to}` - : ''; + const search = shouldEdit + ? `?modalType=${modalType}&settingType=base&actionType=edit&modelName=${to}` + : ''; push( `/plugins/${pluginId}/${type}/${to.toLowerCase()}${ source ? `&source=${source}` : '' @@ -98,25 +92,16 @@ class HomePage extends React.Component { render() { const { - allGroupsAndModelsName, - cancelNewContentType, canOpenModal, - connections, - createTempContentType, deleteGroup, deleteModel, deleteTemporaryGroup, deleteTemporaryModel, groups, - history: { push }, - location: { pathname, search }, match: { params: { type }, }, models, - modifiedData, - newContentType, - onChangeNewContentTypeMainInfos, } = this.props; const displayedData = type === 'groups' ? groups : models; const availableNumber = type === 'groups' ? groups.length : models.length; @@ -176,22 +161,6 @@ class HomePage extends React.Component { )} - - {/* */} ); } diff --git a/packages/strapi-plugin-content-type-builder/admin/src/containers/HomePage/tests/index.test.js b/packages/strapi-plugin-content-type-builder/admin/src/containers/HomePage/tests/index.test.js index aee7671bc6..fcb3efc12b 100644 --- a/packages/strapi-plugin-content-type-builder/admin/src/containers/HomePage/tests/index.test.js +++ b/packages/strapi-plugin-content-type-builder/admin/src/containers/HomePage/tests/index.test.js @@ -2,10 +2,8 @@ import React from 'react'; import { shallow } from 'enzyme'; import pluginId from '../../../pluginId'; - +import { ListHeader } from 'strapi-helper-plugin'; import EmptyContentTypeView from '../../../components/EmptyContentTypeView'; -import TableList from '../../../components/TableList'; -import ModelForm from '../../ModelForm'; import HomePage from '../index'; @@ -71,7 +69,7 @@ describe('CTB ', () => { }, location: { search: '', - pathname: `/plugins/${pluginId}`, + pathname: `/plugins/${pluginId}/models`, }, }; }); @@ -82,93 +80,171 @@ describe('CTB ', () => { shallow(, { context }); }); - // describe('render', () => { - // it('should display the EmptyContentTypeView if there is no model in the application', () => { - // props.models = []; + describe('render', () => { + it('should display the EmptyContentTypeView if there is no model in the application', () => { + props.models = []; - // const context = { emitEvent: jest.fn() }; - // const wrapper = shallow(, { context }); - // const emptyView = wrapper.find(EmptyContentTypeView); + const context = { emitEvent: jest.fn() }; + const wrapper = shallow(, { context }); + const emptyView = wrapper.find(EmptyContentTypeView); - // expect(emptyView).toHaveLength(1); - // }); + expect(emptyView).toHaveLength(1); + }); - // it('the tableList should have a plural title if there is more than 1 model', () => { - // const context = { emitEvent: jest.fn() }; - // const wrapper = shallow(, { context }); - // const table = wrapper.find(TableList); + it('should display the EmptyContentTypeView if there is no model in the application', () => { + props.match.params.type = 'groups'; - // expect(table).toHaveLength(1); - // expect(table.prop('title')).toEqual( - // `${pluginId}.table.contentType.title.plural`, - // ); - // }); + const context = { emitEvent: jest.fn() }; + const wrapper = shallow(, { context }); + const emptyView = wrapper.find(EmptyContentTypeView); - // it('the tableList should have a singular title if there is more less 2 model', () => { - // props.models = [ - // { - // icon: 'fa-cube', - // name: 'permission', - // description: '', - // fields: 6, - // source: 'users-permissions', - // isTemporary: false, - // }, - // ]; + expect(emptyView).toHaveLength(1); + }); - // const context = { emitEvent: jest.fn() }; - // const wrapper = shallow(, { context }); - // const table = wrapper.find(TableList); + it('Should handle the listheader title correctly if there is more than 1 model', () => { + const context = { emitEvent: jest.fn() }; + const wrapper = shallow(, { context }); + const list = wrapper.find(ListHeader); - // expect(table).toHaveLength(1); - // expect(table.prop('title')).toEqual( - // `${pluginId}.table.contentType.title.singular`, - // ); - // }); - // }); + expect(list).toHaveLength(1); + expect(list.prop('title')).toBe( + `${pluginId}.table.contentType.title.plural` + ); + }); - // describe('workflow', () => { - // it('should open the modelForm if there is no saved content type', () => { - // props.canOpenModal = true; - // props.history.push = jest.fn(({ search }) => { - // props.location.search = `?${search}`; - // }); - // const context = { emitEvent: jest.fn() }; - // const wrapper = shallow(, { context }); - // const spyOnClick = jest.spyOn(wrapper.instance(), 'handleClick'); + it('Should handle the listheader title correctly if there is more than 1 group', () => { + props.groups = props.models; + props.match.params.type = 'groups'; + const context = { emitEvent: jest.fn() }; + const wrapper = shallow(, { context }); + const list = wrapper.find(ListHeader); - // wrapper.instance().forceUpdate(); - // // Simulate the click on button - // wrapper.find(TableList).prop('onButtonClick')(); - // wrapper.instance().forceUpdate(); + expect(list).toHaveLength(1); + expect(list.prop('title')).toBe(`${pluginId}.table.groups.title.plural`); + }); - // const form = wrapper.find(ModelForm).first(); + it('Should handle the listheader title correctly if there is less than 2 groups', () => { + props.groups = [ + { + icon: 'fa-cube', + name: 'user', + description: '', + fields: 6, + source: 'users-permissions', + isTemporary: false, + }, + ]; + props.match.params.type = 'groups'; + const context = { emitEvent: jest.fn() }; + const wrapper = shallow(, { context }); + const list = wrapper.find(ListHeader); - // expect(spyOnClick).toHaveBeenCalled(); - // expect(context.emitEvent).toHaveBeenCalledWith('willCreateContentType'); - // expect(props.history.push).toHaveBeenCalledWith({ - // search: 'modalType=model&settingType=base&actionType=create', - // }); - // expect(form.prop('isOpen')).toBe(true); - // }); + expect(list).toHaveLength(1); + expect(list.prop('title')).toBe( + `${pluginId}.table.groups.title.singular` + ); + }); - // it('should not open the modal if the is one or more not saved content type and display a notification', () => { - // props.canOpenModal = false; - // const context = { emitEvent: jest.fn() }; - // const wrapper = shallow(, { context }); + it('Should handle the listheader title correctly if there is less than 2 models', () => { + props.models = [ + { + icon: 'fa-cube', + name: 'user', + description: '', + fields: 6, + source: 'users-permissions', + isTemporary: false, + }, + ]; + const context = { emitEvent: jest.fn() }; + const wrapper = shallow(, { context }); + const list = wrapper.find(ListHeader); - // wrapper.find(TableList).prop('onButtonClick')(); - // wrapper.instance().forceUpdate(); + expect(list).toHaveLength(1); + expect(list.prop('title')).toBe( + `${pluginId}.table.contentType.title.singular` + ); + }); + }); - // const form = wrapper.find(ModelForm).first(); + describe('workflow', () => { + it('should open the modelForm for the model if there is no saved content type', () => { + props.canOpenModal = true; + props.history.push = jest.fn(({ search }) => { + props.location.search = `?${search}`; + }); - // expect(context.emitEvent).not.toHaveBeenCalled(); - // expect(props.history.push).not.toHaveBeenCalled(); - // expect(strapi.notification.info).toHaveBeenCalled(); - // expect(strapi.notification.info).toHaveBeenCalledWith( - // `${pluginId}.notification.info.contentType.creating.notSaved`, - // ); - // expect(form.prop('isOpen')).toBe(false); - // }); - // }); + const context = { emitEvent: jest.fn() }; + const wrapper = shallow(, { context }); + const spyOnClick = jest.spyOn(wrapper.instance(), 'handleClick'); + + wrapper.instance().forceUpdate(); + // Simulate the click on button + wrapper + .find(ListHeader) + .prop('button') + .onClick(); + wrapper.instance().forceUpdate(); + + expect(spyOnClick).toHaveBeenCalled(); + expect(context.emitEvent).toHaveBeenCalledWith('willCreateContentType'); + expect(props.history.push).toHaveBeenCalledWith({ + search: 'modalType=model&settingType=base&actionType=create', + }); + }); + + it('should open the modelForm for groups if there is no is no saved content type', () => { + props.canOpenModal = true; + props.groups = [ + { + icon: 'fa-cube', + name: 'user', + description: '', + fields: 6, + source: 'users-permissions', + isTemporary: false, + }, + ]; + props.location.pathname = `/plugins/${pluginId}/groups`; + props.history.push = jest.fn(({ search }) => { + props.location.search = `?${search}`; + }); + const context = { emitEvent: jest.fn() }; + const wrapper = shallow(, { context }); + const spyOnClick = jest.spyOn(wrapper.instance(), 'handleClick'); + + wrapper.instance().forceUpdate(); + // Simulate the click on button + wrapper + .find(ListHeader) + .prop('button') + .onClick(); + wrapper.instance().forceUpdate(); + + expect(spyOnClick).toHaveBeenCalled(); + expect(context.emitEvent).toHaveBeenCalledWith('willCreateContentType'); + expect(props.history.push).toHaveBeenCalledWith({ + search: 'modalType=model&settingType=base&actionType=create', + }); + }); + + it('should not open the modal if there is one not saved content type and display a notification', () => { + props.canOpenModal = false; + const context = { emitEvent: jest.fn() }; + const wrapper = shallow(, { context }); + + wrapper + .find(ListHeader) + .prop('button') + .onClick(); + wrapper.instance().forceUpdate(); + + expect(context.emitEvent).not.toHaveBeenCalled(); + expect(props.history.push).not.toHaveBeenCalled(); + expect(strapi.notification.info).toHaveBeenCalled(); + expect(strapi.notification.info).toHaveBeenCalledWith( + `${pluginId}.notification.info.work.notSaved` + ); + }); + }); }); diff --git a/packages/strapi-plugin-content-type-builder/admin/src/containers/ModelForm/index.js b/packages/strapi-plugin-content-type-builder/admin/src/containers/ModelForm/index.js index a36cd7ad1c..d8a07b4ed7 100644 --- a/packages/strapi-plugin-content-type-builder/admin/src/containers/ModelForm/index.js +++ b/packages/strapi-plugin-content-type-builder/admin/src/containers/ModelForm/index.js @@ -159,7 +159,11 @@ class ModelForm extends React.Component { link: ( {msg => ( - + {msg} )} diff --git a/packages/strapi-plugin-content-type-builder/admin/src/containers/ModelPage/index.js b/packages/strapi-plugin-content-type-builder/admin/src/containers/ModelPage/index.js index 3c5d84e0da..318ffbbe02 100644 --- a/packages/strapi-plugin-content-type-builder/admin/src/containers/ModelPage/index.js +++ b/packages/strapi-plugin-content-type-builder/admin/src/containers/ModelPage/index.js @@ -32,7 +32,6 @@ import Ul from '../../components/Ul'; import AttributeForm from '../AttributeForm'; import AttributesModalPicker from '../AttributesPickerModal'; -import ModelForm from '../ModelForm'; import RelationForm from '../RelationForm'; import LeftMenu from '../LeftMenu'; @@ -101,18 +100,18 @@ export class ModelPage extends React.Component { getAttributeType = () => getQueryParameters(this.getSearch(), 'attributeType'); - getFormData = () => { - const { modifiedData, newContentType } = this.props; + // getFormData = () => { + // const { modifiedData, newContentType } = this.props; - if ( - this.getActionType() === 'create' || - this.isUpdatingTemporaryContentType() - ) { - return newContentType; - } + // if ( + // this.getActionType() === 'create' || + // this.isUpdatingTemporaryContentType() + // ) { + // return newContentType; + // } - return get(modifiedData, this.getModelName()); - }; + // return get(modifiedData, this.getModelName()); + // }; getModalType = () => getQueryParameters(this.getSearch(), 'modalType'); @@ -503,27 +502,18 @@ export class ModelPage extends React.Component { render() { const listTitleMessageIdBasePrefix = `${pluginId}.modelPage.contentType.list.title`; const { - cancelNewContentType, - connections, clearTemporaryAttribute, clearTemporaryAttributeRelation, - createTempContentType, history: { push }, - location: { pathname, search }, + location: { search }, models, - modifiedData, onChangeAttribute, - onChangeExistingContentTypeMainInfos, - onChangeNewContentTypeMainInfos, onChangeRelation, onChangeRelationNature, onChangeRelationTarget, - resetExistingContentTypeMainInfos, - resetNewContentTypeMainInfos, setTemporaryAttributeRelation, temporaryAttribute, temporaryAttributeRelation, - updateTempContentType, } = this.props; const { showWarning, removePrompt } = this.state; @@ -642,28 +632,6 @@ export class ModelPage extends React.Component { onSubmitEdit={this.handleSubmitEdit} push={push} /> - {/* */} ', () => { name: '', attributes: {}, }, - onChangeExistingContentTypeMainInfos: jest.fn(), - onChangeNewContentTypeMainInfos: jest.fn(), onChangeAttribute: jest.fn(), onChangeRelation: jest.fn(), onChangeRelationNature: jest.fn(), onChangeRelationTarget: jest.fn(), resetEditExistingContentType: jest.fn(), resetEditTempContentType: jest.fn(), - resetExistingContentTypeMainInfos: jest.fn(), - resetNewContentTypeMainInfos: jest.fn(), + saveEditedAttribute: jest.fn(), saveEditedAttributeRelation: jest.fn(), setTemporaryAttribute: jest.fn(), @@ -154,7 +151,6 @@ describe('', () => { target: '', unique: false, }, - updateTempContentType: jest.fn(), }; }); @@ -427,16 +423,12 @@ describe(' lifecycle', () => { name: '', attributes: {}, }, - onChangeExistingContentTypeMainInfos: jest.fn(), - onChangeNewContentTypeMainInfos: jest.fn(), onChangeAttribute: jest.fn(), onChangeRelation: jest.fn(), onChangeRelationNature: jest.fn(), onChangeRelationTarget: jest.fn(), resetEditExistingContentType: jest.fn(), resetEditTempContentType: jest.fn(), - resetExistingContentTypeMainInfos: jest.fn(), - resetNewContentTypeMainInfos: jest.fn(), saveEditedAttribute: jest.fn(), saveEditedAttributeRelation: jest.fn(), setTemporaryAttribute: jest.fn(), @@ -455,7 +447,6 @@ describe(' lifecycle', () => { target: '', unique: false, }, - updateTempContentType: jest.fn(), }; }); diff --git a/packages/strapi-plugin-content-type-builder/admin/src/containers/RelationForm/NaturePicker.js b/packages/strapi-plugin-content-type-builder/admin/src/containers/RelationForm/NaturePicker.js index 075975e28b..212703e778 100644 --- a/packages/strapi-plugin-content-type-builder/admin/src/containers/RelationForm/NaturePicker.js +++ b/packages/strapi-plugin-content-type-builder/admin/src/containers/RelationForm/NaturePicker.js @@ -1,6 +1,6 @@ import React from 'react'; import PropTypes from 'prop-types'; -import { camelCase, truncate } from 'lodash'; +import { truncate } from 'lodash'; import { FormattedMessage } from 'react-intl'; import pluralize from 'pluralize'; @@ -57,14 +57,14 @@ const NaturePicker = ({ modelName, onClick, nature, target }) => { leftName: pluralize(modelName, nature === 'manyToMany' ? 2 : 1), rightName: pluralize( target, - ['manyToMany', 'oneToMany', 'manyToOne'].includes(nature) ? 2 : 1, + ['manyToMany', 'oneToMany', 'manyToOne'].includes(nature) ? 2 : 1 ), } : { leftName: target, rightName: pluralize( modelName, - ['manyToMany', 'oneToMany', 'manyToOne'].includes(nature) ? 2 : 1, + ['manyToMany', 'oneToMany', 'manyToOne'].includes(nature) ? 2 : 1 ), }; diff --git a/packages/strapi-plugin-content-type-builder/admin/src/containers/RelationForm/tests/InlineBlock.test.js b/packages/strapi-plugin-content-type-builder/admin/src/containers/RelationForm/tests/InlineBlock.test.js index faceb26ce3..a5a6d71a2d 100644 --- a/packages/strapi-plugin-content-type-builder/admin/src/containers/RelationForm/tests/InlineBlock.test.js +++ b/packages/strapi-plugin-content-type-builder/admin/src/containers/RelationForm/tests/InlineBlock.test.js @@ -9,11 +9,11 @@ describe('', () => { }); it('should render his children', () => { - const Child = () =>
    I'm a child
    ; + const Child = () =>
    I am a child
    ; const wrapper = shallow( - , +
    ); expect(wrapper.find(Child).exists()).toBe(true); diff --git a/packages/strapi-plugin-documentation/admin/src/containers/HomePage/saga.js b/packages/strapi-plugin-documentation/admin/src/containers/HomePage/saga.js index 53e366af7e..e53ad7a5d4 100755 --- a/packages/strapi-plugin-documentation/admin/src/containers/HomePage/saga.js +++ b/packages/strapi-plugin-documentation/admin/src/containers/HomePage/saga.js @@ -62,7 +62,7 @@ function* submit() { return yield put( setFormErrors({ password: [{ id: 'components.Input.error.validation.required' }], - }), + }) ); } @@ -95,12 +95,16 @@ function* updateDoc(action) { // Individual exports for testing export function* defaultSaga() { - yield all([ - fork(takeLatest, GET_DOC_INFOS, getData), - fork(takeLatest, ON_CONFIRM_DELETE_DOC, deleteDoc), - fork(takeLatest, ON_SUBMIT, submit), - fork(takeLatest, ON_UPDATE_DOC, updateDoc), - ]); + try { + yield all([ + fork(takeLatest, GET_DOC_INFOS, getData), + fork(takeLatest, ON_CONFIRM_DELETE_DOC, deleteDoc), + fork(takeLatest, ON_SUBMIT, submit), + fork(takeLatest, ON_UPDATE_DOC, updateDoc), + ]); + } catch (err) { + // Do nothing + } } // All sagas to be loaded diff --git a/packages/strapi-plugin-settings-manager/admin/src/components/WithFormSection/index.js b/packages/strapi-plugin-settings-manager/admin/src/components/WithFormSection/index.js index f90e955026..1f037006e7 100644 --- a/packages/strapi-plugin-settings-manager/admin/src/components/WithFormSection/index.js +++ b/packages/strapi-plugin-settings-manager/admin/src/components/WithFormSection/index.js @@ -1,12 +1,22 @@ /** -* -* WithFormSection -* -*/ + * + * WithFormSection + * + */ import React from 'react'; import PropTypes from 'prop-types'; -import { findIndex, forEach, has, isObject , join, pullAt, split, includes} from 'lodash'; +import { + findIndex, + forEach, + has, + isObject, + join, + pullAt, + split, + includes, +} from 'lodash'; +/* eslint-disable */ import InputNumber from '../InputNumber'; import InputText from '../InputText'; @@ -18,128 +28,146 @@ import config from './config.json'; import styles from './styles.scss'; /* eslint-disable react/require-default-props */ -const WithFormSection = (InnerComponent) => class extends React.Component { - static propTypes = { - addRequiredInputDesign: PropTypes.bool, - cancelAction: PropTypes.bool, - formErrors: PropTypes.array, - onChange: PropTypes.func, - section: PropTypes.oneOfType([ - PropTypes.object, - PropTypes.array, - ]), - values: PropTypes.object, - } - - constructor(props) { - super(props); - this.state = { - hasNestedInput: false, - showNestedForm: false, - inputWithNestedForm: '', +const WithFormSection = InnerComponent => + class extends React.Component { + static propTypes = { + addRequiredInputDesign: PropTypes.bool, + cancelAction: PropTypes.bool, + formErrors: PropTypes.array, + onChange: PropTypes.func, + section: PropTypes.oneOfType([PropTypes.object, PropTypes.array]), + values: PropTypes.object, }; - this.inputs = { - string: InputText, - password: InputPassword, - number: InputNumber, - boolean: InputToggle, - enum: InputEnum, - select: InputSelect, - }; - } + constructor(props) { + super(props); + this.state = { + hasNestedInput: false, + showNestedForm: false, + inputWithNestedForm: '', + }; - componentDidMount() { - // check if there is inside a section an input that requires nested input to display it on the entire line - if (isObject(this.props.section)) { - this.checkForNestedForm(this.props); + this.inputs = { + string: InputText, + password: InputPassword, + number: InputNumber, + boolean: InputToggle, + enum: InputEnum, + select: InputSelect, + }; } - } - componentWillReceiveProps(nextProps) { - if (nextProps.section !== this.props.section || nextProps.cancelAction !== this.props.cancelAction) { - this.setState({ showNestedForm: false, hasNestedInput: false, inputWithNestedForm: '' }); - if (isObject(nextProps.section)) { - this.checkForNestedForm(nextProps); + componentDidMount() { + // check if there is inside a section an input that requires nested input to display it on the entire line + if (isObject(this.props.section)) { + this.checkForNestedForm(this.props); } } - } - checkForNestedForm(props) { - forEach(props.section.items, (input) => { - if(has(input, 'items')) { - this.setState({ hasNestedInput: true, inputWithNestedForm: input.target }); - - if (props.values[input.target]) { - this.setState({ showNestedForm: true }); + componentWillReceiveProps(nextProps) { + if ( + nextProps.section !== this.props.section || + nextProps.cancelAction !== this.props.cancelAction + ) { + this.setState({ + showNestedForm: false, + hasNestedInput: false, + inputWithNestedForm: '', + }); + if (isObject(nextProps.section)) { + this.checkForNestedForm(nextProps); } } - }); - } - - handleChange = ({ target }) => { - // display nestedForm if the selected input has a nested form - if (target.name === this.state.inputWithNestedForm) { - this.setState({ showNestedForm: target.value }); } - this.props.onChange({ target }); - } + checkForNestedForm(props) { + forEach(props.section.items, input => { + if (has(input, 'items')) { + this.setState({ + hasNestedInput: true, + inputWithNestedForm: input.target, + }); - renderInput = (props, key) => { - const Input = this.inputs[props.type]; - const inputValue = this.props.values[props.target]; - // retrieve options for the select input - const selectOptions = props.type === 'enum' || props.type === 'select' ? props.items : []; + if (props.values[input.target]) { + this.setState({ showNestedForm: true }); + } + } + }); + } - // custom check for dynamic keys used for databases - const dynamicTarget = join(pullAt(split(props.target, '.'),['0', '1', '3', '4']), '.'); + handleChange = ({ target }) => { + // display nestedForm if the selected input has a nested form + if (target.name === this.state.inputWithNestedForm) { + this.setState({ showNestedForm: target.value }); + } - // check if the input has a nested form so it is displayed on the entire line - const customBootstrapClass = this.state.hasNestedInput ? - // bootstrap class to make the input displayed on the entire line - 'col-md-6 offset-md-6 mr-md-5' : - // if the input hasn't a nested form but the config requires him to be displayed differently - config[props.target] || config[dynamicTarget] || ''; + this.props.onChange({ target }); + }; - // custom handleChange props for nested input form - const handleChange = this.state.hasNestedInput ? this.handleChange : this.props.onChange; - let hiddenLabel = includes(props.name, 'enabled'); + renderInput = (props, key) => { + const Input = this.inputs[props.type]; + const inputValue = this.props.values[props.target]; + // retrieve options for the select input + const selectOptions = + props.type === 'enum' || props.type === 'select' ? props.items : []; - if (includes(config.showInputLabel, props.name)) hiddenLabel = false; + // custom check for dynamic keys used for databases + const dynamicTarget = join( + pullAt(split(props.target, '.'), ['0', '1', '3', '4']), + '.' + ); - const errorIndex = findIndex(this.props.formErrors, ['target', props.target]); - const errors = errorIndex !== -1 ? this.props.formErrors[errorIndex].errors : []; + // check if the input has a nested form so it is displayed on the entire line + const customBootstrapClass = this.state.hasNestedInput + ? // bootstrap class to make the input displayed on the entire line + 'col-md-6 offset-md-6 mr-md-5' + : // if the input hasn't a nested form but the config requires him to be displayed differently + config[props.target] || config[dynamicTarget] || ''; - return ( - - ); - } + // custom handleChange props for nested input form + const handleChange = this.state.hasNestedInput + ? this.handleChange + : this.props.onChange; + let hiddenLabel = includes(props.name, 'enabled'); - render() { - return ( - - ); - } -}; + if (includes(config.showInputLabel, props.name)) hiddenLabel = false; + + const errorIndex = findIndex(this.props.formErrors, [ + 'target', + props.target, + ]); + const errors = + errorIndex !== -1 ? this.props.formErrors[errorIndex].errors : []; + + return ( + + ); + }; + + render() { + return ( + + ); + } + }; export default WithFormSection; diff --git a/packages/strapi-plugin-settings-manager/admin/src/components/WithInput/index.js b/packages/strapi-plugin-settings-manager/admin/src/components/WithInput/index.js index cdad423feb..237a085f0e 100644 --- a/packages/strapi-plugin-settings-manager/admin/src/components/WithInput/index.js +++ b/packages/strapi-plugin-settings-manager/admin/src/components/WithInput/index.js @@ -1,23 +1,21 @@ /** -* -* WithInput -* -*/ + * + * WithInput + * + */ import React from 'react'; import styles from './styles.scss'; +/* eslint-disable */ + /* eslint-disable react/require-default-props */ -const WithInput = (InnerInput) => class extends React.Component { // eslint-disable-line react/prefer-stateless-function - render() { - return ( - - ); - } -}; +const WithInput = InnerInput => + class extends React.Component { + // eslint-disable-line react/prefer-stateless-function + render() { + return ; + } + }; export default WithInput;