2017-12-02 16:10:18 +01:00
|
|
|
/**
|
2019-04-16 11:53:29 +02:00
|
|
|
*
|
|
|
|
* PluginCard
|
|
|
|
*
|
|
|
|
*/
|
2017-12-02 16:10:18 +01:00
|
|
|
|
|
|
|
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';
|
|
|
|
|
2019-04-16 11:53:29 +02:00
|
|
|
import { Button } from 'strapi-helper-plugin';
|
2019-02-22 10:08:59 +01:00
|
|
|
import InstallPluginPopup from '../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-04-16 11:53:29 +02:00
|
|
|
state = {
|
2019-01-24 18:24:24 +01:00
|
|
|
boostrapCol: 'col-lg-4',
|
|
|
|
};
|
2017-12-02 18:46:22 +01:00
|
|
|
|
|
|
|
componentDidMount() {
|
2019-01-24 18:24:24 +01:00
|
|
|
// 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
|
|
|
|
2019-01-30 13:40:12 +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-01-24 18:24:24 +01:00
|
|
|
|
2019-04-16 11:53:29 +02:00
|
|
|
handleClickSettings = e => {
|
|
|
|
const settingsPath =
|
|
|
|
this.props.plugin.id === 'content-manager'
|
|
|
|
? '/plugins/content-manager/ctm-configurations'
|
|
|
|
: `/plugins/${this.props.plugin.id}/configurations/${
|
|
|
|
this.props.currentEnvironment
|
|
|
|
}`;
|
2019-01-24 18:24:24 +01:00
|
|
|
|
|
|
|
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 => {
|
|
|
|
if (
|
|
|
|
!this.props.isAlreadyInstalled &&
|
|
|
|
this.props.plugin.id !== 'support-us'
|
|
|
|
) {
|
2018-01-16 18:06:15 +01:00
|
|
|
this.props.downloadPlugin(e);
|
|
|
|
} else if (this.props.plugin.id === 'support-us') {
|
|
|
|
this.aTag.click();
|
|
|
|
} else {
|
|
|
|
this.props.history.push('/list-plugins');
|
|
|
|
}
|
2019-04-16 11:53:29 +02:00
|
|
|
};
|
2018-01-04 19:04:22 +01:00
|
|
|
|
2017-12-02 18:46:22 +01:00
|
|
|
render() {
|
2019-04-16 11:53:29 +02: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';
|
2019-01-24 18:24:24 +01:00
|
|
|
|
|
|
|
// 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-01-24 18:24:24 +01:00
|
|
|
<div className={styles.settings} onClick={this.handleClickSettings}>
|
2019-04-16 11:53:29 +02:00
|
|
|
<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 = {
|
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
|
|
|
|
),
|
2018-01-10 16:55:12 +01:00
|
|
|
};
|
|
|
|
|
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>
|
2019-04-16 11:53:29 +02:00
|
|
|
<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}
|
2019-01-30 13:40:12 +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' }}
|
2019-04-16 11:53:29 +02:00
|
|
|
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-04-16 11:53:29 +02: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}
|
2019-04-16 11:53:29 +02:00
|
|
|
isOpen={
|
|
|
|
!isEmpty(this.props.history.location.hash) &&
|
|
|
|
replace(
|
|
|
|
this.props.history.location.hash.split('::')[0],
|
|
|
|
'#',
|
|
|
|
'',
|
|
|
|
) === this.props.plugin.id
|
|
|
|
}
|
2017-12-12 14:30:24 +01:00
|
|
|
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;
|