Files
SCM-Manager/scm-ui/ui-webapp/src/admin/components/form/ConfigForm.tsx

217 lines
5.7 KiB
TypeScript
Raw Normal View History

import React from "react";
import { translate } from "react-i18next";
import { SubmitButton, Notification } from "@scm-manager/ui-components";
import { NamespaceStrategies, Config } from "@scm-manager/ui-types";
import ProxySettings from "./ProxySettings";
import GeneralSettings from "./GeneralSettings";
import BaseUrlSettings from "./BaseUrlSettings";
import LoginAttempt from "./LoginAttempt";
2018-08-13 16:33:56 +02:00
type Props = {
submitForm: (p: Config) => void;
config?: Config;
loading?: boolean;
configReadPermission: boolean;
configUpdatePermission: boolean;
namespaceStrategies?: NamespaceStrategies;
// context props
t: (p: string) => string;
2018-08-13 16:33:56 +02:00
};
type State = {
config: Config;
showNotification: boolean;
2018-08-21 08:40:49 +02:00
error: {
loginAttemptLimitTimeout: boolean;
loginAttemptLimit: boolean;
};
changed: boolean;
2018-08-13 16:33:56 +02:00
};
class ConfigForm extends React.Component<Props, State> {
constructor(props: Props) {
super(props);
this.state = {
config: {
proxyPassword: null,
proxyPort: 0,
proxyServer: "",
2018-08-13 16:33:56 +02:00
proxyUser: null,
enableProxy: false,
realmDescription: "",
2018-08-13 16:33:56 +02:00
disableGroupingGrid: false,
dateFormat: "",
2018-08-13 16:33:56 +02:00
anonymousAccessEnabled: false,
baseUrl: "",
2018-08-13 16:33:56 +02:00
forceBaseUrl: false,
loginAttemptLimit: 0,
proxyExcludes: [],
skipFailedAuthenticators: false,
pluginUrl: "",
2018-08-13 16:33:56 +02:00
loginAttemptLimitTimeout: 0,
enabledXsrfProtection: true,
namespaceStrategy: "",
loginInfoUrl: "",
_links: {}
},
2018-08-16 16:41:17 +02:00
showNotification: false,
2018-08-21 08:40:49 +02:00
error: {
loginAttemptLimitTimeout: false,
loginAttemptLimit: false
},
changed: false
2018-08-13 16:33:56 +02:00
};
}
componentDidMount() {
const { config, configUpdatePermission } = this.props;
2018-08-13 16:33:56 +02:00
if (config) {
this.setState({
...this.state,
config: {
...config
}
});
}
if (!configUpdatePermission) {
this.setState({
...this.state,
showNotification: true
});
2018-08-13 16:33:56 +02:00
}
}
submit = (event: Event) => {
event.preventDefault();
this.setState({
changed: false
});
2018-08-13 16:33:56 +02:00
this.props.submitForm(this.state.config);
};
render() {
2019-03-04 16:47:44 +01:00
const {
loading,
t,
namespaceStrategies,
2019-03-04 16:47:44 +01:00
configReadPermission,
configUpdatePermission
2019-03-04 16:47:44 +01:00
} = this.props;
const config = this.state.config;
let noPermissionNotification = null;
2019-03-04 16:47:44 +01:00
if (!configReadPermission) {
return (
<Notification
type={"danger"}
children={t("config.form.no-read-permission-notification")}
2019-03-04 16:47:44 +01:00
/>
);
}
if (this.state.showNotification) {
noPermissionNotification = (
<Notification
type={"info"}
children={t("config.form.no-write-permission-notification")}
onClose={() => this.onClose()}
/>
);
}
2018-08-13 16:33:56 +02:00
return (
<form onSubmit={this.submit}>
{noPermissionNotification}
2018-08-13 16:33:56 +02:00
<GeneralSettings
namespaceStrategies={namespaceStrategies}
loginInfoUrl={config.loginInfoUrl}
2018-08-13 16:33:56 +02:00
realmDescription={config.realmDescription}
disableGroupingGrid={config.disableGroupingGrid}
dateFormat={config.dateFormat}
anonymousAccessEnabled={config.anonymousAccessEnabled}
skipFailedAuthenticators={config.skipFailedAuthenticators}
pluginUrl={config.pluginUrl}
enabledXsrfProtection={config.enabledXsrfProtection}
namespaceStrategy={config.namespaceStrategy}
2018-08-13 16:33:56 +02:00
onChange={(isValid, changedValue, name) =>
this.onChange(isValid, changedValue, name)
}
hasUpdatePermission={configUpdatePermission}
2018-08-13 16:33:56 +02:00
/>
<hr />
2018-08-16 16:41:17 +02:00
<LoginAttempt
loginAttemptLimit={config.loginAttemptLimit}
loginAttemptLimitTimeout={config.loginAttemptLimitTimeout}
onChange={(isValid, changedValue, name) =>
this.onChange(isValid, changedValue, name)
}
hasUpdatePermission={configUpdatePermission}
/>
<hr />
2018-08-13 16:33:56 +02:00
<BaseUrlSettings
baseUrl={config.baseUrl}
forceBaseUrl={config.forceBaseUrl}
onChange={(isValid, changedValue, name) =>
this.onChange(isValid, changedValue, name)
}
hasUpdatePermission={configUpdatePermission}
2018-08-13 16:33:56 +02:00
/>
<hr />
2018-08-13 16:33:56 +02:00
<ProxySettings
proxyPassword={config.proxyPassword ? config.proxyPassword : ""}
2018-08-13 16:33:56 +02:00
proxyPort={config.proxyPort}
proxyServer={config.proxyServer ? config.proxyServer : ""}
proxyUser={config.proxyUser ? config.proxyUser : ""}
2018-08-13 16:33:56 +02:00
enableProxy={config.enableProxy}
2018-08-16 11:18:28 +02:00
proxyExcludes={config.proxyExcludes}
2018-08-13 16:33:56 +02:00
onChange={(isValid, changedValue, name) =>
this.onChange(isValid, changedValue, name)
}
hasUpdatePermission={configUpdatePermission}
2018-08-13 16:33:56 +02:00
/>
<hr />
2018-08-13 16:33:56 +02:00
<SubmitButton
loading={loading}
label={t("config.form.submit")}
disabled={
!configUpdatePermission || this.hasError() || !this.state.changed
}
2018-08-13 16:33:56 +02:00
/>
</form>
);
}
onChange = (isValid: boolean, changedValue: any, name: string) => {
2018-08-16 16:41:17 +02:00
this.setState({
...this.state,
config: {
...this.state.config,
[name]: changedValue
2018-08-21 08:40:49 +02:00
},
error: {
...this.state.error,
[name]: !isValid
},
changed: true
2018-08-16 16:41:17 +02:00
});
};
2018-08-21 08:40:49 +02:00
hasError = () => {
return (
this.state.error.loginAttemptLimit ||
this.state.error.loginAttemptLimitTimeout
);
2018-08-13 16:33:56 +02:00
};
onClose = () => {
this.setState({
...this.state,
showNotification: false
});
};
2018-08-13 16:33:56 +02:00
}
export default translate("config")(ConfigForm);