mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-11 07:55:47 +01:00
wait until restart is complete
This commit is contained in:
@@ -10,6 +10,8 @@ import {
|
|||||||
} from "@scm-manager/ui-components";
|
} from "@scm-manager/ui-components";
|
||||||
import type { PluginCollection } from "@scm-manager/ui-types";
|
import type { PluginCollection } from "@scm-manager/ui-types";
|
||||||
import { translate } from "react-i18next";
|
import { translate } from "react-i18next";
|
||||||
|
import waitForRestart from "./waitForRestart";
|
||||||
|
import InstallSuccessNotification from "./InstallSuccessNotification";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
onClose: () => void,
|
onClose: () => void,
|
||||||
@@ -40,14 +42,7 @@ class InstallPendingModal extends React.Component<Props, State> {
|
|||||||
if (error) {
|
if (error) {
|
||||||
return <ErrorNotification error={error} />;
|
return <ErrorNotification error={error} />;
|
||||||
} else if (success) {
|
} else if (success) {
|
||||||
return (
|
return <InstallSuccessNotification />;
|
||||||
<Notification type="success">
|
|
||||||
{t("plugins.modal.successNotification")}{" "}
|
|
||||||
<a onClick={e => window.location.reload()}>
|
|
||||||
{t("plugins.modal.reload")}
|
|
||||||
</a>
|
|
||||||
</Notification>
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
return (
|
return (
|
||||||
<Notification type="warning">
|
<Notification type="warning">
|
||||||
@@ -65,6 +60,7 @@ class InstallPendingModal extends React.Component<Props, State> {
|
|||||||
|
|
||||||
apiClient
|
apiClient
|
||||||
.post(collection._links.installPending.href)
|
.post(collection._links.installPending.href)
|
||||||
|
.then(waitForRestart)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
this.setState({
|
this.setState({
|
||||||
success: true,
|
success: true,
|
||||||
@@ -92,7 +88,9 @@ class InstallPendingModal extends React.Component<Props, State> {
|
|||||||
{collection._embedded.plugins
|
{collection._embedded.plugins
|
||||||
.filter(plugin => plugin.pending)
|
.filter(plugin => plugin.pending)
|
||||||
.map(plugin => (
|
.map(plugin => (
|
||||||
<li key={plugin.name} className="has-text-weight-bold">{plugin.name}</li>
|
<li key={plugin.name} className="has-text-weight-bold">
|
||||||
|
{plugin.name}
|
||||||
|
</li>
|
||||||
))}
|
))}
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -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<Props> {
|
||||||
|
render() {
|
||||||
|
const { t } = this.props;
|
||||||
|
return (
|
||||||
|
<Notification type="success">
|
||||||
|
{t("plugins.modal.successNotification")}{" "}
|
||||||
|
<a onClick={e => window.location.reload(true)}>
|
||||||
|
{t("plugins.modal.reload")}
|
||||||
|
</a>
|
||||||
|
</Notification>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default translate("admin")(InstallSuccessNotification);
|
||||||
@@ -14,6 +14,8 @@ import {
|
|||||||
Notification
|
Notification
|
||||||
} from "@scm-manager/ui-components";
|
} from "@scm-manager/ui-components";
|
||||||
import classNames from "classnames";
|
import classNames from "classnames";
|
||||||
|
import waitForRestart from "./waitForRestart";
|
||||||
|
import InstallSuccessNotification from "./InstallSuccessNotification";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
plugin: Plugin,
|
plugin: Plugin,
|
||||||
@@ -63,10 +65,20 @@ class PluginModal extends React.Component<Props, State> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (restart) {
|
if (restart) {
|
||||||
this.setState({
|
waitForRestart()
|
||||||
...newState,
|
.then(() => {
|
||||||
success: true
|
this.setState({
|
||||||
});
|
...newState,
|
||||||
|
success: true
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
this.setState({
|
||||||
|
loading: false,
|
||||||
|
success: false,
|
||||||
|
error
|
||||||
|
});
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
this.setState(newState, () => {
|
this.setState(newState, () => {
|
||||||
refresh();
|
refresh();
|
||||||
@@ -150,12 +162,7 @@ class PluginModal extends React.Component<Props, State> {
|
|||||||
} else if (success) {
|
} else if (success) {
|
||||||
return (
|
return (
|
||||||
<div className="media">
|
<div className="media">
|
||||||
<Notification type="success">
|
<InstallSuccessNotification />
|
||||||
{t("plugins.modal.successNotification")}{" "}
|
|
||||||
<a onClick={e => window.location.reload()}>
|
|
||||||
{t("plugins.modal.reload")}
|
|
||||||
</a>
|
|
||||||
</Notification>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
} else if (restart) {
|
} else if (restart) {
|
||||||
|
|||||||
30
scm-ui/src/admin/plugins/components/waitForRestart.js
Normal file
30
scm-ui/src/admin/plugins/components/waitForRestart.js
Normal file
@@ -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<void>(executor);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default waitForRestart;
|
||||||
Reference in New Issue
Block a user