]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-8217 Fix error spotted on review
authorPascal Mugnier <pascal.mugnier@sonarsource.com>
Mon, 26 Mar 2018 07:34:26 +0000 (09:34 +0200)
committerSonarTech <sonartech@sonarsource.com>
Thu, 29 Mar 2018 18:20:46 +0000 (20:20 +0200)
server/sonar-web/src/main/js/apps/settings/components/Definition.js
server/sonar-web/src/main/js/apps/settings/components/DefinitionChanges.js
server/sonar-web/src/main/js/apps/settings/utils.js

index 8ca93ac74aef4bd51facba937a9a7550733d5a00..31169d527cb308433bb5b22e5eb26220206551ac 100644 (file)
@@ -97,7 +97,7 @@ class Definition extends React.PureComponent {
     return this.props
       .resetValue(definition.key, componentKey)
       .then(() => {
-        this.props.changeValue(definition.key, definition.defaultValue);
+        this.props.cancelChange(definition.key, componentKey);
         this.safeSetState({ success: true, hasError: false });
         this.timeout = setTimeout(() => this.safeSetState({ success: false }), 3000);
       })
@@ -113,13 +113,9 @@ class Definition extends React.PureComponent {
   };
 
   handleCheck = () => {
-    this.safeSetState({ success: false });
     const componentKey = this.props.component ? this.props.component.key : null;
-    if (this.props.checkValue(this.props.setting.definition.key, componentKey)) {
-      this.safeSetState({ hasError: false });
-    } else {
-      this.safeSetState({ hasError: true });
-    }
+    const hasError = !this.props.checkValue(this.props.setting.definition.key, componentKey);
+    this.safeSetState({ hasError });
   };
 
   handleSave = () => {
@@ -194,6 +190,7 @@ class Definition extends React.PureComponent {
               )}
 
             {!loading &&
+              this.props.validationMessage == null &&
               this.state.success && (
                 <span className="text-success">
                   <AlertSuccessIcon className="spacer-right" />
@@ -218,10 +215,13 @@ class Definition extends React.PureComponent {
             />
           )}
 
-          {hasValueChanged &&
-            !hasError && (
-              <DefinitionChanges onCancel={this.handleCancel} onSave={this.handleSave} />
-            )}
+          {hasValueChanged && (
+            <DefinitionChanges
+              enableSave={!hasError}
+              onCancel={this.handleCancel}
+              onSave={this.handleSave}
+            />
+          )}
         </div>
       </div>
     );
index e15bc661f49f07754de2fb3e3d1c82413c6370f4..a3eb663af9b110e7ff2031958cf36e2cd625444a 100644 (file)
@@ -22,6 +22,12 @@ import React from 'react';
 import PropTypes from 'prop-types';
 import { translate } from '../../../helpers/l10n';
 
+/*::
+type Props = {
+  enableSave: boolean
+};
+*/
+
 export default class DefinitionChanges extends React.PureComponent {
   static propTypes = {
     onSave: PropTypes.func.isRequired,
@@ -43,10 +49,11 @@ export default class DefinitionChanges extends React.PureComponent {
   render() {
     return (
       <div className="settings-definition-changes">
-        <button className="js-save-changes button-success" onClick={e => this.handleSaveClick(e)}>
-          {translate('save')}
-        </button>
-
+        {this.props.enableSave && (
+          <button className="js-save-changes button-success" onClick={e => this.handleSaveClick(e)}>
+            {translate('save')}
+          </button>
+        )}
         <button
           className="js-cancel-changes big-spacer-left button-link"
           onClick={e => this.handleCancelChange(e)}>
index ffd8107f6598a7ddd5a42c8220132d8ecd8f339d..b7aa3a8e34a3807f2191553886a7fb0b92c67fd7 100644 (file)
@@ -117,12 +117,10 @@ function getParentValue(setting) {
 export function getDefaultValue(setting) {
   const parentValue = getParentValue(setting);
 
-  if (parentValue === undefined) {
-    return setting.value;
-  }
-
   if (parentValue == null) {
-    return translate('settings.default.no_value');
+    return setting.definition.defaultValue
+      ? setting.definition.defaultValue
+      : translate('settings.default.no_value');
   }
 
   if (setting.definition.multiValues) {