2018-11-23 07:04:42 +00:00
import _ from 'lodash' ;
import PropTypes from 'prop-types' ;
import React , { Component } from 'react' ;
2020-07-28 18:47:25 +00:00
import Form from 'Components/Form/Form' ;
2018-11-23 07:04:42 +00:00
import LoadingIndicator from 'Components/Loading/LoadingIndicator' ;
2020-07-28 18:47:25 +00:00
import ConfirmModal from 'Components/Modal/ConfirmModal' ;
2018-11-23 07:04:42 +00:00
import PageContent from 'Components/Page/PageContent' ;
2020-05-25 04:22:33 +00:00
import PageContentBody from 'Components/Page/PageContentBody' ;
2020-07-28 18:47:25 +00:00
import { kinds } from 'Helpers/Props' ;
2018-11-23 07:04:42 +00:00
import SettingsToolbarConnector from 'Settings/SettingsToolbarConnector' ;
2020-08-29 03:56:13 +00:00
import translate from 'Utilities/String/translate' ;
2018-11-23 07:04:42 +00:00
import AnalyticSettings from './AnalyticSettings' ;
import BackupSettings from './BackupSettings' ;
import HostSettings from './HostSettings' ;
import LoggingSettings from './LoggingSettings' ;
import ProxySettings from './ProxySettings' ;
import SecuritySettings from './SecuritySettings' ;
import UpdateSettings from './UpdateSettings' ;
2019-07-01 01:50:01 +00:00
const requiresRestartKeys = [
'bindAddress' ,
'port' ,
'urlBase' ,
'enableSsl' ,
'sslPort' ,
2019-10-14 20:21:00 +00:00
'sslCertPath' ,
2021-10-21 20:04:26 +00:00
'sslCertPassword'
2019-07-01 01:50:01 +00:00
] ;
2018-11-23 07:04:42 +00:00
class GeneralSettings extends Component {
//
// Lifecycle
constructor ( props , context ) {
super ( props , context ) ;
this . state = {
isRestartRequiredModalOpen : false
} ;
}
componentDidUpdate ( prevProps ) {
const {
settings ,
isSaving ,
2020-02-22 20:41:39 +00:00
saveError ,
isResettingApiKey
2018-11-23 07:04:42 +00:00
} = this . props ;
2020-02-22 20:41:39 +00:00
if ( ! isResettingApiKey && prevProps . isResettingApiKey ) {
this . setState ( { isRestartRequiredModalOpen : true } ) ;
return ;
}
2018-11-23 07:04:42 +00:00
if ( isSaving || saveError || ! prevProps . isSaving ) {
return ;
}
const prevSettings = prevProps . settings ;
2019-07-01 01:50:01 +00:00
const pendingRestart = _ . some ( requiresRestartKeys , ( key ) => {
2018-11-23 07:04:42 +00:00
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
onConfirmRestart = ( ) => {
this . setState ( { isRestartRequiredModalOpen : false } ) ;
this . props . onConfirmRestart ( ) ;
}
onCloseRestartRequiredModalOpen = ( ) => {
this . setState ( { isRestartRequiredModalOpen : false } ) ;
}
//
// Render
render ( ) {
const {
advancedSettings ,
isFetching ,
isPopulated ,
error ,
settings ,
hasSettings ,
isResettingApiKey ,
isWindows ,
2019-07-01 01:50:01 +00:00
isWindowsService ,
2018-11-23 07:04:42 +00:00
mode ,
2020-04-19 18:08:31 +00:00
packageUpdateMechanism ,
2018-11-23 07:04:42 +00:00
onInputChange ,
onConfirmResetApiKey ,
... otherProps
} = this . props ;
return (
2020-08-29 03:56:13 +00:00
< PageContent title = { translate ( 'GeneralSettings' ) } >
2018-11-23 07:04:42 +00:00
< SettingsToolbarConnector
{ ... otherProps }
/ >
2020-05-25 04:22:33 +00:00
< PageContentBody >
2018-11-23 07:04:42 +00:00
{
isFetching && ! isPopulated &&
< LoadingIndicator / >
}
{
! isFetching && error &&
2020-09-05 18:46:39 +00:00
< div >
{ translate ( 'UnableToLoadGeneralSettings' ) }
< / d i v >
2018-11-23 07:04:42 +00:00
}
{
hasSettings && isPopulated && ! error &&
< Form
id = "generalSettings"
{ ... otherProps }
>
< HostSettings
advancedSettings = { advancedSettings }
settings = { settings }
isWindows = { isWindows }
mode = { mode }
onInputChange = { onInputChange }
/ >
< SecuritySettings
settings = { settings }
isResettingApiKey = { isResettingApiKey }
onInputChange = { onInputChange }
onConfirmResetApiKey = { onConfirmResetApiKey }
/ >
< ProxySettings
settings = { settings }
onInputChange = { onInputChange }
/ >
< LoggingSettings
settings = { settings }
onInputChange = { onInputChange }
/ >
< AnalyticSettings
settings = { settings }
onInputChange = { onInputChange }
/ >
< UpdateSettings
advancedSettings = { advancedSettings }
settings = { settings }
2019-10-14 21:42:30 +00:00
isWindows = { isWindows }
2020-04-19 18:08:31 +00:00
packageUpdateMechanism = { packageUpdateMechanism }
2018-11-23 07:04:42 +00:00
onInputChange = { onInputChange }
/ >
< BackupSettings
advancedSettings = { advancedSettings }
settings = { settings }
onInputChange = { onInputChange }
/ >
< / F o r m >
}
2020-05-25 04:22:33 +00:00
< / P a g e C o n t e n t B o d y >
2018-11-23 07:04:42 +00:00
< ConfirmModal
isOpen = { this . state . isRestartRequiredModalOpen }
kind = { kinds . DANGER }
2020-08-29 03:56:13 +00:00
title = { translate ( 'RestartRadarr' ) }
2019-07-01 01:50:01 +00:00
message = {
` Radarr requires a restart to apply changes, do you want to restart now? ${ isWindowsService ? 'Depending which user is running the Radarr service you may need to restart Radarr as admin once before the service will start automatically.' : '' } `
}
2020-08-29 03:56:13 +00:00
cancelLabel = { translate ( 'IllRestartLater' ) }
confirmLabel = { translate ( 'RestartNow' ) }
2018-11-23 07:04:42 +00:00
onConfirm = { this . onConfirmRestart }
onCancel = { this . onCloseRestartRequiredModalOpen }
/ >
< / P a g e C o n t e n t >
) ;
}
}
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 ,
isWindows : PropTypes . bool . isRequired ,
2019-07-01 01:50:01 +00:00
isWindowsService : PropTypes . bool . isRequired ,
2018-11-23 07:04:42 +00:00
mode : PropTypes . string . isRequired ,
2020-04-19 18:12:44 +00:00
packageUpdateMechanism : PropTypes . string . isRequired ,
2018-11-23 07:04:42 +00:00
onInputChange : PropTypes . func . isRequired ,
onConfirmResetApiKey : PropTypes . func . isRequired ,
onConfirmRestart : PropTypes . func . isRequired
} ;
export default GeneralSettings ;