From 1209ca37476442602fd40e06a9636f470bd9385c Mon Sep 17 00:00:00 2001 From: Pascal Mugnier Date: Thu, 24 May 2018 09:32:40 +0200 Subject: [PATCH] Fix after review --- .../components/ConditionModal.tsx | 47 ++++++------------- .../components/ConditionOperator.tsx | 2 +- 2 files changed, 15 insertions(+), 34 deletions(-) diff --git a/server/sonar-web/src/main/js/apps/quality-gates/components/ConditionModal.tsx b/server/sonar-web/src/main/js/apps/quality-gates/components/ConditionModal.tsx index b5d8fbf5b89..cf70214b296 100644 --- a/server/sonar-web/src/main/js/apps/quality-gates/components/ConditionModal.tsx +++ b/server/sonar-web/src/main/js/apps/quality-gates/components/ConditionModal.tsx @@ -71,17 +71,6 @@ export default class ConditionModal extends React.PureComponent { this.mounted = false; } - handleError = (error: any) => { - parseError(error).then( - message => { - if (this.mounted) { - this.setState({ errorMessage: message }); - } - }, - () => {} - ); - }; - getUpdatedCondition = (metric: Metric) => { const data: Omit = { metric: metric.key, @@ -101,34 +90,26 @@ export default class ConditionModal extends React.PureComponent { return data; }; - handleConditionResponse = (newCondition: Condition) => { - this.props.onAddCondition(newCondition); - }; - handleFormSubmit = () => { if (this.state.metric) { const { condition, qualityGate, organization } = this.props; - + const newCondition = this.getUpdatedCondition(this.state.metric); + let submitPromise: Promise; if (condition) { - const data: Condition = { - id: condition.id, - ...this.getUpdatedCondition(this.state.metric) - }; - - return updateCondition({ organization, ...data }).then( - this.handleConditionResponse, - this.handleError - ); + submitPromise = updateCondition({ organization, id: condition.id, ...newCondition }); } else { - const data = this.getUpdatedCondition(this.state.metric); - - return createCondition({ gateId: qualityGate.id, organization, ...data }).then( - this.handleConditionResponse, - this.handleError - ); + submitPromise = createCondition({ gateId: qualityGate.id, organization, ...newCondition }); } + return submitPromise.then(this.props.onAddCondition, (error: any) => + parseError(error).then(message => { + if (this.mounted) { + this.setState({ errorMessage: message }); + } + return Promise.reject(message); + }) + ); } - return Promise.resolve(); + return Promise.reject('No metric selected'); }; handleChooseType = (metric: Metric) => { @@ -162,7 +143,7 @@ export default class ConditionModal extends React.PureComponent { onClose={onClose} onConfirm={this.handleFormSubmit}> {this.state.errorMessage && ( -
{this.state.errorMessage}
+
{this.state.errorMessage}
)}
diff --git a/server/sonar-web/src/main/js/apps/quality-gates/components/ConditionOperator.tsx b/server/sonar-web/src/main/js/apps/quality-gates/components/ConditionOperator.tsx index f75a1fe388b..526813bde06 100644 --- a/server/sonar-web/src/main/js/apps/quality-gates/components/ConditionOperator.tsx +++ b/server/sonar-web/src/main/js/apps/quality-gates/components/ConditionOperator.tsx @@ -58,7 +58,7 @@ export default class ConditionOperator extends React.PureComponent { return (