// @flow import React from "react"; import { apiClient, Button, ButtonGroup, ErrorNotification, Modal, Notification } from "@scm-manager/ui-components"; import type { PendingPlugins } from "@scm-manager/ui-types"; import { translate } from "react-i18next"; import waitForRestart from "./waitForRestart"; import SuccessNotification from "./SuccessNotification"; type Props = { onClose: () => void, pendingPlugins: PendingPlugins, // context props t: string => string }; type State = { loading: boolean, success: boolean, error?: Error }; class ExecutePendingModal extends React.Component { constructor(props: Props) { super(props); this.state = { loading: false, success: false }; } renderNotifications = () => { const { t } = this.props; const { error, success } = this.state; if (error) { return ; } else if (success) { return ; } else { return ( {t("plugins.modal.restartNotification")} ); } }; executeAndRestart = () => { const { pendingPlugins } = this.props; this.setState({ loading: true }); apiClient .post(pendingPlugins._links.execute.href) .then(waitForRestart) .then(() => { this.setState({ success: true, loading: false, error: undefined }); }) .catch(error => { this.setState({ success: false, loading: false, error: error }); }); }; renderInstallQueue = () => { const { pendingPlugins, t } = this.props; return ( <> {pendingPlugins._embedded && pendingPlugins._embedded.new.length > 0 && ( <> {t("plugins.modal.installQueue")}
    {pendingPlugins._embedded.new .filter(plugin => plugin.pending) .map(plugin => (
  • {plugin.name}
  • ))}
)} ); }; renderUpdateQueue = () => { const { pendingPlugins, t } = this.props; return ( <> {pendingPlugins._embedded && pendingPlugins._embedded.update.length > 0 && ( <> {t("plugins.modal.updateQueue")}
    {pendingPlugins._embedded.update .filter(plugin => plugin.pending) .map(plugin => (
  • {plugin.name}
  • ))}
)} ); }; renderBody = () => { const { t } = this.props; return ( <>

{t("plugins.modal.executePending")}

{this.renderInstallQueue()} {this.renderUpdateQueue()}
{this.renderNotifications()}
); }; renderFooter = () => { const { onClose, t } = this.props; const { loading, error, success } = this.state; return (