Remove useless files in modelpage

This commit is contained in:
soupette 2019-03-20 17:50:11 +01:00
parent 4c7107ff35
commit 6c9f5579ca
11 changed files with 192 additions and 268 deletions

View File

@ -4,6 +4,7 @@
*
*/
/* eslint-disable */
import React from 'react';
import { bindActionCreators } from 'redux';
import { connect } from 'react-redux';
@ -33,7 +34,13 @@ import moment from 'moment';
import { router } from 'app';
import { temporaryContentTypeFieldsUpdated, storeTemporaryMenu } from '../App/actions';
import { addAttributeToContentType, addAttributeRelationToContentType, editContentTypeAttribute, editContentTypeAttributeRelation, updateContentType } from '../ModelPage/actions';
import {
addAttributeToContentType,
addAttributeRelationToContentType,
editContentTypeAttribute,
editContentTypeAttributeRelation,
updateContentType,
} from '../ModelPage/actions';
import AttributeCard from '../../components/AttributeCard';
import InputCheckboxWithNestedInputs from '../../components/InputCheckboxWithNestedInputs';
@ -71,7 +78,8 @@ import forms from './forms.json';
/* eslint-disable consistent-return */
/* eslint-disable react/jsx-wrap-multilines */
export class Form extends React.Component { // eslint-disable-line react/prefer-stateless-function
export class Form extends React.Component {
// eslint-disable-line react/prefer-stateless-function
constructor(props) {
super(props);
this.state = {
@ -114,7 +122,9 @@ export class Form extends React.Component { // eslint-disable-line react/prefer-
storeData.setMenu(newMenu);
}
// Close Modal
const redirectToModelPage = includes(this.props.redirectRoute, 'models') ? `/${this.props.modifiedDataEdit.name}` : '';
const redirectToModelPage = includes(this.props.redirectRoute, 'models')
? `/${this.props.modifiedDataEdit.name}`
: '';
router.push(`${this.props.redirectRoute}${redirectToModelPage}`);
// Reset props
this.props.resetIsFormSet();
@ -137,7 +147,9 @@ export class Form extends React.Component { // eslint-disable-line react/prefer-
}
addAttributeToContentType = (redirectToChoose = false) => {
const formErrors = this.checkAttributeValidations(checkFormValidity(this.props.modifiedDataAttribute, this.props.formValidations));
const formErrors = this.checkAttributeValidations(
checkFormValidity(this.props.modifiedDataAttribute, this.props.formValidations),
);
if (!isEmpty(formErrors)) {
return this.props.setFormErrors(formErrors);
@ -145,7 +157,11 @@ export class Form extends React.Component { // eslint-disable-line react/prefer-
// Check if user is adding a relation with the same content type
if (includes(this.props.hash, 'attributerelation') && this.props.modifiedDataAttribute.params.target === this.props.modelName && get(this.props.modifiedDataAttribute, ['params', 'nature'], '') !== 'oneWay') {
if (
includes(this.props.hash, 'attributerelation') &&
this.props.modifiedDataAttribute.params.target === this.props.modelName &&
get(this.props.modifiedDataAttribute, ['params', 'nature'], '') !== 'oneWay'
) {
// Insert two attributes
this.props.addAttributeRelationToContentType(this.props.modifiedDataAttribute);
} else {
@ -157,10 +173,12 @@ export class Form extends React.Component { // eslint-disable-line react/prefer-
// Empty errors
this.props.resetFormErrors();
this.redirectAfterSave(redirectToChoose);
}
};
addAttributeToTempContentType = (redirectToChoose = false) => {
const formErrors = this.checkAttributeValidations(checkFormValidity(this.props.modifiedDataAttribute, this.props.formValidations));
const formErrors = this.checkAttributeValidations(
checkFormValidity(this.props.modifiedDataAttribute, this.props.formValidations),
);
if (!isEmpty(formErrors)) {
return this.props.setFormErrors(formErrors);
@ -170,7 +188,11 @@ export class Form extends React.Component { // eslint-disable-line react/prefer-
const contentType = this.props.modifiedDataEdit;
// Add the new attribute to the content type attribute list
const newAttribute = this.setTempAttribute();
const parallelAttribute = this.props.modelName === get(newAttribute, ['params', 'target']) && get(newAttribute, ['params', 'nature'], '') === 'oneWay' ? null : this.setParallelAttribute(newAttribute);
const parallelAttribute =
this.props.modelName === get(newAttribute, ['params', 'target']) &&
get(newAttribute, ['params', 'nature'], '') === 'oneWay'
? null
: this.setParallelAttribute(newAttribute);
contentType.attributes = compact(concat(contentType.attributes, newAttribute, parallelAttribute));
// Reset the store and update the parent container
this.props.contentTypeCreate(contentType);
@ -184,16 +206,23 @@ export class Form extends React.Component { // eslint-disable-line react/prefer-
storeData.setModel(model);
this.props.resetFormErrors();
this.redirectAfterSave(redirectToChoose);
}
};
createContentType = (data) => {
createContentType = data => {
// Check form errors
const formErrors = checkFormValidity(data, this.props.formValidations);
// Check if content type name already exists
const sameContentTypeNames = filter(this.props.menuData[0].items, (contentType) => contentType.name === data.name);
const sameContentTypeNames = filter(
this.props.menuData[0].items,
contentType => contentType.name === data.name,
);
if (size(sameContentTypeNames) > 0 && (includes(this.props.hash, '#create') || data.name !== replace(split(this.props.hash, '::')[0], '#edit', ''))) {
formErrors.push({ name: 'name', errors: [{ id: 'content-type-builder.error.contentTypeName.taken' }]});
if (
size(sameContentTypeNames) > 0 &&
(includes(this.props.hash, '#create') ||
data.name !== replace(split(this.props.hash, '::')[0], '#edit', ''))
) {
formErrors.push({ name: 'name', errors: [{ id: 'content-type-builder.error.contentTypeName.taken' }] });
}
if (!isEmpty(formErrors)) {
@ -201,10 +230,16 @@ export class Form extends React.Component { // eslint-disable-line react/prefer-
}
const oldMenu = !isEmpty(this.props.menuData) ? this.props.menuData[0].items : [];
// Check if link already exist in the menu to remove it
const index = findIndex(oldMenu, [ 'name', replace(split(this.props.hash, '::')[0], '#edit', '')]);
const index = findIndex(oldMenu, ['name', replace(split(this.props.hash, '::')[0], '#edit', '')]);
// Insert at a specific position or before the add button the not saved contentType
const position = index !== -1 ? index : size(oldMenu) - 1;
oldMenu.splice(position, index !== -1 ? 1 : 0, { icon: 'fa-cube', fields: 0, description: data.description, name: data.name, isTemporary: true });
const position = index !== -1 ? index : size(oldMenu) - 1;
oldMenu.splice(position, index !== -1 ? 1 : 0, {
icon: 'fa-cube',
fields: 0,
description: data.description,
name: data.name,
isTemporary: true,
});
const newMenu = oldMenu;
const contentType = data;
@ -224,28 +259,33 @@ export class Form extends React.Component { // eslint-disable-line react/prefer-
// Close modal
const modelPage = includes(this.props.redirectRoute, 'models') ? '' : '/models';
router.push(`${this.props.redirectRoute}${modelPage}/${data.name}`);
}
};
checkForNestedInput = (item) => {
checkForNestedInput = item => {
const hasNestedInput = item.items && item.type !== 'select';
return hasNestedInput;
}
};
checkInputContentType = (item) => {
checkInputContentType = item => {
const shouldOverrideHandleBlur = item.name === 'name' && includes(this.props.hash, 'contentType');
return shouldOverrideHandleBlur;
}
};
// Function used when modified the name of the content type and not the attributes
// Fires Form sagas
contentTypeEdit = () => {
const formErrors = checkFormValidity(this.props.modifiedDataEdit, this.props.formValidations);
const sameContentTypeNames = filter(this.props.menuData[0].items, (contentType) => contentType.name === this.props.modifiedDataEdit.name);
const sameContentTypeNames = filter(
this.props.menuData[0].items,
contentType => contentType.name === this.props.modifiedDataEdit.name,
);
if (size(sameContentTypeNames) > 0 && this.props.modifiedDataEdit.name !== replace(split(this.props.hash, '::')[0], '#edit', '')) {
// if (size(sameContentTypeNames) > 0 && this.props.modifiedDataEdit.name !== this.props.modelName) {
formErrors.push({ name: 'name', errors: [{ id: 'content-type-builder.error.contentTypeName.taken' }]});
if (
size(sameContentTypeNames) > 0 &&
this.props.modifiedDataEdit.name !== replace(split(this.props.hash, '::')[0], '#edit', '')
) {
// if (size(sameContentTypeNames) > 0 && this.props.modifiedDataEdit.name !== this.props.modelName) {
formErrors.push({ name: 'name', errors: [{ id: 'content-type-builder.error.contentTypeName.taken' }] });
}
if (!isEmpty(formErrors)) {
@ -266,10 +306,12 @@ export class Form extends React.Component { // eslint-disable-line react/prefer-
this.setState({ showModal: false });
return this.props.contentTypeEdit(this.context);
}
};
editContentTypeAttribute = (redirectTochoose = false) => {
const formErrors = this.checkAttributeValidations(checkFormValidity(this.props.modifiedDataAttribute, this.props.formValidations));
const formErrors = this.checkAttributeValidations(
checkFormValidity(this.props.modifiedDataAttribute, this.props.formValidations),
);
const hashArray = split(this.props.hash, '::');
if (!isEmpty(formErrors)) {
@ -278,19 +320,30 @@ export class Form extends React.Component { // eslint-disable-line react/prefer-
if (!isUndefined(hashArray[4])) {
// Update the parent container (ModelPage)
this.props.editContentTypeAttributeRelation(this.props.modifiedDataAttribute, hashArray[3], hashArray[4], this.props.modifiedDataAttribute.params.target !== this.props.modelName);
this.props.editContentTypeAttributeRelation(
this.props.modifiedDataAttribute,
hashArray[3],
hashArray[4],
this.props.modifiedDataAttribute.params.target !== this.props.modelName,
);
} else {
this.props.editContentTypeAttribute(this.props.modifiedDataAttribute, hashArray[3], this.props.modifiedDataAttribute.params.target === this.props.modelName);
this.props.editContentTypeAttribute(
this.props.modifiedDataAttribute,
hashArray[3],
this.props.modifiedDataAttribute.params.target === this.props.modelName,
);
}
// Empty the store
this.props.resetIsFormSet();
// Empty errors
this.props.resetFormErrors();
this.redirectAfterSave(redirectTochoose);
}
};
editTempContentTypeAttribute = (redirectToChoose = false) => {
const formErrors = this.checkAttributeValidations(checkFormValidity(this.props.modifiedDataAttribute, this.props.formValidations));
const formErrors = this.checkAttributeValidations(
checkFormValidity(this.props.modifiedDataAttribute, this.props.formValidations),
);
if (!isEmpty(formErrors)) {
return this.props.setFormErrors(formErrors);
@ -303,10 +356,15 @@ export class Form extends React.Component { // eslint-disable-line react/prefer-
if (newAttribute.params.target === this.props.modelName) {
const parallelAttribute = this.setParallelAttribute(newAttribute);
contentType.attributes[findIndex(contentType.attributes, ['name', oldAttribute.params.key])] = parallelAttribute;
contentType.attributes[
findIndex(contentType.attributes, ['name', oldAttribute.params.key])
] = parallelAttribute;
}
if (oldAttribute.params.target === this.props.modelName && newAttribute.params.target !== this.props.modelName) {
if (
oldAttribute.params.target === this.props.modelName &&
newAttribute.params.target !== this.props.modelName
) {
contentType.attributes.splice(findIndex(contentType.attributes, ['name', oldAttribute.params.key]), 1);
}
@ -316,19 +374,19 @@ export class Form extends React.Component { // eslint-disable-line react/prefer-
// Empty errors
this.props.resetFormErrors();
storeData.setContentType(newContentType);
}
};
fetchModel = (contentTypeName) => {
fetchModel = contentTypeName => {
this.testContentType(
contentTypeName,
this.props.contentTypeFetchSucceeded,
{ model: storeData.getContentType() },
this.props.contentTypeFetch,
contentTypeName
contentTypeName,
);
}
};
generatePopUpTitle = (popUpFormType) => {
generatePopUpTitle = popUpFormType => {
let popUpTitle;
const type = split(this.props.hash, '::')[0];
@ -352,7 +410,7 @@ export class Form extends React.Component { // eslint-disable-line react/prefer-
}
return popUpTitle;
}
};
getValues = () => {
let values;
@ -370,23 +428,29 @@ export class Form extends React.Component { // eslint-disable-line react/prefer-
}
return values;
}
};
goToAttributeTypeView = (attributeType) => {
goToAttributeTypeView = attributeType => {
this.context.emitEvent('didSelectContentTypeFieldType', { type: attributeType });
const settings = attributeType === 'relation' ? 'defineRelation' : 'baseSettings';
router.push(`${this.props.routePath}#create${this.props.modelName}::attribute${attributeType}::${settings}`);
}
router.push(
`${this.props.routePath}#create${this.props.modelName}::attribute${attributeType}::${settings}`,
);
};
handleBlur = ({ target }) => {
if (target.name === 'name') {
this.props.changeInput(target.name, toLower(camelCase(target.value)), includes(this.props.hash, 'edit'));
this.props.changeInput(
target.name,
toLower(camelCase(target.value)),
includes(this.props.hash, 'edit'),
);
if (!isEmpty(target.value)) {
// The input name for content type doesn't have the default handleBlur validation so we need to manually remove the error
this.props.removeContentTypeRequiredError();
}
}
}
};
handleChange = ({ target }) => {
let value = target.type === 'number' && target.value !== '' ? toNumber(target.value) : target.value;
@ -410,18 +474,17 @@ export class Form extends React.Component { // eslint-disable-line react/prefer-
if (target.name === 'params.nature' && target.value === 'oneWay') {
this.props.changeInputAttribute('params.key', '-');
}
} else {
this.props.changeInput(target.name, value, includes(this.props.hash, 'edit'));
}
}
};
handleKeyBinding = (e) => {
handleKeyBinding = e => {
if (includes(this.props.hash, 'choose')) {
const { nodeToFocus } = this.state;
let toAdd = 0;
switch(e.keyCode) {
switch (e.keyCode) {
case 37: // Left arrow
case 39: // Right arrow
toAdd = nodeToFocus % 2 === 0 ? 1 : -1;
@ -434,7 +497,10 @@ export class Form extends React.Component { // eslint-disable-line react/prefer-
}
break;
case 40:
if (nodeToFocus === forms.attributesDisplay.items.length - 1 || nodeToFocus === forms.attributesDisplay.items.length - 2) {
if (
nodeToFocus === forms.attributesDisplay.items.length - 1 ||
nodeToFocus === forms.attributesDisplay.items.length - 2
) {
toAdd = -8;
} else {
toAdd = 2;
@ -451,11 +517,11 @@ export class Form extends React.Component { // eslint-disable-line react/prefer-
this.setState(prevState => ({ nodeToFocus: prevState.nodeToFocus + toAdd }));
}
}
};
handleSubmit = (e, redirectToChoose = true) => {
e.preventDefault();
const hashArray = split(this.props.hash, ('::'));
const hashArray = split(this.props.hash, '::');
const valueToReplace = includes(this.props.hash, '#create') ? '#create' : '#edit';
const contentTypeName = replace(hashArray[0], valueToReplace, '');
let cbSuccess;
@ -472,7 +538,9 @@ export class Form extends React.Component { // eslint-disable-line react/prefer-
case includes(hashArray[0], '#edit'): {
// Check if the user is editing the attribute
const isAttribute = includes(hashArray[1], 'attribute');
cbSuccess = isAttribute ? () => this.editTempContentTypeAttribute(redirectToChoose) : this.createContentType;
cbSuccess = isAttribute
? () => this.editTempContentTypeAttribute(redirectToChoose)
: this.createContentType;
dataSucces = isAttribute ? null : this.getModelWithCamelCaseName(this.props.modifiedDataEdit);
cbFail = isAttribute ? () => this.editContentTypeAttribute(redirectToChoose) : this.contentTypeEdit;
return this.testContentType(contentTypeName, cbSuccess, dataSucces, cbFail);
@ -483,12 +551,10 @@ export class Form extends React.Component { // eslint-disable-line react/prefer-
return this.testContentType(contentTypeName, cbSuccess, dataSucces, cbFail);
}
default: {
return this.createContentType(
this.getModelWithCamelCaseName(this.props.modifiedData)
);
return this.createContentType(this.getModelWithCamelCaseName(this.props.modifiedData));
}
}
}
};
getModelWithCamelCaseName = (model = {}) => {
if (isEmpty(model) || isEmpty(model.name)) {
@ -499,7 +565,7 @@ export class Form extends React.Component { // eslint-disable-line react/prefer-
...model,
name: toLower(camelCase(model.name)),
};
}
};
initComponent = (props, condition) => {
if (!isEmpty(props.hash)) {
@ -518,7 +584,9 @@ export class Form extends React.Component { // eslint-disable-line react/prefer-
if (isCreating) {
this.props.setAttributeForm(props.hash);
} else if (get(props.contentTypeData, 'name')) {
this.setState({ popUpTitleEdit: get(props.contentTypeData, ['attributes', split(props.hash, '::')[3], 'name']) });
this.setState({
popUpTitleEdit: get(props.contentTypeData, ['attributes', split(props.hash, '::')[3], 'name']),
});
this.props.setAttributeFormEdit(props.hash, props.contentTypeData);
}
break;
@ -531,35 +599,33 @@ export class Form extends React.Component { // eslint-disable-line react/prefer-
} else {
this.setState({ showModal: false });
}
}
};
renderModalBodyChooseAttributes = () => {
const attributesDisplay = has(this.context.plugins.toJS(), 'upload')
? forms.attributesDisplay.items
: forms.attributesDisplay.items.filter(obj => obj.type !== 'media'); // Don't display the media field if the upload plugin isn't installed
return (
map(attributesDisplay, (attribute, key) => (
<AttributeCard
key={key}
attribute={attribute}
autoFocus={key === 0}
routePath={this.props.routePath}
handleClick={this.goToAttributeTypeView}
nodeToFocus={this.state.nodeToFocus}
tabIndex={key}
resetNodeToFocus={this.resetNodeToFocus}
/>
))
);
}
return map(attributesDisplay, (attribute, key) => (
<AttributeCard
key={key}
attribute={attribute}
autoFocus={key === 0}
routePath={this.props.routePath}
handleClick={this.goToAttributeTypeView}
nodeToFocus={this.state.nodeToFocus}
tabIndex={key}
resetNodeToFocus={this.resetNodeToFocus}
/>
));
};
redirectAfterSave = (shouldOpenAttributesModal = false) => {
const { modelName, redirectRoute } = this.props;
const path = shouldOpenAttributesModal ? '#choose::attributes' : '';
router.push(`${redirectRoute}/${modelName}${path}`);
}
};
resetNodeToFocus = () => this.setState({ nodeToFocus: 0 });
@ -570,18 +636,18 @@ export class Form extends React.Component { // eslint-disable-line react/prefer-
} else {
cbFail(failData);
}
}
};
toggle = () => {
this.props.toggle();
// Set the isFormSet props to false when the modal is closing so the store is emptied
this.props.resetIsFormSet();
this.props.resetFormErrors();
}
};
overrideCustomBootstrapClass = () => {
return includes(this.props.hash, 'attributenumber');
}
};
renderInput = (item, key) => (
<InputCheckboxWithNestedInputs
@ -592,14 +658,20 @@ export class Form extends React.Component { // eslint-disable-line react/prefer-
errors={this.props.formErrors}
didCheckErrors={this.props.didCheckErrors}
/>
)
);
renderCustomPopUpHeader = (startTitle) => {
const italicText = !includes(this.props.hash, '#edit') ?
<FormattedMessage id='popUpForm.header' defaultMessage='{title}' values={{ title: replace(split(this.props.hash, ('::'))[1], 'attribute', '') }}>
{(message) => <span style={{ fontStyle: 'italic', textTransform: 'capitalize' }}>{message}</span>}
renderCustomPopUpHeader = startTitle => {
const italicText = !includes(this.props.hash, '#edit') ? (
<FormattedMessage
id="popUpForm.header"
defaultMessage="{title}"
values={{ title: replace(split(this.props.hash, '::')[1], 'attribute', '') }}
>
{message => <span style={{ fontStyle: 'italic', textTransform: 'capitalize' }}>{message}</span>}
</FormattedMessage>
: <span style={{ fontStyle: 'italic', textTransform: 'capitalize' }}>{this.state.popUpTitleEdit}</span>;
) : (
<span style={{ fontStyle: 'italic', textTransform: 'capitalize' }}>{this.state.popUpTitleEdit}</span>
);
return (
<div>
<FormattedMessage id={startTitle} />
@ -609,7 +681,7 @@ export class Form extends React.Component { // eslint-disable-line react/prefer-
<FormattedMessage id="content-type-builder.popUpForm.field" />
</div>
);
}
};
render() {
// Ensure typeof(popUpFormType) is String
@ -618,18 +690,33 @@ export class Form extends React.Component { // eslint-disable-line react/prefer-
const values = this.getValues();
const noNav = includes(this.props.hash, 'choose');
// Override the default rendering
const renderModalBody = includes(this.props.hash, '#choose') ? this.renderModalBodyChooseAttributes : false;
const renderModalBody = includes(this.props.hash, '#choose')
? this.renderModalBodyChooseAttributes
: false;
// Hide the button in the modal
const noButtons = includes(this.props.hash, '#choose');
const buttonSubmitMessage = includes(this.props.hash.split('::')[1], 'contentType') ? 'form.button.save' : 'form.button.continue';
const renderCustomPopUpHeader = !includes(this.props.hash, '#choose') && includes(this.props.hash, '::attribute') ? this.renderCustomPopUpHeader(popUpTitle) : false;
const dropDownItems = take(get(this.props.menuData, ['0', 'items']), size(get(this.props.menuData[0], 'items')) - 1);
const buttonSubmitMessage = includes(this.props.hash.split('::')[1], 'contentType')
? 'form.button.save'
: 'form.button.continue';
const renderCustomPopUpHeader =
!includes(this.props.hash, '#choose') && includes(this.props.hash, '::attribute')
? this.renderCustomPopUpHeader(popUpTitle)
: false;
const dropDownItems = take(
get(this.props.menuData, ['0', 'items']),
size(get(this.props.menuData[0], 'items')) - 1,
);
const edit = includes(this.props.hash, '#edit');
const selectOptions = includes(this.props.hash, 'attributenumber') ? get(this.props.form, ['items', '1', 'items']) : this.props.selectOptions;
const selectOptions = includes(this.props.hash, 'attributenumber')
? get(this.props.form, ['items', '1', 'items'])
: this.props.selectOptions;
if (includes(popUpFormType, 'relation')) {
const contentType = this.props.modelName.split('&source=');
const contentTypeIndex = contentType.length === 2 ? { name: contentType[0], source: contentType[1] } : { name: contentType[0] };
const contentTypeIndex =
contentType.length === 2
? { name: contentType[0], source: contentType[1] }
: { name: contentType[0] };
return (
<PopUpRelations
@ -680,8 +767,10 @@ export class Form extends React.Component { // eslint-disable-line react/prefer-
formErrors={this.props.formErrors}
didCheckErrors={this.props.didCheckErrors}
pluginID="content-type-builder"
overrideCustomBootstrapClass={includes(this.props.hash, 'attributenumber') && includes(this.props.hash, 'baseSettings')}
customBootstrapClass='col-md-6'
overrideCustomBootstrapClass={
includes(this.props.hash, 'attributenumber') && includes(this.props.hash, 'baseSettings')
}
customBootstrapClass="col-md-6"
/>
</div>
);
@ -721,7 +810,7 @@ function mapDispatchToProps(dispatch) {
temporaryContentTypeFieldsUpdated,
updateContentType,
},
dispatch
dispatch,
);
}
@ -738,10 +827,7 @@ Form.propTypes = {
didCheckErrors: PropTypes.bool.isRequired,
editContentTypeAttribute: PropTypes.func.isRequired,
editContentTypeAttributeRelation: PropTypes.func.isRequired,
form: PropTypes.oneOfType([
PropTypes.array.isRequired,
PropTypes.object.isRequired,
]).isRequired,
form: PropTypes.oneOfType([PropTypes.array.isRequired, PropTypes.object.isRequired]).isRequired,
formErrors: PropTypes.array.isRequired,
formValidations: PropTypes.array.isRequired,
hash: PropTypes.string.isRequired,
@ -777,6 +863,9 @@ Form.defaultProps = {
modelName: '',
};
const withConnect = connect(mapStateToProps, mapDispatchToProps);
const withConnect = connect(
mapStateToProps,
mapDispatchToProps,
);
export default withConnect(Form);

View File

@ -1,15 +0,0 @@
/*
*
* ModelPage actions
*
*/
import {
DEFAULT_ACTION,
} from './constants';
export function defaultAction() {
return {
type: DEFAULT_ACTION,
};
}

View File

@ -1,7 +0,0 @@
/*
*
* ModelPage constants
*
*/
export const DEFAULT_ACTION = 'ContentTypeBuilder/ModelPage/DEFAULT_ACTION';

View File

@ -7,7 +7,6 @@
import React from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import { createStructuredSelector } from 'reselect';
import { bindActionCreators, compose } from 'redux';
import { FormattedMessage } from 'react-intl';
import { Redirect } from 'react-router-dom';
@ -51,9 +50,6 @@ import {
import CustomLink from './CustomLink';
import makeSelectModelPage from './selectors';
import reducer from './reducer';
import saga from './saga';
import styles from './styles.scss';
import DocumentationSection from './DocumentationSection';
@ -612,10 +608,6 @@ ModelPage.propTypes = {
updateTempContentType: PropTypes.func.isRequired,
};
const mapStateToProps = createStructuredSelector({
modelpage: makeSelectModelPage(),
});
export function mapDispatchToProps(dispatch) {
return bindActionCreators(
{
@ -633,22 +625,8 @@ export function mapDispatchToProps(dispatch) {
}
const withConnect = connect(
mapStateToProps,
null,
mapDispatchToProps,
);
/* Remove this line if the container doesn't have a route and
* check the documentation to see how to create the container's store
*/
const withReducer = strapi.injectReducer({ key: 'modelPage', reducer, pluginId });
/* Remove the line below the container doesn't have a route and
* check the documentation to see how to create the container's store
*/
const withSaga = strapi.injectSaga({ key: 'modelPage', saga, pluginId });
export default compose(
withReducer,
withSaga,
withConnect,
)(ModelPage);
export default compose(withConnect)(ModelPage);

View File

@ -1,20 +0,0 @@
/*
*
* ModelPage reducer
*
*/
import { fromJS } from 'immutable';
// import {
// } from './constants';
const initialState = fromJS({});
function modelPageReducer(state = initialState, action) {
switch (action.type) {
default:
return state;
}
}
export default modelPageReducer;

View File

@ -1,6 +0,0 @@
// import { take, call, put, select } from 'redux-saga/effects';
// Individual exports for testing
export default function* defaultSaga() {
// See example in containers/HomePage/saga.js
}

View File

@ -1,26 +0,0 @@
import { createSelector } from 'reselect';
import pluginId from '../../pluginId';
/**
* Direct selector to the modelPage state domain
*/
const selectModelPageDomain = () => (state) => state.get(`${pluginId}_modelPage`);
/**
* Other specific selectors
*/
/**
* Default selector used by ModelPage
*/
const makeSelectModelPage = () => createSelector(
selectModelPageDomain(),
(substate) => substate.toJS()
);
export default makeSelectModelPage;
export {
selectModelPageDomain,
};

View File

@ -1,18 +0,0 @@
import {
defaultAction,
} from '../actions';
import {
DEFAULT_ACTION,
} from '../constants';
describe('ModelPage actions', () => {
describe('Default Action', () => {
it('has a type of DEFAULT_ACTION', () => {
const expected = {
type: DEFAULT_ACTION,
};
expect(defaultAction()).toEqual(expected);
});
});
});

View File

@ -1,9 +0,0 @@
import { fromJS } from 'immutable';
import modelPageReducer from '../reducer';
describe('modelPageReducer', () => {
it('returns the initial state', () => {
expect(modelPageReducer(undefined, {})).toEqual(fromJS({}));
});
});

View File

@ -1,15 +0,0 @@
/**
* Test sagas
*/
/* eslint-disable redux-saga/yield-effects */
// import { take, call, put, select } from 'redux-saga/effects';
// import { defaultSaga } from '../saga';
// const generator = defaultSaga();
describe('defaultSaga Saga', () => {
it('Expect to have unit tests specified', () => {
expect(true).toEqual(true);
});
});

View File

@ -1,27 +0,0 @@
import { fromJS } from 'immutable';
import makeSelectModelPageDomain, { selectModelPageDomain } from '../selectors';
import pluginId from '../../../pluginId';
describe('<ModelPage />, selectors', () => {
describe('makeSelectModelPageDomain', () => {
it('should return the globalState (.toJS())', () => {
const mockedState = fromJS({
[`${pluginId}_modelPage`]: fromJS({}),
});
expect(makeSelectModelPageDomain()(mockedState)).toEqual({});
});
});
describe('selectModelPageDomain', () => {
it('should return the globalState', () => {
const mockedState = fromJS({
[`${pluginId}_modelPage`]: fromJS({}),
});
expect(selectModelPageDomain()(mockedState)).toEqual(fromJS({}));
});
});
});