diff --git a/scm-ui/src/admin/plugins/components/InstallPendingModal.js b/scm-ui/src/admin/plugins/components/InstallPendingModal.js index c0094d8d4f..e79d815b3d 100644 --- a/scm-ui/src/admin/plugins/components/InstallPendingModal.js +++ b/scm-ui/src/admin/plugins/components/InstallPendingModal.js @@ -10,6 +10,8 @@ import { } from "@scm-manager/ui-components"; import type { PluginCollection } from "@scm-manager/ui-types"; import { translate } from "react-i18next"; +import waitForRestart from "./waitForRestart"; +import InstallSuccessNotification from "./InstallSuccessNotification"; type Props = { onClose: () => void, @@ -40,14 +42,7 @@ class InstallPendingModal extends React.Component { if (error) { return ; } else if (success) { - return ( - - {t("plugins.modal.successNotification")}{" "} - window.location.reload()}> - {t("plugins.modal.reload")} - - - ); + return ; } else { return ( @@ -65,6 +60,7 @@ class InstallPendingModal extends React.Component { apiClient .post(collection._links.installPending.href) + .then(waitForRestart) .then(() => { this.setState({ success: true, @@ -92,7 +88,9 @@ class InstallPendingModal extends React.Component { {collection._embedded.plugins .filter(plugin => plugin.pending) .map(plugin => ( -
  • {plugin.name}
  • +
  • + {plugin.name} +
  • ))} diff --git a/scm-ui/src/admin/plugins/components/InstallSuccessNotification.js b/scm-ui/src/admin/plugins/components/InstallSuccessNotification.js new file mode 100644 index 0000000000..daebb8a8d0 --- /dev/null +++ b/scm-ui/src/admin/plugins/components/InstallSuccessNotification.js @@ -0,0 +1,25 @@ +// @flow +import React from "react"; +import { translate } from "react-i18next"; +import { Notification } from "@scm-manager/ui-components"; + +type Props = { + // context props + t: string => string +}; + +class InstallSuccessNotification extends React.Component { + render() { + const { t } = this.props; + return ( + + {t("plugins.modal.successNotification")}{" "} + window.location.reload(true)}> + {t("plugins.modal.reload")} + + + ); + } +} + +export default translate("admin")(InstallSuccessNotification); diff --git a/scm-ui/src/admin/plugins/components/PluginModal.js b/scm-ui/src/admin/plugins/components/PluginModal.js index 8f65ba9349..4440bf0ef3 100644 --- a/scm-ui/src/admin/plugins/components/PluginModal.js +++ b/scm-ui/src/admin/plugins/components/PluginModal.js @@ -14,6 +14,8 @@ import { Notification } from "@scm-manager/ui-components"; import classNames from "classnames"; +import waitForRestart from "./waitForRestart"; +import InstallSuccessNotification from "./InstallSuccessNotification"; type Props = { plugin: Plugin, @@ -63,10 +65,20 @@ class PluginModal extends React.Component { }; if (restart) { - this.setState({ - ...newState, - success: true - }); + waitForRestart() + .then(() => { + this.setState({ + ...newState, + success: true + }); + }) + .catch(error => { + this.setState({ + loading: false, + success: false, + error + }); + }); } else { this.setState(newState, () => { refresh(); @@ -150,12 +162,7 @@ class PluginModal extends React.Component { } else if (success) { return (
    - - {t("plugins.modal.successNotification")}{" "} - window.location.reload()}> - {t("plugins.modal.reload")} - - +
    ); } else if (restart) { diff --git a/scm-ui/src/admin/plugins/components/waitForRestart.js b/scm-ui/src/admin/plugins/components/waitForRestart.js new file mode 100644 index 0000000000..93b7b17855 --- /dev/null +++ b/scm-ui/src/admin/plugins/components/waitForRestart.js @@ -0,0 +1,30 @@ +// @flow +import { apiClient } from "@scm-manager/ui-components"; + +const waitForRestart = () => { + const endTime = Number(new Date()) + 10000; + let started = false; + + const executor = (resolve, reject) => { + // we need some initial delay + if (!started) { + started = true; + setTimeout(executor, 100, resolve, reject); + } else { + apiClient + .get("") + .then(resolve) + .catch(() => { + if (Number(new Date()) < endTime) { + setTimeout(executor, 500, resolve, reject); + } else { + reject(new Error("timeout reached")); + } + }); + } + }; + + return new Promise(executor); +}; + +export default waitForRestart;