From b28f54a5076dfd1696b52abe347fbe2e1722940f Mon Sep 17 00:00:00 2001 From: Pascal Mugnier Date: Mon, 26 Mar 2018 09:34:26 +0200 Subject: [PATCH] SONAR-8217 Fix error spotted on review --- .../js/apps/settings/components/Definition.js | 22 +++++++++---------- .../settings/components/DefinitionChanges.js | 15 +++++++++---- .../src/main/js/apps/settings/utils.js | 8 +++---- 3 files changed, 25 insertions(+), 20 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 8ca93ac74ae..31169d527cb 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 @@ -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 && ( @@ -218,10 +215,13 @@ class Definition extends React.PureComponent { /> )} - {hasValueChanged && - !hasError && ( - - )} + {hasValueChanged && ( + + )} ); diff --git a/server/sonar-web/src/main/js/apps/settings/components/DefinitionChanges.js b/server/sonar-web/src/main/js/apps/settings/components/DefinitionChanges.js index e15bc661f49..a3eb663af9b 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/DefinitionChanges.js +++ b/server/sonar-web/src/main/js/apps/settings/components/DefinitionChanges.js @@ -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 (
- - + {this.props.enableSave && ( + + )}