aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web/src/main/js/apps/overview/domains/debt-domain.js
blob: 179520a106fcfcc0ee44902112a4160b66a8662a (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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
import _ from 'underscore';
import d3 from 'd3';
import React from 'react';

import { getMeasuresAndVariations } from '../../../api/measures';
import { DetailedMeasure } from '../components/detailed-measure';
import { DomainTimeline } from '../components/domain-timeline';
import { DomainTreemap } from '../components/domain-treemap';
import { DomainBubbleChart } from '../components/domain-bubble-chart';
import { getPeriodLabel, getPeriodDate } from './../helpers/periods';
import { TooltipsMixin } from '../../../components/mixins/tooltips-mixin';
import { filterMetrics, filterMetricsForDomains } from '../helpers/metrics';
import { CHART_COLORS_RANGE_PERCENT } from '../../../helpers/constants';
import { AddedRemovedMeasure, AddedRemovedDebt, OnNewCodeMeasure, SeverityMeasure } from './../components/issue-measure';
import { IssuesTags } from './../components/issues-tags';
import Assignees from './../components/issues-assignees';
import { getFacet, extractAssignees } from '../../../api/issues';
import { Rating } from '../../../components/shared/rating';
import { DrilldownLink } from '../../../components/shared/drilldown-link';
import { DomainLeakTitle } from '../main/components';


const KNOWN_METRICS = ['violations', 'sqale_index', 'sqale_rating', 'sqale_debt_ratio', 'blocker_violations',
  'critical_violations', 'major_violations', 'minor_violations', 'info_violations', 'confirmed_issues'];


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

  getInitialState() {
    return {
      ready: false,
      leakPeriodLabel: getPeriodLabel(this.props.component.periods, this.props.leakPeriodIndex),
      leakPeriodDate: getPeriodDate(this.props.component.periods, this.props.leakPeriodIndex)
    };
  },

  componentDidMount() {
    Promise.all([
      this.requestMeasures(),
      this.requestIssues(),
      this.requestAssignees()
    ]).then(responses => {
      let measures = this.getMeasuresValues(responses[0], 'value');
      let leak = this.getMeasuresValues(responses[0], 'var' + this.props.leakPeriodIndex);
      let tags = responses[1].facet;
      let assignees = extractAssignees(responses[2].facet, responses[2].response);
      this.setState({ ready: true, measures, leak, tags, assignees });
    });
  },

  getMeasuresValues (measures, fieldKey) {
    let values = {};
    Object.keys(measures).forEach(measureKey => {
      values[measureKey] = measures[measureKey][fieldKey];
    });
    return values;
  },

  getMetricsForDomain() {
    return this.props.metrics
        .filter(metric => ['Issues', 'Technical Debt'].indexOf(metric.domain) !== -1)
        .map(metric => metric.key);
  },

  getMetricsForTimeline() {
    return filterMetricsForDomains(this.props.metrics, ['Issues', 'Technical Debt']);
  },

  getAllMetricsForTimeline() {
    return filterMetrics(this.props.metrics);
  },

  requestMeasures () {
    return getMeasuresAndVariations(this.props.component.key, this.getMetricsForDomain());
  },

  getFacet (facets, facetKey) {
    return _.findWhere(facets, { property: facetKey }).values;
  },

  requestIssues () {
    return getFacet({
      componentUuids: this.props.component.id,
      resolved: 'false'
    }, 'tags');
  },

  requestAssignees () {
    return getFacet({
      componentUuids: this.props.component.id,
      resolved: 'false',
      statuses: 'OPEN,REOPENED'
    }, 'assignees');
  },

  renderLoading () {
    return <div className="text-center">
      <i className="spinner spinner-margin"/>
    </div>;
  },

  renderLegend () {
    return <DomainLeakTitle inline={true} label={this.state.leakPeriodLabel} date={this.state.leakPeriodDate}/>;
  },

  renderOtherMeasures() {
    let metrics = filterMetricsForDomains(this.props.metrics, ['Issues', 'Technical Debt'])
        .filter(metric => KNOWN_METRICS.indexOf(metric.key) === -1)
        .filter(metric => this.state.measures[metric.key] != null)
        .map(metric => {
          return <DetailedMeasure key={metric.key} {...this.props} {...this.state} metric={metric.key}
                                  type={metric.type}/>;
        });
    if (!metrics.length) {
      return null;
    }
    return <div className="overview-detailed-measures-list">{metrics}</div>;
  },

  renderRating () {
    if (this.state.measures['sqale_rating'] == null) {
      return null;
    }
    return <div className="overview-detailed-measure overview-detailed-measure-rating">
      <div className="overview-detailed-measure-nutshell">
        <span className="overview-detailed-measure-value">
          <DrilldownLink component={this.props.component.key} metric="sqale_rating">
            <Rating value={this.state.measures['sqale_rating']}/>
          </DrilldownLink>
        </span>
      </div>
    </div>;
  },

  renderTags () {
    if (!this.state.tags.length) {
      return null;
    }
    return <div className="overview-detailed-measure">
      <div className="overview-detailed-measure-nutshell">
        <IssuesTags {...this.props} tags={this.state.tags}/>
      </div>
    </div>;
  },

  render () {
    if (!this.state.ready) {
      return this.renderLoading();
    }

    let treemapScale = d3.scale.ordinal()
        .domain([1, 2, 3, 4, 5])
        .range(CHART_COLORS_RANGE_PERCENT);

    return <div className="overview-detailed-page">
      <div className="overview-cards-list">
        <div className="overview-card overview-card-fixed-width">
          <div className="overview-card-header">
            <div className="overview-title">{window.t('overview.domain.debt')}</div>
            {this.renderLegend()}
          </div>

          <div className="overview-detailed-measures-list overview-detailed-measures-list-inline">
            {this.renderRating()}
            <AddedRemovedDebt {...this.props} {...this.state}
                metric="sqale_index" leakMetric="new_technical_debt" type="WORK_DUR"/>
            <OnNewCodeMeasure {...this.props} {...this.state}
                metric="sqale_debt_ratio" leakMetric="new_sqale_debt_ratio" type="PERCENT"/>
            <AddedRemovedMeasure {...this.props} {...this.state}
                metric="violations" leakMetric="new_violations" type="INT"/>
          </div>

          <div className="overview-detailed-measures-list overview-detailed-measures-list-inline">
            <SeverityMeasure {...this.props} {...this.state} severity="BLOCKER"/>
            <SeverityMeasure {...this.props} {...this.state} severity="CRITICAL"/>
            <SeverityMeasure {...this.props} {...this.state} severity="MAJOR"/>
            <SeverityMeasure {...this.props} {...this.state} severity="MINOR"/>
            <SeverityMeasure {...this.props} {...this.state} severity="INFO"/>
          </div>

          <div className="overview-detailed-measures-list overview-detailed-measures-list-inline">
            {this.renderTags()}
            <div className="overview-detailed-measure">
              <div className="overview-detailed-measure-nutshell">
                <div className="overview-detailed-measure-name">
                  {window.t('overview.unmanaged_issues')}
                </div>
                <div className="spacer-top">
                  <Assignees {...this.props} assignees={this.state.assignees}/>
                </div>
              </div>
            </div>
          </div>

          {this.renderOtherMeasures()}
        </div>

        <div className="overview-card">
          <DomainBubbleChart {...this.props}
              xMetric="violations"
              yMetric="sqale_index"
              sizeMetrics={['blocker_violations', 'critical_violations']}/>
        </div>
      </div>

      <div className="overview-cards-list">
        <div className="overview-card">
          <DomainTimeline {...this.props} {...this.state}
              initialMetric="sqale_index"
              metrics={this.getMetricsForTimeline()}
              allMetrics={this.getAllMetricsForTimeline()}/>
        </div>
        <div className="overview-card">
          <DomainTreemap {...this.props}
              sizeMetric="ncloc"
              colorMetric="sqale_rating"
              scale={treemapScale}/>
        </div>
      </div>
    </div>;

  }
});