/** * * Controller * */ import React from 'react'; import PropTypes from 'prop-types'; import { get, map } from 'lodash'; import { FormattedMessage } from 'react-intl'; import pluginId from '../../pluginId'; import InputCheckbox from '../InputCheckboxPlugin'; import { Header, Label, Separator, Wrapper } from './Components'; class Controller extends React.Component { state = { inputSelected: '' }; setNewInputSelected = name => { this.setState({ inputSelected: name }); }; handleChange = () => { this.context.selectAllActions( `${this.props.inputNamePath}.controllers.${this.props.name}`, !this.areAllActionsSelected() ); }; hasSomeActionsSelected = () => { const { actions } = this.props; return Object.keys(actions).some( action => actions[action].enabled === true ); }; areAllActionsSelected = () => { const { actions } = this.props; return Object.keys(actions).every( action => actions[action].enabled === true ); }; render() { const labelId = this.areAllActionsSelected() ? 'unselectAll' : 'selectAll'; return (
{this.props.name}
{map(Object.keys(this.props.actions).sort(), actionKey => ( ))}
); } } Controller.contextTypes = { selectAllActions: PropTypes.func.isRequired, }; Controller.defaultProps = { actions: {}, inputNamePath: 'permissions.application', name: '', }; Controller.propTypes = { actions: PropTypes.object, inputNamePath: PropTypes.string, isOpen: PropTypes.bool.isRequired, name: PropTypes.string, }; export default Controller;