/** * * 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 { useEditPageContext } from '../../contexts/EditPage'; import InputCheckbox from '../InputCheckboxPlugin'; import { Header, Label, Separator, Wrapper } from './Components'; function Controller({ actions, inputNamePath, isOpen, name, inputSelected, setInputSelected }) { const { selectAllActions } = useEditPageContext(); const areAllActionsSelected = () => { return Object.keys(actions).every(action => actions[action].enabled === true); }; const handleChange = () => { selectAllActions(`${inputNamePath}.controllers.${name}`, !areAllActionsSelected()); }; const hasSomeActionsSelected = () => { return Object.keys(actions).some(action => actions[action].enabled === true); }; const setNewInputSelected = name => { setInputSelected(name); }; const labelId = areAllActionsSelected() ? 'unselectAll' : 'selectAll'; return (
{name}
{map(Object.keys(actions).sort(), actionKey => ( ))}
); } 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;