From: stanislavh Date: Mon, 27 Nov 2023 14:34:49 +0000 (+0100) Subject: SONAR-21105 Do not show measures and activity for 'open' and 'reopened' issues metrics X-Git-Tag: 10.4.0.87286~394 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=c98acfe402fb765f268f4338d261450cf1f6f83b;p=sonarqube.git SONAR-21105 Do not show measures and activity for 'open' and 'reopened' issues metrics --- diff --git a/server/sonar-web/src/main/js/apps/component-measures/__tests__/ComponentMeasures-it.tsx b/server/sonar-web/src/main/js/apps/component-measures/__tests__/ComponentMeasures-it.tsx index 896a51c68d7..cc06b70332f 100644 --- a/server/sonar-web/src/main/js/apps/component-measures/__tests__/ComponentMeasures-it.tsx +++ b/server/sonar-web/src/main/js/apps/component-measures/__tests__/ComponentMeasures-it.tsx @@ -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({}); diff --git a/server/sonar-web/src/main/js/apps/component-measures/__tests__/utils-test.ts b/server/sonar-web/src/main/js/apps/component-measures/__tests__/utils-test.ts index b74e7998c28..e8ed99ed114 100644 --- a/server/sonar-web/src/main/js/apps/component-measures/__tests__/utils-test.ts +++ b/server/sonar-web/src/main/js/apps/component-measures/__tests__/utils-test.ts @@ -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', diff --git a/server/sonar-web/src/main/js/apps/component-measures/components/ComponentMeasuresApp.tsx b/server/sonar-web/src/main/js/apps/component-measures/components/ComponentMeasuresApp.tsx index e07f41aa4fc..9054885817c 100644 --- a/server/sonar-web/src/main/js/apps/component-measures/components/ComponentMeasuresApp.tsx +++ b/server/sonar-web/src/main/js/apps/component-measures/components/ComponentMeasuresApp.tsx @@ -51,6 +51,7 @@ import '../style.css'; import { Query, banQualityGateMeasure, + filterMeasures, getMeasuresPageMetricKeys, groupByDomains, hasBubbleChart, @@ -144,10 +145,9 @@ class ComponentMeasuresApp extends React.PureComponent { 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; diff --git a/server/sonar-web/src/main/js/apps/component-measures/utils.ts b/server/sonar-web/src/main/js/apps/component-measures/utils.ts index ca845e698b2..86e3c7b91cb 100644 --- a/server/sonar-web/src/main/js/apps/component-measures/utils.ts +++ b/server/sonar-web/src/main/js/apps/component-measures/utils.ts @@ -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( diff --git a/server/sonar-web/src/main/js/apps/projectActivity/components/ProjectActivityApp.tsx b/server/sonar-web/src/main/js/apps/projectActivity/components/ProjectActivityApp.tsx index c9a199e4b27..8a93f70b458 100644 --- a/server/sonar-web/src/main/js/apps/projectActivity/components/ProjectActivityApp.tsx +++ b/server/sonar-web/src/main/js/apps/projectActivity/components/ProjectActivityApp.tsx @@ -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 { } return Object.values(metrics).filter( - (metric) => metric.key !== MetricKey.security_review_rating, + (metric) => + ![...HIDDEN_METRICS, MetricKey.security_review_rating].includes(metric.key as MetricKey), ); }; diff --git a/server/sonar-web/src/main/js/apps/projectActivity/utils.ts b/server/sonar-web/src/main/js/apps/projectActivity/utils.ts index 593bed6b881..e6c3e0911cf 100644 --- a/server/sonar-web/src/main/js/apps/projectActivity/utils.ts +++ b/server/sonar-web/src/main/js/apps/projectActivity/utils.ts @@ -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); - const customMetrics = parsedMetrics.map((metric) => MEASURES_REDIRECTION[metric] ?? metric); + const customMetrics = uniq(parsedMetrics.map((metric) => MEASURES_REDIRECTION[metric] ?? metric)); return { category: parseAsString(urlQuery['category']), diff --git a/server/sonar-web/src/main/js/helpers/constants.ts b/server/sonar-web/src/main/js/helpers/constants.ts index 5dd32be9e4e..ec5a1800c61 100644 --- a/server/sonar-web/src/main/js/helpers/constants.ts +++ b/server/sonar-web/src/main/js/helpers/constants.ts @@ -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 = { diff --git a/server/sonar-web/src/main/js/helpers/measures.ts b/server/sonar-web/src/main/js/helpers/measures.ts index 7071e4c965e..12b13b026ce 100644 --- a/server/sonar-web/src/main/js/helpers/measures.ts +++ b/server/sonar-web/src/main/js/helpers/measures.ts @@ -30,6 +30,8 @@ import { isDefined } from './types'; export const MEASURES_REDIRECTION: Partial> = { [MetricKey.wont_fix_issues]: MetricKey.accepted_issues, + [MetricKey.open_issues]: MetricKey.violations, + [MetricKey.reopened_issues]: MetricKey.violations, }; export function enhanceMeasuresWithMetrics( diff --git a/sonar-core/src/main/resources/org/sonar/l10n/core.properties b/sonar-core/src/main/resources/org/sonar/l10n/core.properties index e5df0b0beda..5aadc624eca 100644 --- a/sonar-core/src/main/resources/org/sonar/l10n/core.properties +++ b/sonar-core/src/main/resources/org/sonar/l10n/core.properties @@ -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: