/** * * Policies * */ import React from 'react'; import cn from 'classnames'; import PropTypes from 'prop-types'; import { FormattedMessage } from 'react-intl'; import { get, isEmpty, map, takeRight, toLower, without } from 'lodash'; import BoundRoute from 'components/BoundRoute'; import Input from 'components/InputsIndex'; import styles from './styles.scss'; class Policies extends React.Component { // eslint-disable-line react/prefer-stateless-function handleChange = (e) => this.context.onChange(e); render() { const baseTitle = 'users-permissions.Policies.header'; const title = this.props.shouldDisplayPoliciesHint ? 'hint' : 'title'; const value = get(this.props.values, this.props.inputSelectName); const path = without(this.props.inputSelectName.split('.'), 'permissions', 'controllers', 'policy'); const controllerRoutes = get(this.props.routes, without(this.props.inputSelectName.split('.'), 'permissions', 'controllers', 'policy')[0]); const routes = isEmpty(controllerRoutes) ? [] : controllerRoutes.filter(o => toLower(o.handler) === toLower(takeRight(path, 2).join('.'))); return (
{!this.props.shouldDisplayPoliciesHint ? ( ) : ''}
{!this.props.shouldDisplayPoliciesHint ? ( map(routes, (route, key) => ) ) : ''}
); } } Policies.contextTypes = { onChange: PropTypes.func.isRequired, }; Policies.defaultProps = { routes: {}, }; Policies.propTypes = { inputSelectName: PropTypes.string.isRequired, routes: PropTypes.object, selectOptions: PropTypes.array.isRequired, shouldDisplayPoliciesHint: PropTypes.bool.isRequired, values: PropTypes.object.isRequired, }; export default Policies;