//@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 PluginModal from "./PluginModal"; const PluginAction = { INSTALL: "install", UPDATE: "update", UNINSTALL: "uninstall" }; type Props = { plugin: Plugin, refresh: () => void, // context props classes: any }; type State = { showInstallModal: boolean, showUpdateModal: boolean, showUninstallModal: 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 }, layout: { "& .level": { paddingBottom: "0.5rem" } }, actionbar: { display: "flex", "& span + span": { marginLeft: "0.5rem" } } }; class PluginEntry extends React.Component { constructor(props: Props) { super(props); this.state = { showInstallModal: false, showUpdateModal: false, showUninstallModal: false }; } createAvatar = (plugin: Plugin) => { return ; }; toggleModal = (showModal: string) => { const oldValue = this.state[showModal]; this.setState({ [showModal]: !oldValue }); }; 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; }; isUninstallable = () => { const { plugin } = this.props; return ( plugin._links && plugin._links.uninstall && plugin._links.uninstall.href ); }; createActionbar = () => { const { classes } = this.props; return (
{this.isInstallable() && ( this.toggleModal("showInstallModal")} > )} {this.isUninstallable() && ( this.toggleModal("showUninstallModal")} > )} {this.isUpdatable() && ( this.toggleModal("showUpdateModal")} > )}
); }; renderModal = () => { const { plugin, refresh } = this.props; if (this.state.showInstallModal && this.isInstallable()) { return ( this.toggleModal("showInstallModal")} /> ); } else if (this.state.showUpdateModal && this.isUpdatable()) { return ( this.toggleModal("showUpdateModal")} /> ); } else if (this.state.showUninstallModal && this.isUninstallable()) { return ( this.toggleModal("showUninstallModal")} /> ); } else { return null; } }; createPendingSpinner = () => { const { plugin, classes } = this.props; return ( ); }; render() { const { plugin, classes } = this.props; const avatar = this.createAvatar(plugin); const actionbar = this.createActionbar(); const footerRight = this.createFooterRight(plugin); const modal = this.renderModal(); return ( <> {modal} ); } } export default injectSheet(styles)(PluginEntry);