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';
|
2018-07-16 17:26:51 +02:00
|
|
|
import { get } from 'lodash';
|
2018-02-22 10:35:19 +01:00
|
|
|
|
|
|
|
// 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
|
|
|
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-07-16 17:26:51 +02:00
|
|
|
{props.displayedRelations.map(relationName => {
|
|
|
|
const relation = get(props.schema, ['relations', relationName], {});
|
2018-05-06 20:34:33 +02:00
|
|
|
const Select = ['oneWay', 'oneToOne', 'manyToOne', 'oneToManyMorph', 'oneToOneMorph'].includes(relation.nature) ? SelectOne : SelectMany;
|
2018-02-22 11:33:01 +01:00
|
|
|
|
|
|
|
return (
|
|
|
|
<Select
|
|
|
|
currentModelName={props.currentModelName}
|
2018-07-16 17:26:51 +02:00
|
|
|
key={relationName}
|
2018-02-22 11:33:01 +01:00
|
|
|
record={props.record}
|
|
|
|
relation={relation}
|
|
|
|
schema={props.schema}
|
|
|
|
setRecordAttribute={props.changeData}
|
|
|
|
location={props.location}
|
|
|
|
/>
|
|
|
|
);
|
2018-02-22 10:35:19 +01:00
|
|
|
})}
|
2018-02-21 15:33:58 +01:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-02-22 10:35:19 +01:00
|
|
|
EditRelations.defaultProps = {
|
2018-07-16 17:26:51 +02:00
|
|
|
displayedRelations: [],
|
2018-02-22 11:33:01 +01:00
|
|
|
record: {},
|
2018-02-22 10:35:19 +01:00
|
|
|
schema: {},
|
|
|
|
};
|
|
|
|
|
|
|
|
EditRelations.propTypes = {
|
2018-02-22 11:33:01 +01:00
|
|
|
changeData: PropTypes.func.isRequired,
|
|
|
|
currentModelName: PropTypes.string.isRequired,
|
2018-07-16 17:26:51 +02:00
|
|
|
displayedRelations: PropTypes.array,
|
2018-02-22 11:33:01 +01:00
|
|
|
location: PropTypes.object.isRequired,
|
|
|
|
record: PropTypes.object,
|
2018-02-22 10:35:19 +01:00
|
|
|
schema: PropTypes.object,
|
|
|
|
};
|
|
|
|
|
2018-02-21 15:33:58 +01:00
|
|
|
export default EditRelations;
|