]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-21105 Do not show measures and activity for 'open' and 'reopened' issues metrics
authorstanislavh <stanislav.honcharov@sonarsource.com>
Mon, 27 Nov 2023 14:34:49 +0000 (15:34 +0100)
committersonartech <sonartech@sonarsource.com>
Tue, 28 Nov 2023 20:02:43 +0000 (20:02 +0000)
server/sonar-web/src/main/js/apps/component-measures/__tests__/ComponentMeasures-it.tsx
server/sonar-web/src/main/js/apps/component-measures/__tests__/utils-test.ts
server/sonar-web/src/main/js/apps/component-measures/components/ComponentMeasuresApp.tsx
server/sonar-web/src/main/js/apps/component-measures/utils.ts
server/sonar-web/src/main/js/apps/projectActivity/components/ProjectActivityApp.tsx
server/sonar-web/src/main/js/apps/projectActivity/utils.ts
server/sonar-web/src/main/js/helpers/constants.ts
server/sonar-web/src/main/js/helpers/measures.ts
sonar-core/src/main/resources/org/sonar/l10n/core.properties

index 896a51c68d72cd69c42ca294fa3405b5ccaeed23..cc06b70332f15e21e54a137c94c81822371ce1c2 100644 (file)
@@ -140,6 +140,14 @@ describe('rendering', () => {
     expect(screen.getAllByText('Releasability rating').length).toBeGreaterThan(0);
   });
 
+  it('should render issues measures when query by open_issues', async () => {
+    const { ui } = getPageObject();
+    renderMeasuresApp('component_measures?id=foo&metric=open_issues');
+    await ui.appLoaded();
+
+    expect(screen.getAllByText('Issues').length).toBeGreaterThan(1);
+  });
+
   it('should render correctly if there are no measures', async () => {
     componentsHandler.registerComponentMeasures({});
     measuresHandler.registerComponentMeasures({});
index b74e7998c28ba9c47aea6e06bde09129b18b6517..e8ed99ed1140246fe91fefa46640d679b539fe1f 100644 (file)
@@ -66,7 +66,7 @@ describe('filterMeasures', () => {
   it('should exclude banned measures', () => {
     expect(
       utils.filterMeasures([
-        { metric: { id: '1', key: MetricKey.bugs, name: 'Bugs', type: 'INT' } },
+        { metric: { id: '1', key: MetricKey.open_issues, name: 'Bugs', type: 'INT' } },
         {
           metric: {
             id: '2',
index e07f41aa4fc17b1bb32a684c358697f53e88d842..9054885817c6e792b8c62cc879777b28e7ff5f40 100644 (file)
@@ -51,6 +51,7 @@ import '../style.css';
 import {
   Query,
   banQualityGateMeasure,
+  filterMeasures,
   getMeasuresPageMetricKeys,
   groupByDomains,
   hasBubbleChart,
@@ -144,10 +145,9 @@ class ComponentMeasuresApp extends React.PureComponent<Props, State> {
     getMeasuresWithPeriod(componentKey, filteredKeys, getBranchLikeQuery(branchLike)).then(
       ({ component, period }) => {
         if (this.mounted) {
-          const measures = banQualityGateMeasure(component).map((measure) =>
-            enhanceMeasure(measure, metrics),
+          const measures = filterMeasures(
+            banQualityGateMeasure(component).map((measure) => enhanceMeasure(measure, metrics)),
           );
-
           const leakPeriod =
             component.qualifier === ComponentQualifier.Project ? period : undefined;
 
index ca845e698b2f143b473d551087cfd59268b99e93..86e3c7b91cb6b73f54ff421272edae294cd189f3 100644 (file)
@@ -20,6 +20,7 @@
 import { groupBy, memoize, sortBy, toPairs } from 'lodash';
 import { enhanceMeasure } from '../../components/measure/utils';
 import { isBranch, isPullRequest } from '../../helpers/branch-like';
+import { HIDDEN_METRICS } from '../../helpers/constants';
 import { getLocalizedMetricName } from '../../helpers/l10n';
 import { MEASURES_REDIRECTION, getDisplayMetrics, isDiffMetric } from '../../helpers/measures';
 import {
@@ -59,21 +60,9 @@ export const KNOWN_DOMAINS = [
   'Size',
   'Complexity',
 ];
-const BANNED_MEASURES = [
-  MetricKey.blocker_violations,
-  MetricKey.new_blocker_violations,
-  MetricKey.critical_violations,
-  MetricKey.new_critical_violations,
-  MetricKey.major_violations,
-  MetricKey.new_major_violations,
-  MetricKey.minor_violations,
-  MetricKey.new_minor_violations,
-  MetricKey.info_violations,
-  MetricKey.new_info_violations,
-];
 
 export function filterMeasures(measures: MeasureEnhanced[]): MeasureEnhanced[] {
-  return measures.filter((measure) => !BANNED_MEASURES.includes(measure.metric.key as MetricKey));
+  return measures.filter((measure) => !HIDDEN_METRICS.includes(measure.metric.key as MetricKey));
 }
 
 export function sortMeasures(
index c9a199e4b27995705c4d711dac8da0237764eeec..8a93f70b4585a640168a3b437ee547ae73293b75 100644 (file)
@@ -39,6 +39,7 @@ import {
 } from '../../../components/activity-graph/utils';
 import { Location, Router, withRouter } from '../../../components/hoc/withRouter';
 import { getBranchLikeQuery } from '../../../helpers/branch-like';
+import { HIDDEN_METRICS } from '../../../helpers/constants';
 import { parseDate } from '../../../helpers/dates';
 import { serializeStringArray } from '../../../helpers/query';
 import { withBranchLikes } from '../../../queries/branch';
@@ -290,7 +291,8 @@ class ProjectActivityApp extends React.PureComponent<Props, State> {
     }
 
     return Object.values(metrics).filter(
-      (metric) => metric.key !== MetricKey.security_review_rating,
+      (metric) =>
+        ![...HIDDEN_METRICS, MetricKey.security_review_rating].includes(metric.key as MetricKey),
     );
   };
 
index 593bed6b88130d2058e26427499a060d85e5824e..e6c3e0911cf1332331af5028c9f57496624d3c8c 100644 (file)
@@ -18,7 +18,7 @@
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  */
 import { startOfDay } from 'date-fns';
-import { isEqual } from 'lodash';
+import { isEqual, uniq } from 'lodash';
 import { DEFAULT_GRAPH } from '../../components/activity-graph/utils';
 import { parseDate } from '../../helpers/dates';
 import { MEASURES_REDIRECTION } from '../../helpers/measures';
@@ -112,7 +112,7 @@ export function getAnalysesByVersionByDay(
 
 export function parseQuery(urlQuery: RawQuery): Query {
   const parsedMetrics = parseAsArray(urlQuery['custom_metrics'], parseAsString<MetricKey>);
-  const customMetrics = parsedMetrics.map((metric) => MEASURES_REDIRECTION[metric] ?? metric);
+  const customMetrics = uniq(parsedMetrics.map((metric) => MEASURES_REDIRECTION[metric] ?? metric));
 
   return {
     category: parseAsString(urlQuery['category']),
index 5dd32be9e4e28f2f84df47e7e7f5c8ac416e3804..ec5a1800c6114ce216c2833725728e078b2d2b01 100644 (file)
@@ -32,6 +32,7 @@ import {
   IssueStatus,
   IssueType,
 } from '../types/issues';
+import { MetricKey } from '../types/metrics';
 import { RuleType } from '../types/types';
 
 export const SEVERITIES = Object.values(IssueSeverity);
@@ -92,6 +93,8 @@ export const RATING_COLORS = [
   { fill: colors.error400, fillTransparent: colors.error400a20, stroke: colors.error700 },
 ];
 
+export const HIDDEN_METRICS = [MetricKey.open_issues, MetricKey.reopened_issues];
+
 export const PROJECT_KEY_MAX_LEN = 400;
 
 export const ALM_DOCUMENTATION_PATHS = {
index 7071e4c965e2503cdc25c48d24eb63171b05e2ab..12b13b026ce7350916fe9bd0af8380989ca96518 100644 (file)
@@ -30,6 +30,8 @@ import { isDefined } from './types';
 
 export const MEASURES_REDIRECTION: Partial<Record<MetricKey, MetricKey>> = {
   [MetricKey.wont_fix_issues]: MetricKey.accepted_issues,
+  [MetricKey.open_issues]: MetricKey.violations,
+  [MetricKey.reopened_issues]: MetricKey.violations,
 };
 
 export function enhanceMeasuresWithMetrics(
index e5df0b0beda19d3acee33b19b3b0d649cec1918d..5aadc624eca0d1af95ac41e908e63e78a4e36c32 100644 (file)
@@ -4012,6 +4012,7 @@ component_measures.domain_overview=Overview
 component_measures.files=files
 component_measures.tab.tree=Tree
 component_measures.tab.list=List
+component_measures.show_metric_history=Show history of this metric
 component_measures.tab.treemap=Treemap
 component_measures.view_as=View as
 component_measures.legend.color=Color: