87 lines
2.3 KiB
JavaScript
Raw Normal View History

/**
*
* Plugin
*
*/
import React from 'react';
import PropTypes from 'prop-types';
import { Collapse } from 'reactstrap';
2017-11-16 17:59:41 +01:00
import { capitalize, get, map } from 'lodash';
import { FormattedMessage } from 'react-intl';
import Controller from 'components/Controller';
import styles from './styles.scss';
class Plugin extends React.Component { // eslint-disable-line react/prefer-stateless-function
state = { collapse: false };
2017-11-16 15:13:46 +01:00
componentWillReceiveProps(nextProps) {
if (nextProps.pluginSelected !== this.props.pluginSelected && nextProps.pluginSelected !== this.props.name) {
this.setState({ collapse: false });
}
}
handleClick = () => {
this.props.changePluginSelected(this.props.name);
this.setState({ collapse: !this.state.collapse });
}
render() {
return (
<div className={styles.plugin}>
<div className={styles.banner} onClick={this.handleClick}>
<div>
<span>{this.props.name}</span>
&nbsp;&nbsp;
2017-11-16 17:59:41 +01:00
<span>
{this.props.name === 'application' ? (
<FormattedMessage
id="users-permissions.Plugin.permissions.application.description"
/>
) : (
<FormattedMessage
id="users-permissions.Plugin.permissions.plugins.description"
values={{ name: capitalize(this.props.name) }}
/>
)}
</span>
</div>
<div className={this.state.collapse ? styles.chevronUp : styles.chevronDown}>
</div>
</div>
<Collapse isOpen={this.state.collapse}>
{map(get(this.props.plugin, 'controllers'), (controllerActions, key) => (
<Controller
inputNamePath={`permissions.${this.props.name}`}
key={key}
name={key}
2017-11-16 17:59:41 +01:00
actions={controllerActions}
/>
))}
</Collapse>
</div>
);
}
}
Plugin.defaultProps = {
name: '',
plugin: {
description: 'users-permissions.Plugin.permissions.description.empty',
controllers: {},
},
};
Plugin.propTypes = {
2017-11-16 15:13:46 +01:00
changePluginSelected: PropTypes.func.isRequired,
name: PropTypes.string,
plugin: PropTypes.shape({
description: PropTypes.string,
}),
2017-11-16 15:13:46 +01:00
pluginSelected: PropTypes.string.isRequired,
};
export default Plugin;