2019-08-20 15:50:11 +02:00
|
|
|
//@flow
|
|
|
|
|
import React from "react";
|
2019-08-20 17:19:57 +02:00
|
|
|
import { compose } from "redux";
|
2019-08-20 15:50:11 +02:00
|
|
|
import { translate } from "react-i18next";
|
2019-08-20 17:19:57 +02:00
|
|
|
import injectSheet from "react-jss";
|
2019-08-20 15:50:11 +02:00
|
|
|
import type { Plugin } from "@scm-manager/ui-types";
|
|
|
|
|
import {
|
2019-08-21 09:59:28 +02:00
|
|
|
apiClient,
|
2019-08-20 15:50:11 +02:00
|
|
|
Button,
|
|
|
|
|
ButtonGroup,
|
2019-08-21 09:59:28 +02:00
|
|
|
Checkbox, ErrorNotification,
|
2019-08-20 15:50:11 +02:00
|
|
|
Modal,
|
|
|
|
|
SubmitButton
|
|
|
|
|
} from "@scm-manager/ui-components";
|
2019-08-20 17:19:57 +02:00
|
|
|
import classNames from "classnames";
|
2019-08-20 15:50:11 +02:00
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
|
plugin: Plugin,
|
|
|
|
|
onSubmit: () => void,
|
|
|
|
|
onClose: () => void,
|
|
|
|
|
|
|
|
|
|
// context props
|
2019-08-20 17:19:57 +02:00
|
|
|
classes: any,
|
2019-08-21 09:59:28 +02:00
|
|
|
t: (key: string, params?: Object) => string
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
type State = {
|
|
|
|
|
loading: boolean,
|
|
|
|
|
error?: Error
|
2019-08-20 15:50:11 +02:00
|
|
|
};
|
|
|
|
|
|
2019-08-20 17:19:57 +02:00
|
|
|
const styles = {
|
|
|
|
|
titleVersion: {
|
|
|
|
|
marginLeft: "0.75rem"
|
|
|
|
|
},
|
|
|
|
|
userLabelAlignment: {
|
|
|
|
|
textAlign: "left",
|
|
|
|
|
marginRight: 0,
|
|
|
|
|
minWidth: "5.5em"
|
|
|
|
|
},
|
|
|
|
|
userFieldFlex: {
|
|
|
|
|
flexGrow: 4
|
|
|
|
|
},
|
|
|
|
|
listSpacing: {
|
|
|
|
|
marginTop: "0 !important"
|
2019-08-21 09:59:28 +02:00
|
|
|
},
|
|
|
|
|
error: {
|
|
|
|
|
marginTop: "1em"
|
2019-08-20 17:19:57 +02:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2019-08-21 09:59:28 +02:00
|
|
|
class PluginModal extends React.Component<Props,State> {
|
|
|
|
|
|
|
|
|
|
constructor(props: Props) {
|
|
|
|
|
super(props);
|
|
|
|
|
this.state = {
|
|
|
|
|
loading: false
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
install = (e: Event) => {
|
|
|
|
|
const { plugin, onClose } = this.props;
|
|
|
|
|
this.setState({
|
|
|
|
|
loading: true
|
|
|
|
|
});
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
apiClient.post(plugin._links.install.href)
|
|
|
|
|
.then(() => {
|
|
|
|
|
this.setState({
|
|
|
|
|
loading: false,
|
|
|
|
|
error: undefined
|
|
|
|
|
}, onClose);
|
|
|
|
|
})
|
|
|
|
|
.catch(error => {
|
|
|
|
|
this.setState({
|
|
|
|
|
loading: false,
|
|
|
|
|
error: error
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
footer = () => {
|
|
|
|
|
const { onClose, t } = this.props;
|
|
|
|
|
const { loading, error } = this.state;
|
|
|
|
|
return (
|
|
|
|
|
<form>
|
|
|
|
|
<ButtonGroup>
|
|
|
|
|
<SubmitButton label={t("plugins.modal.install")} loading={loading} action={this.install} disabled={!!error} />
|
|
|
|
|
<Button label={t("plugins.modal.abort")} action={onClose} />
|
|
|
|
|
</ButtonGroup>
|
|
|
|
|
</form>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2019-08-20 15:50:11 +02:00
|
|
|
renderDependencies() {
|
2019-08-20 17:19:57 +02:00
|
|
|
const { plugin, classes, t } = this.props;
|
2019-08-20 15:50:11 +02:00
|
|
|
|
|
|
|
|
let dependencies = null;
|
|
|
|
|
if (plugin.dependencies && plugin.dependencies.length > 0) {
|
|
|
|
|
dependencies = (
|
|
|
|
|
<>
|
2019-08-20 17:23:03 +02:00
|
|
|
<strong>{t("plugins.modal.dependencyNotification")}</strong>
|
2019-08-20 17:19:57 +02:00
|
|
|
<div className="field is-horizontal">
|
|
|
|
|
<div
|
|
|
|
|
className={classNames(
|
|
|
|
|
classes.userLabelAlignment,
|
|
|
|
|
"field-label is-inline-flex"
|
|
|
|
|
)}
|
|
|
|
|
>
|
|
|
|
|
{t("plugins.modal.dependencies")}:
|
|
|
|
|
</div>
|
|
|
|
|
<div
|
|
|
|
|
className={classNames(
|
|
|
|
|
classes.userFieldFlex,
|
|
|
|
|
"field-body is-inline-flex"
|
|
|
|
|
)}
|
|
|
|
|
>
|
|
|
|
|
<ul className={classes.listSpacing}>
|
|
|
|
|
{plugin.dependencies.map((dependency, index) => {
|
|
|
|
|
return <li key={index}>{dependency}</li>;
|
|
|
|
|
})}
|
|
|
|
|
</ul>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2019-08-20 15:50:11 +02:00
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
return dependencies;
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-21 09:59:28 +02:00
|
|
|
renderError = () => {
|
|
|
|
|
const { classes } = this.props;
|
|
|
|
|
const { error } = this.state;
|
|
|
|
|
if (error) {
|
|
|
|
|
return (
|
|
|
|
|
<div className={classes.error}>
|
|
|
|
|
<ErrorNotification error={error} />
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
};
|
|
|
|
|
|
2019-08-20 15:50:11 +02:00
|
|
|
render() {
|
2019-08-21 09:59:28 +02:00
|
|
|
|
|
|
|
|
const { plugin, onClose, classes, t } = this.props;
|
2019-08-20 15:50:11 +02:00
|
|
|
|
|
|
|
|
const body = (
|
|
|
|
|
<>
|
2019-08-20 17:19:57 +02:00
|
|
|
<div className="media">
|
|
|
|
|
<div className="media-content">
|
2019-08-21 09:59:28 +02:00
|
|
|
<p>{plugin.description}</p>
|
2019-08-20 17:19:57 +02:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="media">
|
|
|
|
|
<div className="media-content">
|
|
|
|
|
<div className="field is-horizontal">
|
|
|
|
|
<div
|
|
|
|
|
className={classNames(
|
|
|
|
|
classes.userLabelAlignment,
|
|
|
|
|
"field-label is-inline-flex"
|
|
|
|
|
)}
|
|
|
|
|
>
|
|
|
|
|
{t("plugins.modal.author")}:
|
|
|
|
|
</div>
|
|
|
|
|
<div
|
|
|
|
|
className={classNames(
|
|
|
|
|
classes.userFieldFlex,
|
|
|
|
|
"field-body is-inline-flex"
|
|
|
|
|
)}
|
|
|
|
|
>
|
|
|
|
|
{plugin.author}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="field is-horizontal">
|
|
|
|
|
<div
|
|
|
|
|
className={classNames(
|
|
|
|
|
classes.userLabelAlignment,
|
|
|
|
|
"field-label is-inline-flex"
|
|
|
|
|
)}
|
|
|
|
|
>
|
|
|
|
|
{t("plugins.modal.version")}:
|
|
|
|
|
</div>
|
|
|
|
|
<div
|
|
|
|
|
className={classNames(
|
|
|
|
|
classes.userFieldFlex,
|
|
|
|
|
"field-body is-inline-flex"
|
|
|
|
|
)}
|
|
|
|
|
>
|
|
|
|
|
{plugin.version}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{this.renderDependencies()}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="media">
|
|
|
|
|
<div className="media-content">
|
|
|
|
|
<Checkbox
|
|
|
|
|
checked={false}
|
|
|
|
|
label={t("plugins.modal.restart")}
|
|
|
|
|
onChange={null}
|
|
|
|
|
disabled={null}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2019-08-21 09:59:28 +02:00
|
|
|
{this.renderError()}
|
2019-08-20 15:50:11 +02:00
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Modal
|
2019-08-20 17:19:57 +02:00
|
|
|
title={t("plugins.modal.title", {
|
2019-08-21 09:59:28 +02:00
|
|
|
name: plugin.displayName ? plugin.displayName : plugin.name
|
2019-08-20 17:19:57 +02:00
|
|
|
})}
|
2019-08-20 15:50:11 +02:00
|
|
|
closeFunction={() => onClose()}
|
|
|
|
|
body={body}
|
2019-08-21 09:59:28 +02:00
|
|
|
footer={this.footer()}
|
2019-08-20 15:50:11 +02:00
|
|
|
active={true}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-20 17:19:57 +02:00
|
|
|
export default compose(
|
|
|
|
|
injectSheet(styles),
|
|
|
|
|
translate("admin")
|
|
|
|
|
)(PluginModal);
|