aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web/src/main/js/apps/overview/main/coverage.js
blob: eb0422c4bcb362d786a1d5ee7313af077abb7dd5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import React from 'react';

import { Domain, DomainHeader, DomainPanel, DomainNutshell, DomainLeak, MeasuresList, Measure, DomainMixin } from './components';
import { DrilldownLink } from '../../../components/shared/drilldown-link';
import { TooltipsMixin } from '../../../components/mixins/tooltips-mixin';
import { getMetricName } from '../helpers/metrics';
import { formatMeasure } from '../../../helpers/measures';


export const GeneralCoverage = React.createClass({
  mixins: [TooltipsMixin, DomainMixin],

  propTypes: {
    measures: React.PropTypes.object.isRequired,
    leakPeriodLabel: React.PropTypes.string,
    leakPeriodDate: React.PropTypes.object
  },

  getCoverageMetric () {
    if (this.props.measures['overall_coverage'] != null) {
      return 'overall_coverage';
    } else if (this.props.measures['coverage'] != null) {
      return 'coverage';
    } else {
      return 'it_coverage';
    }
  },

  getNewCoverageMetric () {
    if (this.props.leak['new_overall_coverage'] != null) {
      return 'new_overall_coverage';
    } else if (this.props.leak['new_coverage'] != null) {
      return 'new_coverage';
    } else {
      return 'new_it_coverage';
    }
  },

  renderNewCoverage () {
    let newCoverageMetric = this.getNewCoverageMetric();

    // FIXME fix period index
    if (this.props.leak[newCoverageMetric] != null) {
      return <DrilldownLink component={this.props.component.key} metric={newCoverageMetric} period="1">
        <span className="js-overview-main-new-coverage">
          {formatMeasure(this.props.leak[newCoverageMetric], 'PERCENT')}
        </span>
      </DrilldownLink>;
    } else {
      return <span></span>;
    }
  },

  renderLeak () {
    if (!this.hasLeakPeriod()) {
      return null;
    }

    return <DomainLeak>
      <MeasuresList>
        <Measure label={getMetricName('new_coverage')}>{this.renderNewCoverage()}</Measure>
      </MeasuresList>
      {this.renderTimeline('after')}
    </DomainLeak>;
  },

  render () {
    let coverageMetric = this.getCoverageMetric();
    if (this.props.measures[coverageMetric] == null) {
      return null;
    }

    return <Domain>
      <DomainHeader title="Coverage" linkTo="/tests"/>

      <DomainPanel domain="coverage">
        <DomainNutshell>
          <MeasuresList>
            <Measure label={getMetricName('coverage')}>
              <DrilldownLink component={this.props.component.key} metric={coverageMetric}>
                <span className="js-overview-main-coverage">
                  {formatMeasure(this.props.measures[coverageMetric], 'PERCENT')}
                </span>
              </DrilldownLink>
            </Measure>
            <Measure label={getMetricName('tests')}>
              <DrilldownLink component={this.props.component.key} metric="tests">
                <span className="js-overview-main-tests">
                  {formatMeasure(this.props.measures['tests'], 'SHORT_INT')}
                </span>
              </DrilldownLink>
            </Measure>
          </MeasuresList>
          {this.renderTimeline('before')}
        </DomainNutshell>
        {this.renderLeak()}
      </DomainPanel>
    </Domain>;
  }
});