From be8ae7d60a00f2b1dc4754800ae9309777dbea2d Mon Sep 17 00:00:00 2001 From: Stas Vilchik Date: Mon, 12 Sep 2016 10:18:05 +0200 Subject: [PATCH] SONAR-5856 simplify saving of password fields --- .../main/js/apps/settings/components/Definition.js | 12 +++++------- .../settings/components/inputs/InputForPassword.js | 4 +++- .../src/main/js/apps/settings/store/actions.js | 8 ++++++++ 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/server/sonar-web/src/main/js/apps/settings/components/Definition.js b/server/sonar-web/src/main/js/apps/settings/components/Definition.js index 66b19fd023a..995b862d039 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/Definition.js +++ b/server/sonar-web/src/main/js/apps/settings/components/Definition.js @@ -30,6 +30,7 @@ import { resetValue, saveValue } from '../store/actions'; import { isLoading, getValidationMessage, getChangedValue } from '../store/rootReducer'; import { failValidation, passValidation } from '../store/settingsPage/validationMessages/actions'; import { cancelChange, changeValue } from '../store/settingsPage/changedValues/actions'; +import { TYPE_PASSWORD } from '../constants'; class Definition extends React.Component { static propTypes = { @@ -71,7 +72,10 @@ class Definition extends React.Component { handleChange (value) { clearTimeout(this.timeout); - return this.props.changeValue(this.props.setting.definition.key, value); + this.props.changeValue(this.props.setting.definition.key, value); + if (this.props.setting.definition.type === TYPE_PASSWORD) { + this.handleSave(); + } } handleReset () { @@ -90,12 +94,6 @@ class Definition extends React.Component { handleSave () { this.safeSetState({ success: false }); - const { definition } = this.props.setting; - if (isEmptyValue(definition, this.props.changedValue)) { - this.props.failValidation(definition.key, translate('settings.state.value_cant_be_empty')); - return; - } - const componentKey = this.props.component ? this.props.component.key : null; this.props.saveValue(this.props.setting.definition.key, componentKey).then(() => { this.safeSetState({ success: true }); diff --git a/server/sonar-web/src/main/js/apps/settings/components/inputs/InputForPassword.js b/server/sonar-web/src/main/js/apps/settings/components/inputs/InputForPassword.js index ddebb7563f8..1da04c7f4ba 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/inputs/InputForPassword.js +++ b/server/sonar-web/src/main/js/apps/settings/components/inputs/InputForPassword.js @@ -64,7 +64,9 @@ export default class InputForPassword extends React.Component { autoFocus={true} autoComplete={false} onChange={e => this.handleInputChange(e)}/> - + + + this.handleCancelChangeClick(e)}> {translate('cancel')} diff --git a/server/sonar-web/src/main/js/apps/settings/store/actions.js b/server/sonar-web/src/main/js/apps/settings/store/actions.js index 9df87830936..df6ed194049 100644 --- a/server/sonar-web/src/main/js/apps/settings/store/actions.js +++ b/server/sonar-web/src/main/js/apps/settings/store/actions.js @@ -26,6 +26,8 @@ import { addGlobalErrorMessage, closeAllGlobalMessages } from '../../../componen import { passValidation, failValidation } from './settingsPage/validationMessages/actions'; import { cancelChange } from './settingsPage/changedValues/actions'; import { getDefinition, getChangedValue } from './rootReducer'; +import { isEmptyValue } from '../utils'; +import { translate } from '../../../helpers/l10n'; export const fetchSettings = componentKey => dispatch => { return getDefinitions(componentKey) @@ -49,6 +51,12 @@ export const saveValue = (key, componentKey) => (dispatch, getState) => { const definition = getDefinition(state, key); const value = getChangedValue(state, key); + if (isEmptyValue(definition, value)) { + dispatch(failValidation(key, translate('settings.state.value_cant_be_empty'))); + dispatch(stopLoading(key)); + return Promise.reject(); + } + return setSettingValue(definition, value, componentKey) .then(() => getValues(key, componentKey)) .then(values => { -- 2.39.5