aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStas Vilchik <vilchiks@gmail.com>2016-11-03 15:18:49 +0100
committerStas Vilchik <vilchiks@gmail.com>2016-11-04 09:08:46 +0100
commit5da9428b75d2e351c7a9d075e2c2ee4a8c101548 (patch)
tree854931a6969c913e4d674506fc8ce001f3c49412
parenta0f3074ca966632ab5b9fac224c114a7f410e3e2 (diff)
downloadsonarqube-5da9428b75d2e351c7a9d075e2c2ee4a8c101548.tar.gz
sonarqube-5da9428b75d2e351c7a9d075e2c2ee4a8c101548.zip
SONAR-8300 display cumulative facets
-rw-r--r--server/sonar-web/src/main/js/apps/projects/filters/CoverageFilter.js4
-rw-r--r--server/sonar-web/src/main/js/apps/projects/filters/IssuesFilter.js3
-rw-r--r--server/sonar-web/src/main/js/apps/projects/store/facets/reducer.js32
-rw-r--r--server/sonar-web/src/main/js/apps/projects/store/utils.js36
-rw-r--r--server/sonar-web/src/main/js/helpers/ratings.js8
5 files changed, 62 insertions, 21 deletions
diff --git a/server/sonar-web/src/main/js/apps/projects/filters/CoverageFilter.js b/server/sonar-web/src/main/js/apps/projects/filters/CoverageFilter.js
index 5ac1adec4c3..0a9f3434166 100644
--- a/server/sonar-web/src/main/js/apps/projects/filters/CoverageFilter.js
+++ b/server/sonar-web/src/main/js/apps/projects/filters/CoverageFilter.js
@@ -35,7 +35,7 @@ export default class CoverageFilter extends React.Component {
};
getFacetValueForOption = (facet, option) => {
- const map = ['*-30.0', '30.0-50.0', '50.0-70.0', '70.0-80.0', '80.0-*'];
+ const map = ['80.0-*', '70.0-80.0', '50.0-70.0', '30.0-50.0', '*-30.0'];
return facet[map[option - 1]];
};
@@ -43,7 +43,7 @@ export default class CoverageFilter extends React.Component {
return (
<FilterContainer
property="coverage"
- options={[5, 4, 3, 2, 1]}
+ options={[1, 2, 3, 4, 5]}
renderName={() => 'Coverage'}
renderOption={this.renderOption}
getFacetValueForOption={this.getFacetValueForOption}
diff --git a/server/sonar-web/src/main/js/apps/projects/filters/IssuesFilter.js b/server/sonar-web/src/main/js/apps/projects/filters/IssuesFilter.js
index c24f6654b53..c955ae24906 100644
--- a/server/sonar-web/src/main/js/apps/projects/filters/IssuesFilter.js
+++ b/server/sonar-web/src/main/js/apps/projects/filters/IssuesFilter.js
@@ -26,6 +26,9 @@ export default class IssuesFilter extends React.Component {
return (
<span>
<Rating value={option} small={true}/>
+ {option > 1 && option < 5 && (
+ <span className="note spacer-left">and worse</span>
+ )}
</span>
);
};
diff --git a/server/sonar-web/src/main/js/apps/projects/store/facets/reducer.js b/server/sonar-web/src/main/js/apps/projects/store/facets/reducer.js
index 4da4c0e9fd3..802e8d36edd 100644
--- a/server/sonar-web/src/main/js/apps/projects/store/facets/reducer.js
+++ b/server/sonar-web/src/main/js/apps/projects/store/facets/reducer.js
@@ -18,10 +18,24 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
import flatMap from 'lodash/flatMap';
+import sumBy from 'lodash/sumBy';
import { createMap } from '../../../../components/store/generalReducers';
import { RECEIVE_PROJECTS } from '../projects/actions';
import { mapMetricToProperty } from '../utils';
+const CUMULATIVE_FACETS = [
+ 'reliability',
+ 'security',
+ 'maintainability',
+ 'coverage',
+ 'duplications',
+ 'size'
+];
+
+const REVERSED_FACETS = [
+ 'coverage'
+];
+
const mapFacetValues = values => {
const map = {};
values.forEach(value => {
@@ -30,11 +44,27 @@ const mapFacetValues = values => {
return map;
};
+const cumulativeMapFacetValues = values => {
+ const map = {};
+ let sum = sumBy(values, value => value.count);
+ values.forEach((value, index) => {
+ map[value.val] = index > 0 && index < values.length - 1 ? sum : value.count;
+ sum -= value.count;
+ });
+ return map;
+};
+
const getFacetsMap = facets => {
const map = {};
facets.forEach(facet => {
const property = mapMetricToProperty(facet.property);
- map[property] = mapFacetValues(facet.values);
+ const { values } = facet;
+ if (REVERSED_FACETS.includes(property)) {
+ values.reverse();
+ }
+ map[property] = CUMULATIVE_FACETS.includes(property) ?
+ cumulativeMapFacetValues(values) :
+ mapFacetValues(values);
});
return map;
};
diff --git a/server/sonar-web/src/main/js/apps/projects/store/utils.js b/server/sonar-web/src/main/js/apps/projects/store/utils.js
index ac937893b18..d2422b8ee85 100644
--- a/server/sonar-web/src/main/js/apps/projects/store/utils.js
+++ b/server/sonar-web/src/main/js/apps/projects/store/utils.js
@@ -42,18 +42,26 @@ export const parseUrlQuery = urlQuery => ({
'size': getAsNumericRating(urlQuery['size']),
});
+const convertIssuesRating = (metric, rating) => {
+ if (rating > 1 && rating < 5) {
+ return `${metric} >= ${rating}`;
+ } else {
+ return `${metric} = ${rating}`;
+ }
+};
+
const convertCoverage = coverage => {
switch (coverage) {
case 1:
- return 'coverage < 30';
+ return 'coverage >= 80';
case 2:
- return 'coverage >= 30 and coverage < 50';
+ return 'coverage < 80';
case 3:
- return 'coverage >= 50 and coverage < 70';
+ return 'coverage < 70';
case 4:
- return 'coverage >= 70 and coverage < 80';
+ return 'coverage < 50';
case 5:
- return 'coverage >= 80';
+ return 'coverage < 30';
default:
return '';
}
@@ -64,11 +72,11 @@ const convertDuplications = duplications => {
case 1:
return 'duplicated_lines_density < 3';
case 2:
- return 'duplicated_lines_density >= 3 and duplicated_lines_density < 5';
+ return 'duplicated_lines_density >= 3';
case 3:
- return 'duplicated_lines_density >= 5 and duplicated_lines_density < 10';
+ return 'duplicated_lines_density >= 5';
case 4:
- return 'duplicated_lines_density >= 10 duplicated_lines_density < 20';
+ return 'duplicated_lines_density >= 10';
case 5:
return 'duplicated_lines_density >= 20';
default:
@@ -81,11 +89,11 @@ const convertSize = size => {
case 1:
return 'ncloc < 1000';
case 2:
- return 'ncloc >= 1000 and ncloc < 10000';
+ return 'ncloc >= 1000';
case 3:
- return 'ncloc >= 10000 and ncloc < 100000';
+ return 'ncloc >= 10000';
case 4:
- return 'ncloc >= 100000 ncloc < 500000';
+ return 'ncloc >= 100000';
case 5:
return 'ncloc >= 500000';
default:
@@ -113,15 +121,15 @@ export const convertToFilter = query => {
}
if (query['reliability'] != null) {
- conditions.push('reliability_rating = ' + query['reliability']);
+ conditions.push(convertIssuesRating('reliability_rating', query['reliability']));
}
if (query['security'] != null) {
- conditions.push('security_rating = ' + query['security']);
+ conditions.push(convertIssuesRating('security_rating', query['security']));
}
if (query['maintainability'] != null) {
- conditions.push('sqale_rating = ' + query['maintainability']);
+ conditions.push(convertIssuesRating('sqale_rating', query['maintainability']));
}
return conditions.join(' and ');
diff --git a/server/sonar-web/src/main/js/helpers/ratings.js b/server/sonar-web/src/main/js/helpers/ratings.js
index 1d8347316d8..3c6d110676e 100644
--- a/server/sonar-web/src/main/js/helpers/ratings.js
+++ b/server/sonar-web/src/main/js/helpers/ratings.js
@@ -26,20 +26,20 @@ const checkNumberRating = coverageRating => {
export const getCoverageRatingLabel = rating => {
checkNumberRating(rating);
- const mapping = ['< 30%', '30–50%', '50–70%', '70–80%', '> 80%'];
+ const mapping = ['> 80%', '< 80%', '< 70%', '< 50%', '< 30%'];
return mapping[rating - 1];
};
export const getCoverageRatingAverageValue = rating => {
checkNumberRating(rating);
- const mapping = [15, 40, 60, 75, 90];
+ const mapping = [90, 75, 60, 40, 15];
return mapping[rating - 1];
};
export const getDuplicationsRatingLabel = rating => {
checkNumberRating(rating);
- const mapping = ['< 3%', '3–5%', '5–10%', '10–20%', '> 20%'];
+ const mapping = ['< 3%', '> 3%', '> 5%', '> 10%', '> 20%'];
return mapping[rating - 1];
};
@@ -52,7 +52,7 @@ export const getDuplicationsRatingAverageValue = rating => {
export const getSizeRatingLabel = rating => {
checkNumberRating(rating);
- const mapping = ['< 1k', '1k–10k', '10k–100k', '100k–500k', '> 500k'];
+ const mapping = ['< 1k', '> 1k', '> 10k', '> 100k', '> 500k'];
return mapping[rating - 1];
};