2017-12-02 16:10:18 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* PluginCard
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import cn from 'classnames';
|
2017-12-12 17:49:06 +01:00
|
|
|
import { isEmpty, replace } from 'lodash';
|
2017-12-02 18:46:22 +01:00
|
|
|
import { FormattedMessage } from 'react-intl';
|
|
|
|
|
|
|
|
import Button from 'components/Button';
|
2017-12-12 14:30:24 +01:00
|
|
|
import InstallPluginPopup from 'components/InstallPluginPopup';
|
2017-12-16 16:51:23 +01:00
|
|
|
|
2017-12-02 16:10:18 +01:00
|
|
|
import styles from './styles.scss';
|
2019-01-24 18:24:24 +01:00
|
|
|
|
|
|
|
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-01-24 18:24:24 +01:00
|
|
|
state = {
|
|
|
|
isOpen: false,
|
|
|
|
boostrapCol: 'col-lg-4',
|
|
|
|
};
|
2017-12-02 18:46:22 +01:00
|
|
|
|
|
|
|
componentDidMount() {
|
2019-01-24 18:24:24 +01:00
|
|
|
// this.shouldOpenModal(this.props);
|
|
|
|
|
|
|
|
// Listen window resize.
|
2017-12-11 19:04:27 +01:00
|
|
|
window.addEventListener('resize', this.setBoostrapCol);
|
2019-01-24 18:24:24 +01:00
|
|
|
|
2017-12-11 19:04:27 +01:00
|
|
|
this.setBoostrapCol();
|
2017-12-02 18:46:22 +01:00
|
|
|
}
|
|
|
|
|
2019-01-24 18:24:24 +01:00
|
|
|
componentWillReceiveProps() {
|
|
|
|
// if (nextProps.history.location.hash !== this.props.history.location.hash) {
|
|
|
|
// this.shouldOpenModal(nextProps);
|
|
|
|
// }
|
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-01-24 18:24:24 +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();
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
handleClickSettings = (e) => {
|
|
|
|
const settingsPath = this.props.plugin.id === 'content-manager' ? '/plugins/content-manager/ctm-configurations' : `/plugins/${this.props.plugin.id}/configurations/${this.props.currentEnvironment}`;
|
|
|
|
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
|
|
|
|
this.props.history.push(settingsPath);
|
2017-12-12 14:30:24 +01:00
|
|
|
}
|
|
|
|
|
2018-01-15 16:43:08 +01:00
|
|
|
handleDownloadPlugin = (e) => {
|
2018-01-16 18:06:15 +01:00
|
|
|
if (!this.props.isAlreadyInstalled && this.props.plugin.id !== 'support-us') {
|
|
|
|
this.props.downloadPlugin(e);
|
|
|
|
} else if (this.props.plugin.id === 'support-us') {
|
|
|
|
this.aTag.click();
|
|
|
|
} else {
|
|
|
|
this.props.history.push('/list-plugins');
|
|
|
|
}
|
2018-01-04 19:04:22 +01:00
|
|
|
}
|
|
|
|
|
2017-12-02 18:46:22 +01:00
|
|
|
shouldOpenModal = (props) => {
|
|
|
|
this.setState({ isOpen: !isEmpty(props.history.location.hash) });
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2019-01-24 18:24:24 +01:00
|
|
|
const buttonClass = !this.props.isAlreadyInstalled ? styles.primary : styles.secondary;
|
|
|
|
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.
|
|
|
|
const settingsComponent = (PLUGINS_WITH_CONFIG.includes(this.props.plugin.id) &&
|
|
|
|
<div className={styles.settings} onClick={this.handleClickSettings}>
|
|
|
|
<i className='fa fa-cog' />
|
|
|
|
<FormattedMessage id='app.components.PluginCard.settings' />
|
2017-12-16 16:51:23 +01:00
|
|
|
</div>
|
|
|
|
);
|
2017-12-02 18:46:22 +01:00
|
|
|
|
2018-01-10 16:55:12 +01:00
|
|
|
const descriptions = {
|
|
|
|
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-01-24 18:24:24 +01:00
|
|
|
<div className={cn(this.state.boostrapCol, styles.pluginCard)}>
|
2017-12-02 18:46:22 +01:00
|
|
|
<div className={styles.wrapper}>
|
|
|
|
<div className={styles.cardTitle}>
|
2019-01-24 18:24:24 +01:00
|
|
|
<div className={styles.frame}>
|
|
|
|
<span className={styles.helper} />
|
|
|
|
<img src={this.props.plugin.logo} alt="icon" />
|
|
|
|
</div>
|
|
|
|
<div>{this.props.plugin.name} <i className='fa fa-external-link' onClick={() => window.open(`https://github.com/strapi/strapi/tree/master/packages/strapi-plugin-${this.props.plugin.id}`, '_blank')} /></div>
|
2017-12-02 18:46:22 +01:00
|
|
|
</div>
|
|
|
|
<div className={styles.cardDescription}>
|
2019-01-24 18:24:24 +01:00
|
|
|
{descriptions.long}
|
2017-12-11 20:19:22 +01:00
|
|
|
<FormattedMessage id="app.components.PluginCard.more-details" />
|
2017-12-02 18:46:22 +01:00
|
|
|
</div>
|
2018-01-04 19:04:22 +01:00
|
|
|
<div className={styles.cardFooter} onClick={e => e.stopPropagation()}>
|
2019-01-24 18:24:24 +01:00
|
|
|
<div className={styles.cardFooterButton}>
|
2017-12-02 18:46:22 +01:00
|
|
|
<Button
|
|
|
|
className={cn(buttonClass, styles.button)}
|
|
|
|
label={buttonLabel}
|
2018-01-05 16:19:53 +01:00
|
|
|
onClick={this.handleDownloadPlugin}
|
2017-12-02 18:46:22 +01:00
|
|
|
/>
|
2017-12-12 18:30:09 +01:00
|
|
|
<a
|
2018-01-16 18:06:15 +01:00
|
|
|
href="https://strapi.io/shop"
|
2017-12-12 18:30:09 +01:00
|
|
|
style={{ display: 'none' }}
|
|
|
|
ref={(a) => { this.aTag = a; }}
|
2018-01-16 18:06:15 +01:00
|
|
|
target="_blank"
|
2017-12-12 18:30:09 +01:00
|
|
|
>
|
|
|
|
|
|
|
|
</a>
|
2017-12-02 18:46:22 +01:00
|
|
|
</div>
|
2019-01-24 18:24:24 +01:00
|
|
|
{this.props.isAlreadyInstalled ?
|
|
|
|
(
|
|
|
|
settingsComponent
|
|
|
|
)
|
|
|
|
:
|
|
|
|
(
|
|
|
|
<div className={styles.compatible}>
|
|
|
|
<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>
|
2017-12-12 14:30:24 +01:00
|
|
|
<InstallPluginPopup
|
|
|
|
history={this.props.history}
|
2017-12-12 19:53:04 +01:00
|
|
|
isAlreadyInstalled={this.props.isAlreadyInstalled}
|
2017-12-12 14:30:24 +01:00
|
|
|
isOpen={!isEmpty(this.props.history.location.hash) && replace(this.props.history.location.hash.split('::')[0], '#', '') === this.props.plugin.id}
|
|
|
|
plugin={this.props.plugin}
|
|
|
|
/>
|
2017-12-02 16:10:18 +01:00
|
|
|
</div>
|
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 = {
|
2019-01-24 18:24:24 +01:00
|
|
|
currentEnvironment: PropTypes.string.isRequired,
|
2018-01-04 19:04:22 +01:00
|
|
|
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;
|