2017-11-15 17:35:32 +01:00
|
|
|
/**
|
2019-08-13 11:31:10 +02:00
|
|
|
*
|
|
|
|
* Plugin
|
|
|
|
*
|
|
|
|
*/
|
2017-11-15 17:35:32 +01:00
|
|
|
|
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { Collapse } from 'reactstrap';
|
2019-12-06 11:09:48 +01:00
|
|
|
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
2017-12-04 15:03:53 +01:00
|
|
|
import { capitalize, get, isEmpty, map } from 'lodash';
|
2017-11-15 17:35:32 +01:00
|
|
|
import { FormattedMessage } from 'react-intl';
|
2019-10-03 12:58:20 +02:00
|
|
|
import { EditPageContext } from '../../contexts/EditPage';
|
2019-02-22 11:16:42 +01:00
|
|
|
import Controller from '../Controller';
|
2017-11-15 17:35:32 +01:00
|
|
|
|
2020-04-26 18:13:20 +02:00
|
|
|
import { Banner, Chevron, ControllerWrapper, Description, Icon, Name, Wrapper } from './Components';
|
2017-11-15 17:35:32 +01:00
|
|
|
|
2019-08-13 11:31:10 +02:00
|
|
|
class Plugin extends React.Component {
|
|
|
|
// eslint-disable-line react/prefer-stateless-function
|
2020-08-03 16:49:40 +02:00
|
|
|
state = { collapse: false };
|
2017-11-15 17:35:32 +01:00
|
|
|
|
2019-10-03 12:58:20 +02:00
|
|
|
static contextType = EditPageContext;
|
|
|
|
|
2017-12-13 13:43:36 +01:00
|
|
|
componentDidMount() {
|
|
|
|
// Open the application's permissions section if there are APIs
|
2020-04-26 18:13:20 +02:00
|
|
|
if (this.props.name === 'application' && !isEmpty(get(this.props.plugin, 'controllers'))) {
|
2017-12-13 13:43:36 +01:00
|
|
|
this.props.changePluginSelected('application');
|
|
|
|
this.setState({ collapse: !this.state.collapse });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-13 11:31:10 +02:00
|
|
|
UNSAFE_componentWillReceiveProps(nextProps) {
|
|
|
|
if (
|
|
|
|
nextProps.pluginSelected !== this.props.pluginSelected &&
|
|
|
|
nextProps.pluginSelected !== this.props.name
|
|
|
|
) {
|
2017-11-30 12:10:23 +01:00
|
|
|
this.context.resetShouldDisplayPoliciesHint();
|
2017-11-16 15:13:46 +01:00
|
|
|
this.setState({ collapse: false });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
handleClick = () => {
|
|
|
|
this.props.changePluginSelected(this.props.name);
|
2017-12-04 15:03:53 +01:00
|
|
|
|
|
|
|
if (!isEmpty(get(this.props.plugin, 'controllers'))) {
|
|
|
|
this.setState({ collapse: !this.state.collapse });
|
|
|
|
}
|
2017-11-30 15:01:19 +01:00
|
|
|
|
|
|
|
if (this.state.collapse) {
|
|
|
|
this.context.resetShouldDisplayPoliciesHint();
|
|
|
|
}
|
2019-08-13 11:31:10 +02:00
|
|
|
};
|
2017-11-15 17:35:32 +01:00
|
|
|
|
|
|
|
render() {
|
2020-02-11 17:29:14 +01:00
|
|
|
const { appPlugins } = this.context;
|
|
|
|
const { plugin } = this.props;
|
2017-11-17 12:14:12 +01:00
|
|
|
const divStyle = this.state.collapse ? { marginBottom: '.4rem' } : {};
|
2020-02-11 17:29:14 +01:00
|
|
|
const pluginId = get(plugin, ['information', 'id'], null);
|
|
|
|
const icon = get(appPlugins, [pluginId, 'pluginLogo'], null);
|
2017-12-14 17:06:26 +01:00
|
|
|
const emptyApplication = !isEmpty(get(this.props.plugin, 'controllers'));
|
2017-11-17 12:14:12 +01:00
|
|
|
|
2018-01-26 14:06:44 +01:00
|
|
|
if (!emptyApplication) {
|
|
|
|
return <div />;
|
|
|
|
}
|
|
|
|
|
2017-11-15 17:35:32 +01:00
|
|
|
return (
|
2019-09-16 19:18:35 +02:00
|
|
|
<Wrapper style={divStyle}>
|
|
|
|
<Banner onClick={this.handleClick}>
|
2017-11-15 17:35:32 +01:00
|
|
|
<div>
|
2018-06-14 15:30:54 +02:00
|
|
|
{this.props.name !== 'application' && (
|
2019-09-16 19:18:35 +02:00
|
|
|
<Icon>{icon && <img src={icon} alt="icon" />}</Icon>
|
2018-06-14 15:30:54 +02:00
|
|
|
)}
|
2019-09-16 19:18:35 +02:00
|
|
|
<Name>{this.props.name}</Name>
|
2017-11-15 17:35:32 +01:00
|
|
|
—
|
2019-09-16 19:18:35 +02:00
|
|
|
<Description>
|
2017-11-16 17:59:41 +01:00
|
|
|
{this.props.name === 'application' ? (
|
2019-08-13 11:31:10 +02:00
|
|
|
<FormattedMessage id="users-permissions.Plugin.permissions.application.description" />
|
2017-11-16 17:59:41 +01:00
|
|
|
) : (
|
|
|
|
<FormattedMessage
|
|
|
|
id="users-permissions.Plugin.permissions.plugins.description"
|
|
|
|
values={{ name: capitalize(this.props.name) }}
|
|
|
|
/>
|
|
|
|
)}
|
2019-09-16 19:18:35 +02:00
|
|
|
</Description>
|
2019-10-08 10:21:27 +02:00
|
|
|
{emptyApplication && (
|
|
|
|
<Chevron>
|
|
|
|
{this.state.collapse ? (
|
2019-12-06 11:09:48 +01:00
|
|
|
<FontAwesomeIcon icon="chevron-up" />
|
2019-10-08 10:21:27 +02:00
|
|
|
) : (
|
2019-12-06 11:09:48 +01:00
|
|
|
<FontAwesomeIcon icon="chevron-down" />
|
2019-10-08 10:21:27 +02:00
|
|
|
)}
|
|
|
|
</Chevron>
|
|
|
|
)}
|
2017-11-15 17:35:32 +01:00
|
|
|
</div>
|
2019-09-16 19:18:35 +02:00
|
|
|
</Banner>
|
2017-11-15 17:35:32 +01:00
|
|
|
<Collapse isOpen={this.state.collapse}>
|
2017-11-17 12:14:12 +01:00
|
|
|
<div />
|
2019-09-16 19:18:35 +02:00
|
|
|
<ControllerWrapper>
|
2020-04-26 18:13:20 +02:00
|
|
|
{map(get(this.props.plugin, 'controllers'), (controllerActions, key) => (
|
|
|
|
<Controller
|
|
|
|
inputNamePath={`permissions.${this.props.name}`}
|
|
|
|
isOpen={this.state.collapse}
|
|
|
|
key={key}
|
|
|
|
name={key}
|
|
|
|
actions={controllerActions}
|
|
|
|
resetInputBackground={this.state.resetInputBackground}
|
|
|
|
/>
|
|
|
|
))}
|
2019-09-16 19:18:35 +02:00
|
|
|
</ControllerWrapper>
|
2017-11-15 17:35:32 +01:00
|
|
|
</Collapse>
|
2019-09-16 19:18:35 +02:00
|
|
|
</Wrapper>
|
2017-11-15 17:35:32 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Plugin.defaultProps = {
|
|
|
|
name: '',
|
|
|
|
plugin: {
|
|
|
|
description: 'users-permissions.Plugin.permissions.description.empty',
|
|
|
|
controllers: {},
|
2018-01-05 16:19:53 +01:00
|
|
|
information: {},
|
2017-11-15 17:35:32 +01:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
Plugin.propTypes = {
|
2017-11-16 15:13:46 +01:00
|
|
|
changePluginSelected: PropTypes.func.isRequired,
|
2017-11-15 17:35:32 +01:00
|
|
|
name: PropTypes.string,
|
|
|
|
plugin: PropTypes.shape({
|
|
|
|
description: PropTypes.string,
|
2018-01-05 16:19:53 +01:00
|
|
|
information: PropTypes.shape({
|
2018-01-12 17:50:18 +01:00
|
|
|
logo: PropTypes.string,
|
2018-01-11 17:13:09 +01:00
|
|
|
}),
|
2017-11-15 17:35:32 +01:00
|
|
|
}),
|
2017-11-16 15:13:46 +01:00
|
|
|
pluginSelected: PropTypes.string.isRequired,
|
2017-11-15 17:35:32 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
export default Plugin;
|