]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5856 simplify saving of password fields
authorStas Vilchik <vilchiks@gmail.com>
Mon, 12 Sep 2016 08:18:05 +0000 (10:18 +0200)
committerStas Vilchik <vilchiks@gmail.com>
Mon, 12 Sep 2016 10:06:29 +0000 (12:06 +0200)
server/sonar-web/src/main/js/apps/settings/components/Definition.js
server/sonar-web/src/main/js/apps/settings/components/inputs/InputForPassword.js
server/sonar-web/src/main/js/apps/settings/store/actions.js

index 66b19fd023ae256814f8acabdde12649ba93a40e..995b862d03998822c8935d559291b84121a16b98 100644 (file)
@@ -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 });
index ddebb7563f897ee9e4d920026bb35aa9df56b3a6..1da04c7f4ba87b361144a60e9c756834c7595a92 100644 (file)
@@ -64,7 +64,9 @@ export default class InputForPassword extends React.Component {
                 autoFocus={true}
                 autoComplete={false}
                 onChange={e => this.handleInputChange(e)}/>
-            <button className="spacer-left">{translate('set')}</button>
+
+            <button className="spacer-left button-success">{translate('save')}</button>
+
             <a className="spacer-left" href="#" onClick={e => this.handleCancelChangeClick(e)}>
               {translate('cancel')}
             </a>
index 9df87830936469b344543d138a5def8b06e6ce2d..df6ed194049f9689c2703b5cdd97786348c9cf98 100644 (file)
@@ -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 => {