67 lines
1.7 KiB
JavaScript
Raw Normal View History

/**
*
* EditRelations
*
*/
import React from 'react';
import { FormattedMessage } from 'react-intl';
2018-02-22 10:35:19 +01:00
import PropTypes from 'prop-types';
import { get, map } from 'lodash';
2018-02-22 10:35:19 +01:00
// Components.
import SelectOne from 'components/SelectOne';
import SelectMany from 'components/SelectMany';
import styles from './styles.scss';
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) {
return (
<div className={styles.editFormRelations}>
<FormattedMessage id="content-manager.EditRelations.title">
{(message) => <h3>{message}</h3>}
</FormattedMessage>
{map(filterRelationsUpload(props.schema.relations), (relation, key) => {
if (relation.nature.toLowerCase().includes('morph') && relation[key]) return '';
2018-02-22 11:33:01 +01:00
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}
key={key}
record={props.record}
relation={relation}
schema={props.schema}
setRecordAttribute={props.changeData}
location={props.location}
/>
);
2018-02-22 10:35:19 +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,
};
export default EditRelations;