From: stanislavh Date: Tue, 30 Jan 2024 17:15:29 +0000 (+0100) Subject: SONAR-21455 Adjust logic of showing application warning X-Git-Tag: 10.4.0.87286~46 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=68cdc84139405f39dac06d55ad37f636e12e6a7f;p=sonarqube.git SONAR-21455 Adjust logic of showing application warning --- diff --git a/server/sonar-web/src/main/js/apps/overview/branches/BranchOverviewRenderer.tsx b/server/sonar-web/src/main/js/apps/overview/branches/BranchOverviewRenderer.tsx index 1a6e477c88b..1c8eefaafaa 100644 --- a/server/sonar-web/src/main/js/apps/overview/branches/BranchOverviewRenderer.tsx +++ b/server/sonar-web/src/main/js/apps/overview/branches/BranchOverviewRenderer.tsx @@ -98,18 +98,17 @@ export default function BranchOverviewRenderer(props: BranchOverviewRendererProp }); const intl = useIntl(); - // Check if any potentially missing uncomputed measure is not present - const isMissingMeasures = [ - MetricKey.new_accepted_issues, - MetricKey.security_issues, - MetricKey.maintainability_issues, - MetricKey.reliability_issues, - ].some((key) => !measures.find((measure) => measure.metric.key === key)); - const leakPeriod = component.qualifier === ComponentQualifier.Application ? appLeak : period; const isNewCodeTab = tab === MeasuresTabs.New; const hasNewCodeMeasures = measures.some((m) => isDiffMetric(m.metric.key)); + // Check if any potentially missing uncomputed measure is not present + const isMissingMeasures = ( + isNewCodeTab + ? [MetricKey.new_accepted_issues] + : [MetricKey.security_issues, MetricKey.maintainability_issues, MetricKey.reliability_issues] + ).some((key) => !measures.find((measure) => measure.metric.key === key)); + React.useEffect(() => { // Open Overall tab by default if there are no new measures. if (loadingStatus === false && !hasNewCodeMeasures && isNewCodeTab) { @@ -120,6 +119,15 @@ export default function BranchOverviewRenderer(props: BranchOverviewRendererProp /* eslint-disable-next-line react-hooks/exhaustive-deps */ }, [loadingStatus, hasNewCodeMeasures]); + const appReanalysisWarning = + isMissingMeasures && isApplication(component.qualifier) ? ( + + {intl.formatMessage({ + id: 'overview.missing_project_data.APP', + })} + + ) : null; + return ( <> - {hasNewCodeMeasures && - isMissingMeasures && - isApplication(component.qualifier) && ( - - {intl.formatMessage({ - id: 'overview.missing_project_data.APP', - })} - - )} - - {isNewCodeTab && !hasNewCodeMeasures && ( - - )} - - {isNewCodeTab && hasNewCodeMeasures && ( - + {isNewCodeTab && ( + <> + {hasNewCodeMeasures ? ( + <> + {appReanalysisWarning} + + + ) : ( + + )} + )} {!isNewCodeTab && ( - + <> + {appReanalysisWarning} + + )} diff --git a/server/sonar-web/src/main/js/apps/overview/branches/__tests__/BranchOverview-it.tsx b/server/sonar-web/src/main/js/apps/overview/branches/__tests__/BranchOverview-it.tsx index a761cf832c1..ef86a352004 100644 --- a/server/sonar-web/src/main/js/apps/overview/branches/__tests__/BranchOverview-it.tsx +++ b/server/sonar-web/src/main/js/apps/overview/branches/__tests__/BranchOverview-it.tsx @@ -473,17 +473,29 @@ describe('application overview', () => { expect(await screen.findByText('portfolio.app.empty')).toBeInTheDocument(); }); + it.each([['new_accepted_issues', MetricKey.new_accepted_issues]])( + 'should ask to reanalyze all projects if a project is not computed for %s', + async (missingMetricKey) => { + measuresHandler.deleteComponentMeasure('foo', missingMetricKey as MetricKey); + + renderBranchOverview({ component }); + + expect(await screen.findByText('overview.missing_project_data.APP')).toBeInTheDocument(); + }, + ); + it.each([ - ['new_accepted_issues', MetricKey.new_accepted_issues], ['security_issues', MetricKey.security_issues], ['reliability_issues', MetricKey.reliability_issues], ['maintainability_issues', MetricKey.maintainability_issues], ])( - 'should ask to reanalyze all projects if a project is not computed', + 'should ask to reanalyze all projects if a project is not computed for %s', async (missingMetricKey) => { - measuresHandler.deleteComponentMeasure('foo', missingMetricKey as MetricKey); + const { ui, user } = getPageObjects(); + measuresHandler.deleteComponentMeasure('foo', missingMetricKey as MetricKey); renderBranchOverview({ component }); + await user.click(await ui.overallCodeButton.find()); expect(await screen.findByText('overview.missing_project_data.APP')).toBeInTheDocument(); },