247 lines
7.0 KiB
JavaScript
Raw Normal View History

2017-12-02 16:10:18 +01:00
/**
2019-04-16 11:53:29 +02:00
*
* PluginCard
*
*/
2019-07-02 08:37:41 +02:00
/* eslint-disable */
2017-12-02 16:10:18 +01:00
import React from 'react';
import PropTypes from 'prop-types';
2017-12-02 18:46:22 +01:00
import { FormattedMessage } from 'react-intl';
import { Button, PopUpWarning } from 'strapi-helper-plugin';
2019-12-06 11:09:48 +01:00
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
2019-09-17 17:19:10 +02:00
import Wrapper from './Wrapper';
const PLUGINS_WITH_CONFIG = ['content-manager', 'email', 'upload'];
2017-12-02 16:10:18 +01:00
2018-05-02 11:01:27 +02:00
/* eslint-disable react/no-unused-state */
2017-12-02 18:46:22 +01:00
class PluginCard extends React.Component {
2019-04-16 11:53:29 +02:00
state = {
boostrapCol: 'col-lg-4',
showModalAutoReload: false,
showModalEnv: false,
};
2017-12-02 18:46:22 +01:00
componentDidMount() {
// Listen window resize.
2017-12-11 19:04:27 +01:00
window.addEventListener('resize', this.setBoostrapCol);
this.setBoostrapCol();
2017-12-02 18:46:22 +01:00
}
2017-12-11 19:04:27 +01:00
componentWillUnmount() {
2017-12-12 14:30:24 +01:00
window.removeEventListener('resize', this.setBoostrapCol);
2017-12-11 19:04:27 +01:00
}
setBoostrapCol = () => {
let boostrapCol = 'col-lg-4';
if (window.innerWidth > 1680) {
boostrapCol = 'col-lg-3';
}
if (window.innerWidth > 2300) {
boostrapCol = 'col-lg-2';
}
this.setState({ boostrapCol });
2019-04-16 11:53:29 +02:00
};
2017-12-11 19:04:27 +01:00
handleClick = () => {
if (this.props.plugin.id !== 'support-us') {
this.props.history.push({
pathname: this.props.history.location.pathname,
hash: `${this.props.plugin.id}::description`,
});
} else {
this.aTag.click();
}
2019-04-16 11:53:29 +02:00
};
2019-04-16 11:53:29 +02:00
handleClickSettings = e => {
const settingsPath =
this.props.plugin.id === 'content-manager'
? '/plugins/content-manager/ctm-configurations/models'
: `/plugins/${this.props.plugin.id}/configurations/${this.props.currentEnvironment}`;
e.preventDefault();
e.stopPropagation();
this.props.history.push(settingsPath);
2019-04-16 11:53:29 +02:00
};
2017-12-12 14:30:24 +01:00
2019-04-16 11:53:29 +02:00
handleDownloadPlugin = e => {
const {
autoReload,
currentEnvironment,
downloadPlugin,
history: { push },
isAlreadyInstalled,
plugin: { id },
} = this.props;
if (!autoReload) {
this.setState({ showModalAutoReload: true });
} else if (currentEnvironment !== 'development') {
this.setState({ showModalEnv: true });
} else if (!isAlreadyInstalled) {
downloadPlugin(e);
} else {
push('/list-plugins');
}
2019-04-16 11:53:29 +02:00
};
2017-12-02 18:46:22 +01:00
render() {
2019-04-16 11:53:29 +02:00
const buttonClass = !this.props.isAlreadyInstalled
2019-09-17 17:19:10 +02:00
? 'primary'
: 'secondary';
2019-04-16 11:53:29 +02:00
const buttonLabel = this.props.isAlreadyInstalled
? 'app.components.PluginCard.Button.label.install'
: 'app.components.PluginCard.Button.label.download';
// Display settings link for a selection of plugins.
2019-04-16 11:53:29 +02:00
const settingsComponent = PLUGINS_WITH_CONFIG.includes(
this.props.plugin.id
2019-04-16 11:53:29 +02:00
) && (
2019-09-17 17:19:10 +02:00
<div className="settings" onClick={this.handleClickSettings}>
2019-12-06 11:09:48 +01:00
{/* <i className="fa fa-cog" /> */}
<FontAwesomeIcon icon="cog" />
2019-04-16 11:53:29 +02:00
<FormattedMessage id="app.components.PluginCard.settings" />
2017-12-16 16:51:23 +01:00
</div>
);
2017-12-02 18:46:22 +01:00
const descriptions = {
2019-04-16 11:53:29 +02:00
short:
this.props.plugin.id === 'support-us' ? (
<FormattedMessage id={this.props.plugin.description.short} />
) : (
this.props.plugin.description.short
),
long:
this.props.plugin.id === 'support-us' ? (
<FormattedMessage
id={
this.props.plugin.description.long ||
this.props.plugin.description.short
}
/>
) : (
this.props.plugin.description.long ||
this.props.plugin.description.short
),
};
2017-12-02 18:46:22 +01:00
return (
2019-09-17 17:19:10 +02:00
<Wrapper className={this.state.boostrapCol}>
<div className="wrapper">
<div className="cardTitle">
<div className="frame">
<span className="helper" />
<img src={this.props.plugin.logo} alt="icon" />
</div>
2019-04-16 11:53:29 +02:00
<div>
{this.props.plugin.name}{' '}
<i
2019-11-19 16:17:15 +01:00
className="fa fa-external-link-alt"
2019-04-16 11:53:29 +02:00
onClick={() =>
window.open(
`https://github.com/strapi/strapi/tree/master/packages/strapi-plugin-${this.props.plugin.id}`,
'_blank'
2019-04-16 11:53:29 +02:00
)
}
/>
</div>
2017-12-02 18:46:22 +01:00
</div>
2019-09-17 17:19:10 +02:00
<div className="cardDescription">
{descriptions.long}
{/* &nbsp;<FormattedMessage id="app.components.PluginCard.more-details" /> */}
2017-12-02 18:46:22 +01:00
</div>
2019-09-17 17:19:10 +02:00
<div className="cardFooter" onClick={e => e.stopPropagation()}>
<div className="cardFooterButton">
2017-12-02 18:46:22 +01:00
<Button
2019-09-17 17:19:10 +02:00
className={`${buttonClass} button`}
2017-12-02 18:46:22 +01:00
label={buttonLabel}
onClick={this.handleDownloadPlugin}
2017-12-02 18:46:22 +01:00
/>
2017-12-12 18:30:09 +01:00
<a
href="https://strapi.io/shop"
2017-12-12 18:30:09 +01:00
style={{ display: 'none' }}
2019-04-16 11:53:29 +02:00
ref={a => {
this.aTag = a;
}}
target="_blank"
2017-12-12 18:30:09 +01:00
>
&nbsp;
</a>
2017-12-02 18:46:22 +01:00
</div>
2019-04-16 11:53:29 +02:00
{this.props.isAlreadyInstalled ? (
settingsComponent
) : (
2019-09-17 17:19:10 +02:00
<div className="compatible">
2019-04-16 11:53:29 +02:00
<i
className={`fa fa-${
this.props.plugin.isCompatible ? 'check' : 'times'
}`}
/>
<FormattedMessage
id={`app.components.PluginCard.compatible${
this.props.plugin.id === 'support-us' ? 'Community' : ''
}`}
/>
</div>
)}
2017-12-02 18:46:22 +01:00
</div>
2017-12-02 16:10:18 +01:00
</div>
2019-09-17 15:23:29 +02:00
<PopUpWarning
content={{
message:
'app.components.PluginCard.PopUpWarning.install.impossible.autoReload.needed',
title:
'app.components.PluginCard.PopUpWarning.install.impossible.title',
confirm:
'app.components.PluginCard.PopUpWarning.install.impossible.confirm',
}}
isOpen={this.state.showModalAutoReload}
onlyConfirmButton
onConfirm={() => this.setState({ showModalAutoReload: false })}
popUpWarningType="warning"
/>
<PopUpWarning
content={{
message:
'app.components.PluginCard.PopUpWarning.install.impossible.environment',
title:
'app.components.PluginCard.PopUpWarning.install.impossible.title',
confirm:
'app.components.PluginCard.PopUpWarning.install.impossible.confirm',
}}
isOpen={this.state.showModalEnv}
onlyConfirmButton
onConfirm={() => this.setState({ showModalEnv: false })}
popUpWarningType="warning"
/>
2019-09-17 17:19:10 +02:00
</Wrapper>
2017-12-02 18:46:22 +01:00
);
}
2017-12-02 16:10:18 +01:00
}
PluginCard.defaultProps = {
isAlreadyInstalled: false,
plugin: {
description: '',
id: '',
name: '',
price: 0,
ratings: 5,
},
};
PluginCard.propTypes = {
currentEnvironment: PropTypes.string.isRequired,
downloadPlugin: PropTypes.func.isRequired,
2017-12-02 18:46:22 +01:00
history: PropTypes.object.isRequired,
2017-12-02 16:10:18 +01:00
isAlreadyInstalled: PropTypes.bool,
plugin: PropTypes.object,
};
export default PluginCard;