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

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({}));
});
});
});