// @flow import React from "react"; import { translate } from "react-i18next"; import { SubmitButton } from "../../../components/buttons/index"; import type { Config } from "../../types/Config"; import ProxySettings from "./ProxySettings"; import GeneralSettings from "./GeneralSettings"; import BaseUrlSettings from "./BaseUrlSettings"; import AdminSettings from "./AdminSettings"; import Notification from "../../../components/Notification"; type Props = { submitForm: Config => void, config?: Config, loading?: boolean, t: string => string, configUpdatePermission: boolean }; type State = { config: Config, showNotification: boolean }; class ConfigForm extends React.Component { constructor(props: Props) { super(props); this.state = { config: { proxyPassword: null, proxyPort: 0, proxyServer: "", proxyUser: null, enableProxy: false, realmDescription: "", enableRepositoryArchive: false, disableGroupingGrid: false, dateFormat: "", anonymousAccessEnabled: false, adminGroups: [], adminUsers: [], baseUrl: "", forceBaseUrl: false, loginAttemptLimit: 0, proxyExcludes: [], skipFailedAuthenticators: false, pluginUrl: "", loginAttemptLimitTimeout: 0, enabledXsrfProtection: true, defaultNamespaceStrategy: "", _links: {} }, showNotification: false }; } componentDidMount() { const { config, configUpdatePermission } = this.props; if (config) { this.setState({ ...this.state, config: { ...config } }); } if (!configUpdatePermission) { this.setState({ ...this.state, showNotification: true }); } } submit = (event: Event) => { event.preventDefault(); this.props.submitForm(this.state.config); }; render() { const { loading, t, configUpdatePermission } = this.props; const config = this.state.config; let noPermissionNotification = null; if (this.state.showNotification) { noPermissionNotification = ( this.onClose()} /> ); } return (
{noPermissionNotification} this.onChange(isValid, changedValue, name) } hasUpdatePermission={configUpdatePermission} />
this.onChange(isValid, changedValue, name) } hasUpdatePermission={configUpdatePermission} />
this.onChange(isValid, changedValue, name) } hasUpdatePermission={configUpdatePermission} />
this.onChange(isValid, changedValue, name) } hasUpdatePermission={configUpdatePermission} />
); } onChange = (isValid: boolean, changedValue: any, name: string) => { if (isValid) { this.setState({ ...this.state, config: { ...this.state.config, [name]: changedValue } }); } }; onClose = () => { this.setState({ ...this.state, showNotification: false }); }; } export default translate("config")(ConfigForm);