mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-15 09:46:16 +01:00
implemented plugin installation ui
This commit is contained in:
@@ -5,9 +5,10 @@ import { translate } from "react-i18next";
|
|||||||
import injectSheet from "react-jss";
|
import injectSheet from "react-jss";
|
||||||
import type { Plugin } from "@scm-manager/ui-types";
|
import type { Plugin } from "@scm-manager/ui-types";
|
||||||
import {
|
import {
|
||||||
|
apiClient,
|
||||||
Button,
|
Button,
|
||||||
ButtonGroup,
|
ButtonGroup,
|
||||||
Checkbox,
|
Checkbox, ErrorNotification,
|
||||||
Modal,
|
Modal,
|
||||||
SubmitButton
|
SubmitButton
|
||||||
} from "@scm-manager/ui-components";
|
} from "@scm-manager/ui-components";
|
||||||
@@ -20,7 +21,12 @@ type Props = {
|
|||||||
|
|
||||||
// context props
|
// context props
|
||||||
classes: any,
|
classes: any,
|
||||||
t: string => string
|
t: (key: string, params?: Object) => string
|
||||||
|
};
|
||||||
|
|
||||||
|
type State = {
|
||||||
|
loading: boolean,
|
||||||
|
error?: Error
|
||||||
};
|
};
|
||||||
|
|
||||||
const styles = {
|
const styles = {
|
||||||
@@ -37,10 +43,55 @@ const styles = {
|
|||||||
},
|
},
|
||||||
listSpacing: {
|
listSpacing: {
|
||||||
marginTop: "0 !important"
|
marginTop: "0 !important"
|
||||||
|
},
|
||||||
|
error: {
|
||||||
|
marginTop: "1em"
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class PluginModal extends React.Component<Props> {
|
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>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
renderDependencies() {
|
renderDependencies() {
|
||||||
const { plugin, classes, t } = this.props;
|
const { plugin, classes, t } = this.props;
|
||||||
|
|
||||||
@@ -77,14 +128,28 @@ class PluginModal extends React.Component<Props> {
|
|||||||
return dependencies;
|
return dependencies;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
renderError = () => {
|
||||||
|
const { classes } = this.props;
|
||||||
|
const { error } = this.state;
|
||||||
|
if (error) {
|
||||||
|
return (
|
||||||
|
<div className={classes.error}>
|
||||||
|
<ErrorNotification error={error} />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { plugin, onSubmit, onClose, classes, t } = this.props;
|
|
||||||
|
const { plugin, onClose, classes, t } = this.props;
|
||||||
|
|
||||||
const body = (
|
const body = (
|
||||||
<>
|
<>
|
||||||
<div className="media">
|
<div className="media">
|
||||||
<div className="media-content">
|
<div className="media-content">
|
||||||
<p>{plugin.description && plugin.description}</p>
|
<p>{plugin.description}</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="media">
|
<div className="media">
|
||||||
@@ -139,26 +204,18 @@ class PluginModal extends React.Component<Props> {
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
{this.renderError()}
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|
||||||
const footer = (
|
|
||||||
<form onSubmit={onSubmit}>
|
|
||||||
<ButtonGroup>
|
|
||||||
<SubmitButton label={t("plugins.modal.install")} />
|
|
||||||
<Button label={t("plugins.modal.abort")} action={onClose} />
|
|
||||||
</ButtonGroup>
|
|
||||||
</form>
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal
|
<Modal
|
||||||
title={t("plugins.modal.title", {
|
title={t("plugins.modal.title", {
|
||||||
name: plugin.displayName ? plugin.displayName : ""
|
name: plugin.displayName ? plugin.displayName : plugin.name
|
||||||
})}
|
})}
|
||||||
closeFunction={() => onClose()}
|
closeFunction={() => onClose()}
|
||||||
body={body}
|
body={body}
|
||||||
footer={footer}
|
footer={this.footer()}
|
||||||
active={true}
|
active={true}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -86,7 +86,6 @@ public class AvailablePluginResource {
|
|||||||
*/
|
*/
|
||||||
@POST
|
@POST
|
||||||
@Path("/{name}/install")
|
@Path("/{name}/install")
|
||||||
@Consumes(VndMediaType.PLUGIN)
|
|
||||||
@StatusCodes({
|
@StatusCodes({
|
||||||
@ResponseCode(code = 200, condition = "success"),
|
@ResponseCode(code = 200, condition = "success"),
|
||||||
@ResponseCode(code = 500, condition = "internal server error")
|
@ResponseCode(code = 500, condition = "internal server error")
|
||||||
|
|||||||
@@ -132,7 +132,6 @@ class AvailablePluginResourceTest {
|
|||||||
@Test
|
@Test
|
||||||
void installPlugin() throws URISyntaxException {
|
void installPlugin() throws URISyntaxException {
|
||||||
MockHttpRequest request = MockHttpRequest.post("/v2/plugins/available/pluginName/install");
|
MockHttpRequest request = MockHttpRequest.post("/v2/plugins/available/pluginName/install");
|
||||||
request.accept(VndMediaType.PLUGIN);
|
|
||||||
MockHttpResponse response = new MockHttpResponse();
|
MockHttpResponse response = new MockHttpResponse();
|
||||||
|
|
||||||
dispatcher.invoke(request, response);
|
dispatcher.invoke(request, response);
|
||||||
|
|||||||
Reference in New Issue
Block a user