From 8d0ec033969eaf7fb0e9672816ce6a85a9a301f0 Mon Sep 17 00:00:00 2001 From: Stas Vilchik Date: Wed, 25 May 2016 16:44:48 +0200 Subject: [PATCH] fix unwanted WS call when QG is green --- .../qualityGate/QualityGateConditions.js | 47 ++++++++++--------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/server/sonar-web/src/main/js/apps/overview/qualityGate/QualityGateConditions.js b/server/sonar-web/src/main/js/apps/overview/qualityGate/QualityGateConditions.js index d48614ce09d..b3ed4fac498 100644 --- a/server/sonar-web/src/main/js/apps/overview/qualityGate/QualityGateConditions.js +++ b/server/sonar-web/src/main/js/apps/overview/qualityGate/QualityGateConditions.js @@ -47,17 +47,17 @@ export default class QualityGateConditions extends React.Component { componentDidMount () { this.mounted = true; - this.loadFailedMeasures(this.props); + this.loadFailedMeasures(); } shouldComponentUpdate (nextProps, nextState) { return shallowCompare(this, nextProps, nextState); } - componentDidUpdate (nextProps) { - if (nextProps.conditions !== this.props.conditions || - nextProps.component !== this.props.component) { - this.loadFailedMeasures(nextProps); + componentDidUpdate (prevProps) { + if (prevProps.conditions !== this.props.conditions || + prevProps.component !== this.props.component) { + this.loadFailedMeasures(); } } @@ -65,24 +65,27 @@ export default class QualityGateConditions extends React.Component { this.mounted = false; } - loadFailedMeasures (props) { - const { component, conditions } = props; + loadFailedMeasures () { + const { component, conditions } = this.props; const failedConditions = conditions.filter(c => c.level !== 'OK'); - const metrics = failedConditions.map(condition => condition.metric); - - getMeasuresAndMeta( - component.key, - metrics, - { additionalFields: 'metrics' } - ).then(r => { - if (this.mounted) { - const measures = enhanceMeasuresWithMetrics(r.component.measures, r.metrics); - this.setState({ - conditions: enhanceConditions(failedConditions, measures), - loading: false - }); - } - }); + if (failedConditions.length > 0) { + const metrics = failedConditions.map(condition => condition.metric); + getMeasuresAndMeta( + component.key, + metrics, + { additionalFields: 'metrics' } + ).then(r => { + if (this.mounted) { + const measures = enhanceMeasuresWithMetrics(r.component.measures, r.metrics); + this.setState({ + conditions: enhanceConditions(failedConditions, measures), + loading: false + }); + } + }); + } else { + this.setState({ loading: false }); + } } render () { -- 2.39.5