//@flow import React from "react"; import injectSheet from "react-jss"; import type { Plugin } from "@scm-manager/ui-types"; import { CardColumn } from "@scm-manager/ui-components"; import PluginAvatar from "./PluginAvatar"; import classNames from "classnames"; import InstallPluginModal from "./InstallPluginModal"; import UpdatePluginModal from "./UpdatePluginModal"; type Props = { plugin: Plugin, refresh: () => void, // context props classes: any }; type State = { showModal: boolean }; const styles = { link: { cursor: "pointer", pointerEvents: "all", padding: "0.5rem", border: "solid 1px var(--dark-25)", borderRadius: "4px", "&:hover": { borderColor: "var(--dark-50)" } }, topRight: { position: "absolute", right: 0, top: 0 } }; class PluginEntry extends React.Component { constructor(props: Props) { super(props); this.state = { showModal: false }; } createAvatar = (plugin: Plugin) => { return ; }; toggleModal = () => { this.setState(prevState => ({ showModal: !prevState.showModal })); }; createFooterRight = (plugin: Plugin) => { return {plugin.author}; }; isInstallable = () => { const { plugin } = this.props; return plugin._links && plugin._links.install && plugin._links.install.href; }; isUpdatable = () => { const { plugin } = this.props; return plugin._links && plugin._links.update && plugin._links.update.href; }; createActionbar = () => { const { classes } = this.props; if (this.isInstallable()) { return ( ); } else if (this.isUpdatable()) { return ( ); } }; renderModal = () => { const { plugin, refresh } = this.props; if (this.isInstallable()) { return ( ); } else if (this.isUpdatable()) { return ( ); } }; createPendingSpinner = () => { const { plugin, classes } = this.props; if (plugin.pending) { return ( ); } return null; }; render() { const { plugin } = this.props; const { showModal } = this.state; const avatar = this.createAvatar(plugin); const actionbar = this.createActionbar(); const footerRight = this.createFooterRight(plugin); const modal = showModal ? this.renderModal() : null; return ( <> {modal} ); } } export default injectSheet(styles)(PluginEntry);