Files
SCM-Manager/scm-ui/src/admin/plugins/components/InstallPendingModal.js

135 lines
3.1 KiB
JavaScript
Raw Normal View History

// @flow
import React from "react";
import {
apiClient,
Button,
ButtonGroup,
ErrorNotification,
Modal,
Notification
} from "@scm-manager/ui-components";
import type { PluginCollection } from "@scm-manager/ui-types";
import { translate } from "react-i18next";
2019-08-22 08:24:01 +02:00
import waitForRestart from "./waitForRestart";
import InstallSuccessNotification from "./InstallSuccessNotification";
type Props = {
onClose: () => void,
collection: PluginCollection,
// context props
t: string => string
};
type State = {
loading: boolean,
success: boolean,
error?: Error
};
class InstallPendingModal extends React.Component<Props, State> {
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-08-22 08:24:01 +02:00
return <InstallSuccessNotification />;
} else {
return (
<Notification type="warning">
{t("plugins.modal.restartNotification")}
</Notification>
);
}
};
installAndRestart = () => {
const { collection } = this.props;
this.setState({
loading: true
});
apiClient
.post(collection._links.installPending.href)
2019-08-22 08:24:01 +02:00
.then(waitForRestart)
.then(() => {
this.setState({
success: true,
loading: false,
error: undefined
});
})
.catch(error => {
this.setState({
success: false,
loading: false,
error: error
});
});
};
renderBody = () => {
const { collection, t } = this.props;
return (
<>
<div className="media">
<div className="content">
<p>{t("plugins.modal.installPending")}</p>
<ul>
{collection._embedded.plugins
.filter(plugin => plugin.pending)
.map(plugin => (
2019-08-22 08:24:01 +02:00
<li key={plugin.name} className="has-text-weight-bold">
{plugin.name}
</li>
))}
</ul>
</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"
label={t("plugins.modal.installAndRestart")}
loading={loading}
action={this.installAndRestart}
disabled={error || success}
/>
<Button label={t("plugins.modal.abort")} action={onClose} />
</ButtonGroup>
);
};
render() {
const { onClose, t } = this.props;
return (
<Modal
title={t("plugins.modal.installAndRestart")}
closeFunction={onClose}
body={this.renderBody()}
footer={this.renderFooter()}
active={true}
/>
);
}
}
export default translate("admin")(InstallPendingModal);