import React from 'react'; import PropTypes from 'prop-types'; import { Flexbox, RetinaImg, Switch } from 'mailspring-component-kit'; import PluginsActions from './plugins-actions'; class Package extends React.Component { static displayName = 'Package'; static propTypes = { package: PropTypes.object.isRequired, showVersions: PropTypes.bool, }; _onDisablePackage = () => { PluginsActions.disablePackage(this.props.package); }; _onEnablePackage = () => { PluginsActions.enablePackage(this.props.package); }; _onUninstallPackage = () => { PluginsActions.uninstallPackage(this.props.package); }; _onUpdatePackage = () => { PluginsActions.updatePackage(this.props.package); }; _onInstallPackage = () => { PluginsActions.installPackage(this.props.package); }; _onShowPackage = () => { PluginsActions.showPackage(this.props.package); }; render() { const actions = []; const extras = []; let icon = ; let uninstallButton = null; if (this.props.package.icon) { icon = ( ); } else if (this.props.package.theme) { icon = ; } if (this.props.package.installed) { if ( ['user', 'dev', 'example'].indexOf(this.props.package.category) !== -1 && !this.props.package.theme ) { if (this.props.package.enabled) { actions.push( Disable ); } else { actions.push( Enable ); } } if (this.props.package.category === 'user') { uninstallButton = (
Uninstall
); } if (this.props.package.category === 'dev') { actions.push(
Show...
); } } else if (this.props.package.installing) { actions.push(
Installing...
); } else { actions.push(
Install
); } const { name, description, title, version } = this.props.package; if (this.props.package.newerVersionAvailable) { extras.push(
A newer version is available: {this.props.package.newerVersion}
Update
); } const versionLabel = this.props.showVersions ? `v${version}` : null; return (
{icon}
{title || name} {versionLabel}
{uninstallButton}
{description}
{actions}
{extras}
); } } export default Package;