diff --git a/app/javascript/react/screens/App/Settings/screens/GeneralSettings/GeneralSettings.js b/app/javascript/react/screens/App/Settings/screens/GeneralSettings/GeneralSettings.js index f96a7c47ca..866869544a 100644 --- a/app/javascript/react/screens/App/Settings/screens/GeneralSettings/GeneralSettings.js +++ b/app/javascript/react/screens/App/Settings/screens/GeneralSettings/GeneralSettings.js @@ -5,6 +5,8 @@ import { Form, Button, Icon, OverlayTrigger, Popover, Spinner } from 'patternfly import NumberInput from '../../../common/forms/NumberInput'; import TextInputWithCheckbox from '../../../common/forms/TextInputWithCheckbox'; +const FORM_NAME = 'settings'; + export class GeneralSettings extends React.Component { componentDidMount() { const { fetchServersAction, fetchServersUrl, fetchSettingsAction, fetchSettingsUrl } = this.props; @@ -17,6 +19,20 @@ export class GeneralSettings extends React.Component { patchSettingsAction(servers, settingsForm.values); }; + enforceConstraintsOnChange = (event, newValue, prevValue, fieldChanging) => { + const { + settingsForm: { + values: { max_concurrent_tasks_per_host, max_concurrent_tasks_per_ems } + }, + formChangeAction + } = this.props; + if (fieldChanging === 'max_concurrent_tasks_per_host' && newValue > max_concurrent_tasks_per_ems) { + formChangeAction(FORM_NAME, 'max_concurrent_tasks_per_ems', newValue); + } else if (fieldChanging === 'max_concurrent_tasks_per_ems' && newValue < max_concurrent_tasks_per_host) { + formChangeAction(FORM_NAME, 'max_concurrent_tasks_per_host', newValue); + } + }; + render() { const { isFetchingServers, isFetchingSettings, isSavingSettings, savedSettings, settingsForm } = this.props; @@ -71,6 +87,7 @@ export class GeneralSettings extends React.Component { component={NumberInput} normalize={NumberInput.normalizeStringToInt} min={1} + onChange={this.enforceConstraintsOnChange} /> @@ -85,10 +102,11 @@ export class GeneralSettings extends React.Component { component={NumberInput} normalize={NumberInput.normalizeStringToInt} min={1} + onChange={this.enforceConstraintsOnChange} /> -{/* FIXME: uncomment once backend is ready + {/* FIXME: uncomment once backend is ready

{__('Resource Utilization Limits for Migrations')}

@@ -141,7 +159,8 @@ GeneralSettings.propTypes = { savedSettings: PropTypes.object, settingsForm: PropTypes.object, fetchServersUrl: PropTypes.string, - fetchSettingsUrl: PropTypes.string + fetchSettingsUrl: PropTypes.string, + formChangeAction: PropTypes.func }; GeneralSettings.defaultProps = { @@ -150,5 +169,5 @@ GeneralSettings.defaultProps = { }; export default reduxForm({ - form: 'settings' + form: FORM_NAME })(GeneralSettings); diff --git a/app/javascript/react/screens/App/Settings/screens/GeneralSettings/index.js b/app/javascript/react/screens/App/Settings/screens/GeneralSettings/index.js index b4534df1b2..b664059942 100644 --- a/app/javascript/react/screens/App/Settings/screens/GeneralSettings/index.js +++ b/app/javascript/react/screens/App/Settings/screens/GeneralSettings/index.js @@ -1,8 +1,8 @@ import { connect } from 'react-redux'; +import { change } from 'redux-form'; import GeneralSettings from './GeneralSettings'; -import * as SettingsActions from '../../SettingsActions'; -import * as RouterActions from '../../../../../../redux/actions/routerActions'; +import { fetchServersAction, fetchSettingsAction, patchSettingsAction } from '../../SettingsActions'; const mapStateToProps = ({ settings, form }, ownProps) => ({ ...settings, @@ -17,6 +17,6 @@ const mergeProps = (stateProps, dispatchProps, ownProps) => Object.assign(stateP export default connect( mapStateToProps, - Object.assign(SettingsActions, RouterActions), + { fetchServersAction, fetchSettingsAction, patchSettingsAction, formChangeAction: change }, mergeProps )(GeneralSettings);