Prevent the ctb from breaking if a user tries to edit an attribute that it cannot currently handle

This commit is contained in:
cyril lopez 2018-03-19 12:49:25 +01:00
parent d78c0a0200
commit c6b24f046b

View File

@ -26,6 +26,8 @@ import List from 'components/List';
import NoTableWarning from 'components/NoTableWarning';
import PluginLeftMenu from 'components/PluginLeftMenu';
import forms from 'containers/Form/forms.json';
import injectSaga from 'utils/injectSaga';
import injectReducer from 'utils/injectReducer';
@ -46,6 +48,9 @@ import reducer from './reducer';
import selectModelPage from './selectors';
import styles from './styles.scss';
// Array of attributes that the ctb can handle at the moment
const availableAttributes = Object.keys(forms.attribute);
/* eslint-disable jsx-a11y/no-static-element-interactions */
/* eslint-disable react/jsx-wrap-multilines */
@ -174,8 +179,8 @@ export class ModelPage extends React.Component { // eslint-disable-line react/pr
const index = findIndex(this.props.modelPage.model.attributes, ['name', attributeName]);
const attribute = this.props.modelPage.model.attributes[index];
// Remove enumeration type because it's not supported by this plugin for the moment.
if (attribute.params.type === 'enumeration') {
// Display a notification if the attribute is not present in the ones that the ctb handles
if (!includes(availableAttributes, attribute.params.type)) {
return strapi.notification.info('content-type-builder.notification.info.enumeration');
}
const settingsType = attribute.params.type ? 'baseSettings' : 'defineRelation';
@ -294,6 +299,7 @@ export class ModelPage extends React.Component { // eslint-disable-line react/pr
onButtonClick={this.handleClickAddAttribute}
/>;
const icoType = includes(this.props.match.params.modelName, '&source=') ? '' : 'pencil';
return (
<div className={styles.modelPage}>
<div className="container-fluid">