/** * * EditFormRelations * */ import React from 'react'; import PropTypes from 'prop-types'; import { get, map, size } from 'lodash'; // Components. import SelectOne from 'components/SelectOne'; import SelectMany from 'components/SelectMany'; // Utils. import getQueryParameters from 'utils/getQueryParameters'; // Style. import styles from './styles.scss'; class EditFormRelations extends React.Component { // eslint-disable-line react/prefer-stateless-function componentDidMount() { if (size(get(this.props.schema, [this.props.currentModelName, 'relations'])) === 0 && !this.props.isNull) { this.props.toggleNull(); } } render() { const source = getQueryParameters(this.props.location.search, 'source'); const currentSchema = get(this.props.schema, [this.props.currentModelName]) || get(this.props.schema, ['plugins', source, this.props.currentModelName]); const relations = map(currentSchema.relations, (relation, i) => { switch (relation.nature) { case 'oneToOne': case 'manyToOne': if (relation.dominant) { return ( ); } break; case 'oneToMany': case 'manyToMany': return ( ); default: break; } }); if (!relations.length) { return (null); } return (

Relational data

{relations}
); } } EditFormRelations.propTypes = { currentModelName: PropTypes.oneOfType([ PropTypes.bool, PropTypes.string, ]).isRequired, isNull: PropTypes.bool.isRequired, location: PropTypes.shape({ search: PropTypes.string, }).isRequired, record: PropTypes.oneOfType([ PropTypes.object, PropTypes.bool, ]).isRequired, schema: PropTypes.oneOfType([ PropTypes.object, PropTypes.bool, ]).isRequired, setRecordAttribute: PropTypes.func.isRequired, toggleNull: PropTypes.func.isRequired, }; export default EditFormRelations;