import _ from 'lodash'; import PropTypes from 'prop-types'; import React, { Component } from 'react'; import { icons, inputTypes, kinds, sizes } from 'Helpers/Props'; import LoadingIndicator from 'Components/Loading/LoadingIndicator'; import FieldSet from 'Components/FieldSet'; import Icon from 'Components/Icon'; import ClipboardButton from 'Components/Link/ClipboardButton'; import PageContent from 'Components/Page/PageContent'; import PageContentBodyConnector from 'Components/Page/PageContentBodyConnector'; import SettingsToolbarConnector from 'Settings/SettingsToolbarConnector'; import Form from 'Components/Form/Form'; import FormGroup from 'Components/Form/FormGroup'; import FormLabel from 'Components/Form/FormLabel'; import FormInputGroup from 'Components/Form/FormInputGroup'; import FormInputButton from 'Components/Form/FormInputButton'; import ConfirmModal from 'Components/Modal/ConfirmModal'; class GeneralSettings extends Component { // // Lifecycle constructor(props, context) { super(props, context); this.state = { isConfirmApiKeyResetModalOpen: false, isRestartRequiredModalOpen: false }; } componentDidUpdate(prevProps) { const { settings, isSaving, saveError } = this.props; if (isSaving || saveError || !prevProps.isSaving) { return; } const prevSettings = prevProps.settings; const keys = [ 'bindAddress', 'port', 'urlBase', 'enableSsl', 'sslPort', 'sslCertHash', 'authenticationMethod', 'username', 'password', 'apiKey' ]; const pendingRestart = _.some(keys, (key) => { const setting = settings[key]; const prevSetting = prevSettings[key]; if (!setting || !prevSetting) { return false; } const previousValue = prevSetting.previousValue; const value = setting.value; return previousValue != null && previousValue !== value; }); this.setState({ isRestartRequiredModalOpen: pendingRestart }); } // // Listeners onApikeyFocus = (event) => { event.target.select(); } onResetApiKeyPress = () => { this.setState({ isConfirmApiKeyResetModalOpen: true }); } onConfirmResetApiKey = () => { this.setState({ isConfirmApiKeyResetModalOpen: false }); this.props.onConfirmResetApiKey(); } onCloseResetApiKeyModal = () => { this.setState({ isConfirmApiKeyResetModalOpen: false }); } onConfirmRestart = () => { this.setState({ isRestartRequiredModalOpen: false }); this.props.onConfirmRestart(); } onCloseRestartRequiredModalOpen = () => { this.setState({ isRestartRequiredModalOpen: false }); } // // Render render() { const { advancedSettings, isFetching, isPopulated, error, settings, hasSettings, isResettingApiKey, isMono, isWindows, mode, onInputChange, ...otherProps } = this.props; const { isConfirmApiKeyResetModalOpen, isRestartRequiredModalOpen } = this.state; const { bindAddress, port, urlBase, enableSsl, sslPort, sslCertHash, launchBrowser, authenticationMethod, username, password, apiKey, proxyEnabled, proxyType, proxyHostname, proxyPort, proxyUsername, proxyPassword, proxyBypassFilter, proxyBypassLocalAddresses, logLevel, analyticsEnabled, branch, updateAutomatically, updateMechanism, updateScriptPath } = settings; const authenticationMethodOptions = [ { key: 'none', value: 'None' }, { key: 'basic', value: 'Basic (Browser Popup)' }, { key: 'forms', value: 'Forms (Login Page)' } ]; const proxyTypeOptions = [ { key: 'http', value: 'HTTP(S)' }, { key: 'socks4', value: 'Socks4' }, { key: 'socks5', value: 'Socks5 (Support TOR)' } ]; const logLevelOptions = [ { key: 'info', value: 'Info' }, { key: 'debug', value: 'Debug' }, { key: 'trace', value: 'Trace' } ]; const updateOptions = [ { key: 'builtIn', value: 'Built-In' }, { key: 'script', value: 'Script' } ]; const authenticationEnabled = authenticationMethod && authenticationMethod.value !== 'none'; return ( { isFetching && !isPopulated && } { !isFetching && error &&
Unable to load General settings
} { hasSettings && isPopulated && !error &&
Bind Address Port Number URL Base Enable SSL { enableSsl.value && SSL Port } { isWindows && enableSsl.value && SSL Cert Hash } { mode !== 'service' && Open browser on start }
Authentication { authenticationEnabled && Username } { authenticationEnabled && Password } API Key , ]} onChange={onInputChange} onFocus={this.onApikeyFocus} {...apiKey} />
Use Proxy { proxyEnabled.value &&
Proxy Type Hostname Port Username Password Ignored Addresses Bypass Proxy for Local Addresses
}
Log Level
Send Anonymous Usage Data
{ advancedSettings &&
Branch { isMono &&
Automatic Mechanism { updateMechanism.value === 'script' && Script Path }
}
}
}
); } } GeneralSettings.propTypes = { advancedSettings: PropTypes.bool.isRequired, isFetching: PropTypes.bool.isRequired, isPopulated: PropTypes.bool.isRequired, error: PropTypes.object, isSaving: PropTypes.bool.isRequired, saveError: PropTypes.object, settings: PropTypes.object.isRequired, isResettingApiKey: PropTypes.bool.isRequired, hasSettings: PropTypes.bool.isRequired, isMono: PropTypes.bool.isRequired, isWindows: PropTypes.bool.isRequired, mode: PropTypes.string.isRequired, onInputChange: PropTypes.func.isRequired, onConfirmResetApiKey: PropTypes.func.isRequired, onConfirmRestart: PropTypes.func.isRequired }; export default GeneralSettings;