2019-08-21 14:54:01 +02:00
|
|
|
// @flow
|
|
|
|
|
import React from "react";
|
|
|
|
|
import {
|
|
|
|
|
apiClient,
|
|
|
|
|
Button,
|
|
|
|
|
ButtonGroup,
|
|
|
|
|
ErrorNotification,
|
|
|
|
|
Modal,
|
|
|
|
|
Notification
|
|
|
|
|
} from "@scm-manager/ui-components";
|
2019-09-16 14:31:55 +02:00
|
|
|
import type { PendingPlugins } from "@scm-manager/ui-types";
|
2019-08-21 14:54:01 +02:00
|
|
|
import { translate } from "react-i18next";
|
2019-08-22 08:24:01 +02:00
|
|
|
import waitForRestart from "./waitForRestart";
|
2019-09-16 18:51:00 +02:00
|
|
|
import SuccessNotification from "./SuccessNotification";
|
2019-08-21 14:54:01 +02:00
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
|
onClose: () => void,
|
2019-09-16 14:31:55 +02:00
|
|
|
pendingPlugins: PendingPlugins,
|
2019-08-21 14:54:01 +02:00
|
|
|
|
|
|
|
|
// context props
|
|
|
|
|
t: string => string
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
type State = {
|
|
|
|
|
loading: boolean,
|
|
|
|
|
success: boolean,
|
|
|
|
|
error?: Error
|
|
|
|
|
};
|
|
|
|
|
|
2019-09-16 14:31:55 +02:00
|
|
|
class ExecutePendingModal extends React.Component<Props, State> {
|
2019-08-21 14:54:01 +02:00
|
|
|
constructor(props: Props) {
|
|
|
|
|
super(props);
|
|
|
|
|
this.state = {
|
|
|
|
|
loading: false,
|
|
|
|
|
success: false
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
renderNotifications = () => {
|
|
|
|
|
const { t } = this.props;
|
|
|
|
|
const { error, success } = this.state;
|
|
|
|
|
if (error) {
|
|
|
|
|
return <ErrorNotification error={error} />;
|
|
|
|
|
} else if (success) {
|
2019-09-16 18:51:00 +02:00
|
|
|
return <SuccessNotification />;
|
2019-08-21 14:54:01 +02:00
|
|
|
} else {
|
|
|
|
|
return (
|
|
|
|
|
<Notification type="warning">
|
|
|
|
|
{t("plugins.modal.restartNotification")}
|
|
|
|
|
</Notification>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2019-09-16 18:51:00 +02:00
|
|
|
executeAndRestart = () => {
|
2019-09-16 14:31:55 +02:00
|
|
|
const { pendingPlugins } = this.props;
|
2019-08-21 14:54:01 +02:00
|
|
|
this.setState({
|
|
|
|
|
loading: true
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
apiClient
|
2019-09-16 14:31:55 +02:00
|
|
|
.post(pendingPlugins._links.execute.href)
|
2019-08-22 08:24:01 +02:00
|
|
|
.then(waitForRestart)
|
2019-08-21 14:54:01 +02:00
|
|
|
.then(() => {
|
|
|
|
|
this.setState({
|
|
|
|
|
success: true,
|
|
|
|
|
loading: false,
|
|
|
|
|
error: undefined
|
|
|
|
|
});
|
|
|
|
|
})
|
|
|
|
|
.catch(error => {
|
|
|
|
|
this.setState({
|
|
|
|
|
success: false,
|
|
|
|
|
loading: false,
|
|
|
|
|
error: error
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2019-09-16 14:31:55 +02:00
|
|
|
renderInstallQueue = () => {
|
|
|
|
|
const { pendingPlugins, t } = this.props;
|
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
{pendingPlugins._embedded &&
|
|
|
|
|
pendingPlugins._embedded.new.length > 0 && (
|
|
|
|
|
<>
|
|
|
|
|
<strong>{t("plugins.modal.installQueue")}</strong>
|
|
|
|
|
<ul>
|
2019-09-17 16:25:24 +02:00
|
|
|
{pendingPlugins._embedded.new.map(plugin => (
|
|
|
|
|
<li key={plugin.name}>{plugin.name}</li>
|
|
|
|
|
))}
|
2019-09-16 14:31:55 +02:00
|
|
|
</ul>
|
|
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
renderUpdateQueue = () => {
|
|
|
|
|
const { pendingPlugins, t } = this.props;
|
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
{pendingPlugins._embedded &&
|
|
|
|
|
pendingPlugins._embedded.update.length > 0 && (
|
|
|
|
|
<>
|
|
|
|
|
<strong>{t("plugins.modal.updateQueue")}</strong>
|
|
|
|
|
<ul>
|
2019-09-17 16:25:24 +02:00
|
|
|
{pendingPlugins._embedded.update.map(plugin => (
|
|
|
|
|
<li key={plugin.name}>{plugin.name}</li>
|
|
|
|
|
))}
|
|
|
|
|
</ul>
|
|
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
renderUninstallQueue = () => {
|
|
|
|
|
const { pendingPlugins, t } = this.props;
|
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
{pendingPlugins._embedded &&
|
|
|
|
|
pendingPlugins._embedded.uninstall.length > 0 && (
|
|
|
|
|
<>
|
|
|
|
|
<strong>{t("plugins.modal.uninstallQueue")}</strong>
|
|
|
|
|
<ul>
|
|
|
|
|
{pendingPlugins._embedded.uninstall.map(plugin => (
|
|
|
|
|
<li key={plugin.name}>{plugin.name}</li>
|
|
|
|
|
))}
|
2019-09-16 14:31:55 +02:00
|
|
|
</ul>
|
|
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2019-08-21 14:54:01 +02:00
|
|
|
renderBody = () => {
|
2019-09-16 14:31:55 +02:00
|
|
|
const { t } = this.props;
|
2019-08-21 14:54:01 +02:00
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
<div className="media">
|
|
|
|
|
<div className="content">
|
2019-09-16 14:31:55 +02:00
|
|
|
<p>{t("plugins.modal.executePending")}</p>
|
|
|
|
|
{this.renderInstallQueue()}
|
|
|
|
|
{this.renderUpdateQueue()}
|
2019-09-17 16:25:24 +02:00
|
|
|
{this.renderUninstallQueue()}
|
2019-08-21 14:54:01 +02:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="media">{this.renderNotifications()}</div>
|
|
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
renderFooter = () => {
|
|
|
|
|
const { onClose, t } = this.props;
|
|
|
|
|
const { loading, error, success } = this.state;
|
|
|
|
|
return (
|
|
|
|
|
<ButtonGroup>
|
|
|
|
|
<Button
|
|
|
|
|
color="warning"
|
2019-09-16 14:31:55 +02:00
|
|
|
label={t("plugins.modal.executeAndRestart")}
|
2019-08-21 14:54:01 +02:00
|
|
|
loading={loading}
|
2019-09-16 18:51:00 +02:00
|
|
|
action={this.executeAndRestart}
|
2019-08-21 14:54:01 +02:00
|
|
|
disabled={error || success}
|
|
|
|
|
/>
|
|
|
|
|
<Button label={t("plugins.modal.abort")} action={onClose} />
|
|
|
|
|
</ButtonGroup>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
render() {
|
|
|
|
|
const { onClose, t } = this.props;
|
|
|
|
|
return (
|
|
|
|
|
<Modal
|
2019-09-16 14:31:55 +02:00
|
|
|
title={t("plugins.modal.executeAndRestart")}
|
2019-08-21 14:54:01 +02:00
|
|
|
closeFunction={onClose}
|
|
|
|
|
body={this.renderBody()}
|
|
|
|
|
footer={this.renderFooter()}
|
|
|
|
|
active={true}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-16 14:31:55 +02:00
|
|
|
export default translate("admin")(ExecutePendingModal);
|