mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-08 06:25:45 +01:00
implemented success banner for config changes
This commit is contained in:
@@ -2,12 +2,7 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import { translate } from "react-i18next";
|
import { translate } from "react-i18next";
|
||||||
import type { Links } from "@scm-manager/ui-types";
|
import type { Links } from "@scm-manager/ui-types";
|
||||||
import {
|
import { apiClient, SubmitButton, Loading, ErrorNotification } from "../";
|
||||||
apiClient,
|
|
||||||
SubmitButton,
|
|
||||||
Loading,
|
|
||||||
ErrorNotification
|
|
||||||
} from "../";
|
|
||||||
|
|
||||||
type RenderProps = {
|
type RenderProps = {
|
||||||
readOnly: boolean,
|
readOnly: boolean,
|
||||||
@@ -20,10 +15,10 @@ type Props = {
|
|||||||
render: (props: RenderProps) => any, // ???
|
render: (props: RenderProps) => any, // ???
|
||||||
|
|
||||||
// context props
|
// context props
|
||||||
t: (string) => string
|
t: string => string
|
||||||
};
|
};
|
||||||
|
|
||||||
type ConfigurationType = {
|
type ConfigurationType = {
|
||||||
_links: Links
|
_links: Links
|
||||||
} & Object;
|
} & Object;
|
||||||
|
|
||||||
@@ -32,6 +27,7 @@ type State = {
|
|||||||
fetching: boolean,
|
fetching: boolean,
|
||||||
modifying: boolean,
|
modifying: boolean,
|
||||||
contentType?: string,
|
contentType?: string,
|
||||||
|
configChanged: boolean,
|
||||||
|
|
||||||
configuration?: ConfigurationType,
|
configuration?: ConfigurationType,
|
||||||
modifiedConfiguration?: ConfigurationType,
|
modifiedConfiguration?: ConfigurationType,
|
||||||
@@ -43,12 +39,12 @@ type State = {
|
|||||||
* synchronizing the configuration with the backend.
|
* synchronizing the configuration with the backend.
|
||||||
*/
|
*/
|
||||||
class Configuration extends React.Component<Props, State> {
|
class Configuration extends React.Component<Props, State> {
|
||||||
|
|
||||||
constructor(props: Props) {
|
constructor(props: Props) {
|
||||||
super(props);
|
super(props);
|
||||||
this.state = {
|
this.state = {
|
||||||
fetching: true,
|
fetching: true,
|
||||||
modifying: false,
|
modifying: false,
|
||||||
|
configChanged: false,
|
||||||
valid: false
|
valid: false
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -56,7 +52,8 @@ class Configuration extends React.Component<Props, State> {
|
|||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
const { link } = this.props;
|
const { link } = this.props;
|
||||||
|
|
||||||
apiClient.get(link)
|
apiClient
|
||||||
|
.get(link)
|
||||||
.then(this.captureContentType)
|
.then(this.captureContentType)
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(this.loadConfig)
|
.then(this.loadConfig)
|
||||||
@@ -119,19 +116,39 @@ class Configuration extends React.Component<Props, State> {
|
|||||||
|
|
||||||
this.setState({ modifying: true });
|
this.setState({ modifying: true });
|
||||||
|
|
||||||
const {modifiedConfiguration} = this.state;
|
const { modifiedConfiguration } = this.state;
|
||||||
|
|
||||||
apiClient.put(this.getModificationUrl(), modifiedConfiguration, this.getContentType())
|
apiClient
|
||||||
.then(() => this.setState({ modifying: false }))
|
.put(
|
||||||
|
this.getModificationUrl(),
|
||||||
|
modifiedConfiguration,
|
||||||
|
this.getContentType()
|
||||||
|
)
|
||||||
|
.then(() => this.setState({ modifying: false, configChanged: true }))
|
||||||
.catch(this.handleError);
|
.catch(this.handleError);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
renderConfigChangedNotification = () => {
|
||||||
|
if (this.state.configChanged) {
|
||||||
|
return (
|
||||||
|
<div className="notification is-primary">
|
||||||
|
<button
|
||||||
|
className="delete"
|
||||||
|
onClick={() => this.setState({ configChanged: false })}
|
||||||
|
/>
|
||||||
|
{this.props.t("config-form.submit-success-notification")}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { t } = this.props;
|
const { t } = this.props;
|
||||||
const { fetching, error, configuration, modifying, valid } = this.state;
|
const { fetching, error, configuration, modifying, valid } = this.state;
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
return <ErrorNotification error={error}/>;
|
return <ErrorNotification error={error} />;
|
||||||
} else if (fetching || !configuration) {
|
} else if (fetching || !configuration) {
|
||||||
return <Loading />;
|
return <Loading />;
|
||||||
} else {
|
} else {
|
||||||
@@ -144,19 +161,21 @@ class Configuration extends React.Component<Props, State> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<form onSubmit={this.modifyConfiguration}>
|
<>
|
||||||
{ this.props.render(renderProps) }
|
{this.renderConfigChangedNotification()}
|
||||||
<hr/>
|
<form onSubmit={this.modifyConfiguration}>
|
||||||
<SubmitButton
|
{this.props.render(renderProps)}
|
||||||
label={t("config-form.submit")}
|
<hr />
|
||||||
disabled={!valid || readOnly}
|
<SubmitButton
|
||||||
loading={modifying}
|
label={t("config-form.submit")}
|
||||||
/>
|
disabled={!valid || readOnly}
|
||||||
</form>
|
loading={modifying}
|
||||||
|
/>
|
||||||
|
</form>
|
||||||
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default translate("config")(Configuration);
|
export default translate("config")(Configuration);
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
},
|
},
|
||||||
"config-form": {
|
"config-form": {
|
||||||
"submit": "Submit",
|
"submit": "Submit",
|
||||||
|
"submit-success-notification": "Configuration changed!",
|
||||||
"no-permission-notification": "Please note: You do not have the permission to edit the config!"
|
"no-permission-notification": "Please note: You do not have the permission to edit the config!"
|
||||||
},
|
},
|
||||||
"proxy-settings": {
|
"proxy-settings": {
|
||||||
|
|||||||
@@ -34,7 +34,19 @@ type Props = {
|
|||||||
t: string => string
|
t: string => string
|
||||||
};
|
};
|
||||||
|
|
||||||
class GlobalConfig extends React.Component<Props> {
|
type State = {
|
||||||
|
configChanged: boolean
|
||||||
|
};
|
||||||
|
|
||||||
|
class GlobalConfig extends React.Component<Props, State> {
|
||||||
|
constructor(props: Props) {
|
||||||
|
super(props);
|
||||||
|
|
||||||
|
this.state = {
|
||||||
|
configChanged: false
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
this.props.configReset();
|
this.props.configReset();
|
||||||
this.props.fetchConfig(this.props.configLink);
|
this.props.fetchConfig(this.props.configLink);
|
||||||
@@ -42,6 +54,22 @@ class GlobalConfig extends React.Component<Props> {
|
|||||||
|
|
||||||
modifyConfig = (config: Config) => {
|
modifyConfig = (config: Config) => {
|
||||||
this.props.modifyConfig(config);
|
this.props.modifyConfig(config);
|
||||||
|
this.setState({ configChanged: true });
|
||||||
|
};
|
||||||
|
|
||||||
|
renderConfigChangedNotification = () => {
|
||||||
|
if (this.state.configChanged) {
|
||||||
|
return (
|
||||||
|
<div className="notification is-primary">
|
||||||
|
<button
|
||||||
|
className="delete"
|
||||||
|
onClick={() => this.setState({ configChanged: false })}
|
||||||
|
/>
|
||||||
|
{this.props.t("config-form.submit-success-notification")}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
@@ -64,6 +92,7 @@ class GlobalConfig extends React.Component<Props> {
|
|||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<Title title={t("global-config.title")} />
|
<Title title={t("global-config.title")} />
|
||||||
|
{this.renderConfigChangedNotification()}
|
||||||
<ConfigForm
|
<ConfigForm
|
||||||
submitForm={config => this.modifyConfig(config)}
|
submitForm={config => this.modifyConfig(config)}
|
||||||
config={config}
|
config={config}
|
||||||
|
|||||||
Reference in New Issue
Block a user