From: Ismail Cherri Date: Mon, 21 Oct 2024 11:57:13 +0000 (+0200) Subject: SONAR-23232 Fix analysis missing message showing on all Pull Requests X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=226ccce51ea2a73e35fc330126d73d825813400d;p=sonarqube.git SONAR-23232 Fix analysis missing message showing on all Pull Requests --- 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 1a0ccf0c4d1..a3f42dde545 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 @@ -176,7 +176,7 @@ describe('rendering', () => { ].forEach((measure) => { expect(ui.measureLink(measure).get()).toBeInTheDocument(); }); - expect(screen.getByText('overview.missing_project_dataTRK')).toBeInTheDocument(); + expect(ui.analysisMissingMessage.get()).toBeInTheDocument(); }); it('should show new counts but not ratings if no rating measures', async () => { @@ -208,7 +208,7 @@ describe('rendering', () => { ].forEach((measure) => { expect(ui.measureLink(measure).get()).toBeInTheDocument(); }); - expect(screen.getByText('overview.missing_project_dataTRK')).toBeInTheDocument(); + expect(ui.analysisMissingMessage.get()).toBeInTheDocument(); }); it('should show old measures and no flag message if no rating measures and legacy mode', async () => { @@ -345,6 +345,26 @@ describe('rendering', () => { expect(await ui.detailsUnavailableText.find()).toBeInTheDocument(); }); + it('should not render analysis missing if on a pull request and leak measure are available', async () => { + const { ui } = getPageObject(); + renderMeasuresApp('component_measures?id=foo&pullRequest=01'); + await ui.appLoaded(); + + expect(screen.queryByText('overview.missing_project_dataTRK')).not.toBeInTheDocument(); + }); + + it('should render analysis missing if on a pull request and leak measure are missing', async () => { + const { ui } = getPageObject(); + measuresHandler.deleteComponentMeasure( + 'foo', + MetricKey.new_software_quality_maintainability_rating, + ); + renderMeasuresApp('component_measures?id=foo&pullRequest=01'); + await ui.appLoaded(); + + expect(ui.analysisMissingMessage.get()).toBeInTheDocument(); + }); + it('should render a warning message if the user does not have access to all components', async () => { const { ui } = getPageObject(); renderMeasuresApp('component_measures?id=foo&metric=code_smells', { @@ -663,6 +683,7 @@ function getPageObject() { seeDataAsListLink: byRole('link', { name: 'component_measures.overview.see_data_as_list' }), bubbleChart: byTestId('bubble-chart'), newCodePeriodTxt: byText('component_measures.leak_legend.new_code'), + analysisMissingMessage: byText('overview.missing_project_dataTRK'), // Navigation overviewDomainLink: byRole('link', { 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 f12e7111e68..f1a488cb6bd 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 @@ -46,6 +46,8 @@ import AnalysisMissingInfoMessage from '../../../components/shared/AnalysisMissi import { translate } from '../../../helpers/l10n'; import { areCCTMeasuresComputed, + areLeakCCTMeasuresComputed, + areLeakSoftwareQualityRatingsComputed, areSoftwareQualityRatingsComputed, } from '../../../helpers/measures'; import { useCurrentBranchQuery } from '../../../queries/branch'; @@ -104,6 +106,10 @@ export default function ComponentMeasuresApp() { componentWithMeasures?.qualifier === ComponentQualifier.Project ? period : undefined; const displayOverview = hasBubbleChart(bubblesByDomain, query.metric); + const showMissingAnalysisMessage = isPullRequest(branchLike) + ? !areLeakCCTMeasuresComputed(measures) || !areLeakSoftwareQualityRatingsComputed(measures) + : !areCCTMeasuresComputed(measures) || !areSoftwareQualityRatingsComputed(measures); + if (!component) { return null; } @@ -226,8 +232,7 @@ export default function ComponentMeasuresApp() { /> )} - {(!areCCTMeasuresComputed(measures) || - !areSoftwareQualityRatingsComputed(measures)) && ( + {showMissingAnalysisMessage && ( + measures?.find((measure) => + isMeasureEnhanced(measure) ? measure.metric.key === metric : measure.metric === metric, + ), + ); +} + export function areLeakAndOverallCCTMeasuresComputed(measures?: Measure[] | MeasureEnhanced[]) { return areLeakCCTMeasuresComputed(measures) && areCCTMeasuresComputed(measures); }