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-02-26 14:53:13 +01:00
|
|
|
import { get, map } 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-26 14:53:13 +01:00
|
|
|
const filterRelationsUpload = (data) => Object.keys(data).reduce((acc, current) => {
|
|
|
|
if (get(data, [current, 'plugin']) !== 'upload') {
|
|
|
|
acc[current] = data[current];
|
|
|
|
}
|
|
|
|
|
|
|
|
return acc;
|
|
|
|
}, {});
|
|
|
|
|
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-02-26 14:53:13 +01:00
|
|
|
{map(filterRelationsUpload(props.schema.relations), (relation, key) => {
|
2018-02-22 11:33:01 +01:00
|
|
|
|
|
|
|
const Select = ['oneWay', 'oneToOne', 'manyToOne'].includes(relation.nature) && relation.dominant ? SelectOne : SelectMany;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Select
|
|
|
|
currentModelName={props.currentModelName}
|
|
|
|
key={key}
|
|
|
|
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-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,
|
|
|
|
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;
|