aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web/src/main/js/components/shared/drilldown-link.js
blob: 13b0afeb0c33b4cc9f8dbf5741141fde4cb07f8a (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
/*
 * SonarQube
 * Copyright (C) 2009-2017 SonarSource SA
 * mailto:info AT sonarsource DOT com
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 3 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */
import React from 'react';
import PropTypes from 'prop-types';
import { Link } from 'react-router';
import { getComponentDrilldownUrl, getComponentIssuesUrl } from '../../helpers/urls';

const ISSUE_MEASURES = [
  'violations',
  'new_violations',
  'blocker_violations',
  'critical_violations',
  'major_violations',
  'minor_violations',
  'info_violations',
  'new_blocker_violations',
  'new_critical_violations',
  'new_major_violations',
  'new_minor_violations',
  'new_info_violations',
  'open_issues',
  'reopened_issues',
  'confirmed_issues',
  'false_positive_issues',
  'code_smells',
  'new_code_smells',
  'bugs',
  'new_bugs',
  'vulnerabilities',
  'new_vulnerabilities'
];

export class DrilldownLink extends React.PureComponent {
  static propTypes = {
    children: PropTypes.oneOfType([PropTypes.node, PropTypes.arrayOf(PropTypes.node)]),
    className: PropTypes.string,
    component: PropTypes.string.isRequired,
    metric: PropTypes.string.isRequired,
    sinceLeakPeriod: PropTypes.bool
  };
  isIssueMeasure = () => {
    return ISSUE_MEASURES.indexOf(this.props.metric) !== -1;
  };

  propsToIssueParams = () => {
    const params = {};

    if (this.props.sinceLeakPeriod) {
      params.sinceLeakPeriod = true;
    }

    switch (this.props.metric) {
      case 'blocker_violations':
      case 'new_blocker_violations':
        Object.assign(params, { resolved: 'false', severities: 'BLOCKER' });
        break;
      case 'critical_violations':
      case 'new_critical_violations':
        Object.assign(params, { resolved: 'false', severities: 'CRITICAL' });
        break;
      case 'major_violations':
      case 'new_major_violations':
        Object.assign(params, { resolved: 'false', severities: 'MAJOR' });
        break;
      case 'minor_violations':
      case 'new_minor_violations':
        Object.assign(params, { resolved: 'false', severities: 'MINOR' });
        break;
      case 'info_violations':
      case 'new_info_violations':
        Object.assign(params, { resolved: 'false', severities: 'INFO' });
        break;
      case 'open_issues':
        Object.assign(params, { resolved: 'false', statuses: 'OPEN' });
        break;
      case 'reopened_issues':
        Object.assign(params, { resolved: 'false', statuses: 'REOPENED' });
        break;
      case 'confirmed_issues':
        Object.assign(params, { resolved: 'false', statuses: 'CONFIRMED' });
        break;
      case 'false_positive_issues':
        Object.assign(params, { resolutions: 'FALSE-POSITIVE' });
        break;
      case 'code_smells':
      case 'new_code_smells':
        Object.assign(params, { resolved: 'false', types: 'CODE_SMELL' });
        break;
      case 'bugs':
      case 'new_bugs':
        Object.assign(params, { resolved: 'false', types: 'BUG' });
        break;
      case 'vulnerabilities':
      case 'new_vulnerabilities':
        Object.assign(params, { resolved: 'false', types: 'VULNERABILITY' });
        break;
      default:
        Object.assign(params, { resolved: 'false' });
    }
    return params;
  };

  renderIssuesLink = () => {
    const url = getComponentIssuesUrl(this.props.component, this.propsToIssueParams());

    return (
      <Link to={url} className={this.props.className}>
        {this.props.children}
      </Link>
    );
  };

  render() {
    if (this.isIssueMeasure()) {
      return this.renderIssuesLink();
    }

    const url = getComponentDrilldownUrl(this.props.component, this.props.metric);
    return (
      <Link to={url} className={this.props.className}>
        {this.props.children}
      </Link>
    );
  }
}