aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web/src/main/js/components/shared
diff options
context:
space:
mode:
authorStas Vilchik <vilchiks@gmail.com>2015-11-12 18:05:08 +0100
committerStas Vilchik <vilchiks@gmail.com>2015-11-13 14:25:00 +0100
commit27c49eda28940ca7600587b75fcbc9223268ee8b (patch)
treeb296526a4426370c20cff34aa55cc0097ee87d01 /server/sonar-web/src/main/js/components/shared
parent3348f196c986cfc9db1cfeb2a57ae847c2f4df63 (diff)
downloadsonarqube-27c49eda28940ca7600587b75fcbc9223268ee8b.tar.gz
sonarqube-27c49eda28940ca7600587b75fcbc9223268ee8b.zip
SONAR-6331 refactor overview code
Diffstat (limited to 'server/sonar-web/src/main/js/components/shared')
-rw-r--r--server/sonar-web/src/main/js/components/shared/drilldown-link.js91
-rw-r--r--server/sonar-web/src/main/js/components/shared/issues-link.js11
-rw-r--r--server/sonar-web/src/main/js/components/shared/quality-gate-link.js9
-rw-r--r--server/sonar-web/src/main/js/components/shared/quality-profile-link.js9
-rw-r--r--server/sonar-web/src/main/js/components/shared/rating.js15
5 files changed, 135 insertions, 0 deletions
diff --git a/server/sonar-web/src/main/js/components/shared/drilldown-link.js b/server/sonar-web/src/main/js/components/shared/drilldown-link.js
new file mode 100644
index 00000000000..d149a3db83c
--- /dev/null
+++ b/server/sonar-web/src/main/js/components/shared/drilldown-link.js
@@ -0,0 +1,91 @@
+import _ from 'underscore';
+import moment from 'moment';
+import React from 'react';
+
+import { IssuesLink } from './issues-link';
+import { getComponentDrilldownUrl } from '../../helpers/urls';
+
+
+const ISSUE_MEASURES = [
+ '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'
+];
+
+
+export const DrilldownLink = React.createClass({
+ isIssueMeasure() {
+ return ISSUE_MEASURES.indexOf(this.props.metric) !== -1;
+ },
+
+ propsToIssueParams() {
+ let params = {};
+ if (this.props.periodDate) {
+ params.createdAfter = moment(this.props.periodDate).format('YYYY-MM-DDTHH:mm:ssZZ');
+ }
+ switch (this.props.metric) {
+ case 'blocker_violations':
+ case 'new_blocker_violations':
+ _.extend(params, { resolved: 'false', severities: 'BLOCKER' });
+ break;
+ case 'critical_violations':
+ case 'new_critical_violations':
+ _.extend(params, { resolved: 'false', severities: 'CRITICAL' });
+ break;
+ case 'major_violations':
+ case 'new_major_violations':
+ _.extend(params, { resolved: 'false', severities: 'MAJOR' });
+ break;
+ case 'minor_violations':
+ case 'new_minor_violations':
+ _.extend(params, { resolved: 'false', severities: 'MINOR' });
+ break;
+ case 'info_violations':
+ case 'new_info_violations':
+ _.extend(params, { resolved: 'false', severities: 'INFO' });
+ break;
+ case 'open_issues':
+ _.extend(params, { resolved: 'false', statuses: 'OPEN' });
+ break;
+ case 'reopened_issues':
+ _.extend(params, { resolved: 'false', statuses: 'REOPENED' });
+ break;
+ case 'confirmed_issues':
+ _.extend(params, { resolved: 'false', statuses: 'CONFIRMED' });
+ break;
+ case 'false_positive_issues':
+ _.extend(params, { resolutions: 'FALSE-POSITIVE' });
+ break;
+ default:
+ _.extend(params, { resolved: 'false' });
+ }
+ return params;
+ },
+
+ renderIssuesLink() {
+ return <IssuesLink component={this.props.component} params={this.propsToIssueParams()}>
+ {this.props.children}
+ </IssuesLink>;
+ },
+
+ render() {
+ if (this.isIssueMeasure()) {
+ return this.renderIssuesLink();
+ }
+
+ let url = getComponentDrilldownUrl(this.props.component, this.props.metric, this.props.period);
+ return <a className={this.props.className} href={url}>{this.props.children}</a>;
+ }
+});
diff --git a/server/sonar-web/src/main/js/components/shared/issues-link.js b/server/sonar-web/src/main/js/components/shared/issues-link.js
new file mode 100644
index 00000000000..230ead7c83b
--- /dev/null
+++ b/server/sonar-web/src/main/js/components/shared/issues-link.js
@@ -0,0 +1,11 @@
+import React from 'react';
+
+import { getComponentIssuesUrl } from '../../helpers/urls';
+
+
+export const IssuesLink = React.createClass({
+ render() {
+ let url = getComponentIssuesUrl(this.props.component, this.props.params);
+ return <a className={this.props.className} href={url}>{this.props.children}</a>;
+ }
+});
diff --git a/server/sonar-web/src/main/js/components/shared/quality-gate-link.js b/server/sonar-web/src/main/js/components/shared/quality-gate-link.js
new file mode 100644
index 00000000000..5b05c8cd4af
--- /dev/null
+++ b/server/sonar-web/src/main/js/components/shared/quality-gate-link.js
@@ -0,0 +1,9 @@
+import React from 'react';
+
+
+export const QualityGateLink = React.createClass({
+ render() {
+ let url = `${baseUrl}/quality_gates/show/${this.props.gate}`;
+ return <a href={url}>{this.props.children}</a>;
+ }
+});
diff --git a/server/sonar-web/src/main/js/components/shared/quality-profile-link.js b/server/sonar-web/src/main/js/components/shared/quality-profile-link.js
new file mode 100644
index 00000000000..c7c296bce47
--- /dev/null
+++ b/server/sonar-web/src/main/js/components/shared/quality-profile-link.js
@@ -0,0 +1,9 @@
+import React from 'react';
+
+
+export const QualityProfileLink = React.createClass({
+ render() {
+ let url = `${baseUrl}/profiles/show?key=${encodeURIComponent(this.props.profile)}`;
+ return <a href={url}>{this.props.children}</a>;
+ }
+});
diff --git a/server/sonar-web/src/main/js/components/shared/rating.js b/server/sonar-web/src/main/js/components/shared/rating.js
new file mode 100644
index 00000000000..791466fdfc4
--- /dev/null
+++ b/server/sonar-web/src/main/js/components/shared/rating.js
@@ -0,0 +1,15 @@
+import React from 'react';
+
+import { formatMeasure } from '../../helpers/measures';
+
+
+export const Rating = React.createClass({
+ render() {
+ if (this.props.value == null || isNaN(this.props.value)) {
+ return null;
+ }
+ let formatted = formatMeasure(this.props.value, 'RATING');
+ let className = 'rating rating-' + formatted;
+ return <span className={className}>{formatted}</span>;
+ }
+});