2018-02-21 15:33:58 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* EditRelations
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
import React from 'react';
|
|
|
|
import { FormattedMessage } from 'react-intl';
|
2018-02-22 10:35:19 +01:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { map } from 'lodash';
|
|
|
|
|
|
|
|
// Components.
|
|
|
|
import SelectOne from 'components/SelectOne';
|
|
|
|
import SelectMany from 'components/SelectMany';
|
|
|
|
|
2018-02-21 15:33:58 +01:00
|
|
|
import styles from './styles.scss';
|
|
|
|
|
2018-02-22 10:35:19 +01:00
|
|
|
// TODO change handler names
|
|
|
|
/* eslint-disable react/jsx-handler-names */
|
|
|
|
function EditRelations(props) {
|
2018-02-21 15:33:58 +01:00
|
|
|
return (
|
|
|
|
<div className={styles.editFormRelations}>
|
|
|
|
<FormattedMessage id="content-manager.EditRelations.title">
|
|
|
|
{(message) => <h3>{message}</h3>}
|
|
|
|
</FormattedMessage>
|
2018-02-22 10:35:19 +01:00
|
|
|
{map(props.schema.relations, (relation, key) => {
|
|
|
|
switch (relation.nature) {
|
|
|
|
case 'oneWay':
|
|
|
|
case 'oneToOne':
|
|
|
|
case 'manyToOne':
|
|
|
|
if (relation.dominant) {
|
|
|
|
return (
|
|
|
|
<SelectOne
|
|
|
|
currentModelName={props.currentModelName}
|
|
|
|
key={key}
|
|
|
|
record={props.record}
|
|
|
|
relation={relation}
|
|
|
|
schema={props.schema}
|
|
|
|
setRecordAttribute={props.changeData}
|
|
|
|
location={props.location}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'oneToMany':
|
|
|
|
case 'manyToMany':
|
|
|
|
return (
|
|
|
|
<SelectMany
|
|
|
|
currentModelName={props.currentModelName}
|
|
|
|
key={key}
|
|
|
|
record={props.record}
|
|
|
|
relation={relation}
|
|
|
|
schema={props.schema}
|
|
|
|
setRecordAttribute={props.changeData}
|
|
|
|
location={props.location}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
})}
|
2018-02-21 15:33:58 +01:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-02-22 10:35:19 +01:00
|
|
|
EditRelations.defaultProps = {
|
|
|
|
schema: {},
|
|
|
|
};
|
|
|
|
|
|
|
|
EditRelations.propTypes = {
|
|
|
|
schema: PropTypes.object,
|
|
|
|
};
|
|
|
|
|
2018-02-21 15:33:58 +01:00
|
|
|
export default EditRelations;
|