From 71448e0378fcea35b848affcb8743609a8487d89 Mon Sep 17 00:00:00 2001 From: Viktor Vorona Date: Tue, 15 Oct 2024 16:43:32 +0200 Subject: [PATCH] SONAR-23197 Project list adapt MQR/Standard mode --- .../components/__tests__/PageSidebar-test.tsx | 4 +++ .../project-card/ProjectCardMeasures.tsx | 12 ++++++-- .../__tests__/ProjectCardMeasures-test.tsx | 28 +++++++++++++++++-- .../js/apps/projects/filters/RatingFacet.tsx | 12 ++++++-- .../resources/org/sonar/l10n/core.properties | 2 ++ 5 files changed, 50 insertions(+), 8 deletions(-) diff --git a/server/sonar-web/src/main/js/apps/projects/components/__tests__/PageSidebar-test.tsx b/server/sonar-web/src/main/js/apps/projects/components/__tests__/PageSidebar-test.tsx index c1d41c9b149..28793462844 100644 --- a/server/sonar-web/src/main/js/apps/projects/components/__tests__/PageSidebar-test.tsx +++ b/server/sonar-web/src/main/js/apps/projects/components/__tests__/PageSidebar-test.tsx @@ -89,6 +89,8 @@ it('should show legacy filters', async () => { renderPageSidebar(); expect(await screen.findAllByText(/projects.facets.rating_option/)).toHaveLength(20); + expect(screen.getByText('projects.facets.security.description')).toBeInTheDocument(); + expect(screen.getByText('projects.facets.reliability.description')).toBeInTheDocument(); expect(screen.getByText('projects.facets.rating_option.security.legacy.1')).toBeInTheDocument(); expect( screen.getByText('projects.facets.rating_option.reliability.legacy.1'), @@ -100,6 +102,8 @@ it('should show non legacy filters', async () => { renderPageSidebar(); expect(await screen.findAllByText(/projects.facets.rating_option/)).toHaveLength(20); + expect(screen.queryByText('projects.facets.security.description')).not.toBeInTheDocument(); + expect(screen.queryByText('projects.facets.reliability.description')).not.toBeInTheDocument(); expect(screen.getByText('projects.facets.rating_option.security.1')).toBeInTheDocument(); expect(screen.getByText('projects.facets.rating_option.reliability.1')).toBeInTheDocument(); }); diff --git a/server/sonar-web/src/main/js/apps/projects/components/project-card/ProjectCardMeasures.tsx b/server/sonar-web/src/main/js/apps/projects/components/project-card/ProjectCardMeasures.tsx index 3b7ac673094..19dfe38e4dc 100644 --- a/server/sonar-web/src/main/js/apps/projects/components/project-card/ProjectCardMeasures.tsx +++ b/server/sonar-web/src/main/js/apps/projects/components/project-card/ProjectCardMeasures.tsx @@ -123,7 +123,9 @@ function renderRatings(props: ProjectCardMeasuresProps, isLegacy: boolean) { ? [] : [ { - iconLabel: translate(`metric.${MetricKey.security_issues}.short_name`), + iconLabel: translate( + `metric.${isLegacy ? MetricKey.vulnerabilities : MetricKey.security_issues}.short_name`, + ), noShrink: true, metricKey: isLegacy || measures[MetricKey.security_issues] === undefined @@ -133,7 +135,9 @@ function renderRatings(props: ProjectCardMeasuresProps, isLegacy: boolean) { metricType: MetricType.ShortInteger, }, { - iconLabel: translate(`metric.${MetricKey.reliability_issues}.short_name`), + iconLabel: translate( + `metric.${isLegacy ? MetricKey.bugs : MetricKey.reliability_issues}.short_name`, + ), metricKey: isLegacy || measures[MetricKey.reliability_issues] === undefined ? MetricKey.bugs @@ -142,7 +146,9 @@ function renderRatings(props: ProjectCardMeasuresProps, isLegacy: boolean) { metricType: MetricType.ShortInteger, }, { - iconLabel: translate(`metric.${MetricKey.maintainability_issues}.short_name`), + iconLabel: translate( + `metric.${isLegacy ? MetricKey.code_smells : MetricKey.maintainability_issues}.short_name`, + ), metricKey: isLegacy || measures[MetricKey.maintainability_issues] === undefined ? MetricKey.code_smells diff --git a/server/sonar-web/src/main/js/apps/projects/components/project-card/__tests__/ProjectCardMeasures-test.tsx b/server/sonar-web/src/main/js/apps/projects/components/project-card/__tests__/ProjectCardMeasures-test.tsx index dda98e4df78..ac3263e479d 100644 --- a/server/sonar-web/src/main/js/apps/projects/components/project-card/__tests__/ProjectCardMeasures-test.tsx +++ b/server/sonar-web/src/main/js/apps/projects/components/project-card/__tests__/ProjectCardMeasures-test.tsx @@ -22,7 +22,9 @@ import * as React from 'react'; import { ComponentQualifier } from '~sonar-aligned/types/component'; import { MetricKey } from '~sonar-aligned/types/metrics'; +import SettingsServiceMock from '../../../../../api/mocks/SettingsServiceMock'; import { renderComponent } from '../../../../../helpers/testReactTestingUtils'; +import { SettingsKey } from '../../../../../types/settings'; import { Dict } from '../../../../../types/types'; import ProjectCardMeasures, { ProjectCardMeasuresProps } from '../ProjectCardMeasures'; @@ -31,10 +33,32 @@ jest.mock('date-fns', () => ({ differenceInMilliseconds: () => 1000 * 60 * 60 * 24 * 30 * 8, // ~ 8 months })); +const settingsService = new SettingsServiceMock(); + +beforeEach(() => { + settingsService.reset(); +}); + describe('Overall measures', () => { - it('should be rendered properly', () => { + it('should be rendered properly', async () => { + renderProjectCardMeasures(); + expect(await screen.findByTitle('metric.security_issues.short_name')).toBeInTheDocument(); + expect(screen.getByTitle('metric.reliability_issues.short_name')).toBeInTheDocument(); + expect(screen.getByTitle('metric.maintainability_issues.short_name')).toBeInTheDocument(); + expect(screen.queryByTitle('metric.vulnerabilities.short_name')).not.toBeInTheDocument(); + expect(screen.queryByTitle('metric.bugs.short_name')).not.toBeInTheDocument(); + expect(screen.queryByTitle('metric.code_smells.short_name')).not.toBeInTheDocument(); + }); + + it('should be rendered properly in Standard mode', async () => { + settingsService.set(SettingsKey.MQRMode, 'false'); renderProjectCardMeasures(); - expect(screen.getByTitle('metric.security_issues.short_name')).toBeInTheDocument(); + expect(await screen.findByTitle('metric.vulnerabilities.short_name')).toBeInTheDocument(); + expect(screen.getByTitle('metric.bugs.short_name')).toBeInTheDocument(); + expect(screen.getByTitle('metric.code_smells.short_name')).toBeInTheDocument(); + expect(screen.queryByTitle('metric.security_issues.short_name')).not.toBeInTheDocument(); + expect(screen.queryByTitle('metric.reliability_issues.short_name')).not.toBeInTheDocument(); + expect(screen.queryByTitle('metric.maintainability_issues.short_name')).not.toBeInTheDocument(); }); it("should be not be rendered if there's no line of code", () => { diff --git a/server/sonar-web/src/main/js/apps/projects/filters/RatingFacet.tsx b/server/sonar-web/src/main/js/apps/projects/filters/RatingFacet.tsx index cd9aad48051..5a0b704345b 100644 --- a/server/sonar-web/src/main/js/apps/projects/filters/RatingFacet.tsx +++ b/server/sonar-web/src/main/js/apps/projects/filters/RatingFacet.tsx @@ -40,6 +40,7 @@ interface Props { export default function RatingFacet(props: Readonly) { const { facet, maxFacetValue, name, property, value } = props; + const { data: isLegacy } = useIsLegacyCCTMode(); const renderAccessibleLabel = React.useCallback( (option: number) => { @@ -65,7 +66,7 @@ export default function RatingFacet(props: Readonly) { facet={facet} header={translate('metric_domain', name)} description={ - hasDescription(property) + hasDescription(property, isLegacy) ? translate(`projects.facets.${property.replace('new_', '')}.description`) : undefined } @@ -81,8 +82,13 @@ export default function RatingFacet(props: Readonly) { ); } -const hasDescription = (property: string) => { - return ['maintainability', 'new_maintainability', 'security_review'].includes(property); +const hasDescription = (property: string, isLegacy = false) => { + return [ + 'maintainability', + 'new_maintainability', + 'security_review', + ...(isLegacy ? ['security', 'new_security', 'reliability', 'new_reliability'] : []), + ].includes(property); }; function renderOption(option: string | number, property: string) { 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 7a2e6d94f73..00d977c03b3 100644 --- a/sonar-core/src/main/resources/org/sonar/l10n/core.properties +++ b/sonar-core/src/main/resources/org/sonar/l10n/core.properties @@ -1361,6 +1361,8 @@ projects.facets.rating_option.security_review.4=≥ 30% to <50% projects.facets.rating_option.security_review.5=< 30% projects.facets.security_review.description=The percentage of reviewed (fixed or safe) security hotspots projects.facets.maintainability.description=Ratio of the estimated time needed to fix all outstanding maintainability issues to the size of the project +projects.facets.security.description=Vulnerability count +projects.facets.reliability.description=Bug count projects.facets.languages=Languages projects.facets.search.languages=Search for languages projects.facets.new_lines=New Lines -- 2.39.5