From 5e66c60c4cc35a6023413324f56c46411e326d54 Mon Sep 17 00:00:00 2001 From: 7PH Date: Mon, 29 Jan 2024 14:21:35 +0100 Subject: [PATCH] SONAR-21455 Drop dead code & Re-organize branch/pr overview components to relevant folders --- .../design-system/src/theme/light.ts | 2 +- .../branches/BranchOverviewRenderer.tsx | 2 +- .../js/apps/overview/branches/DebtValue.tsx | 75 ---------- .../branches/DrilldownMeasureValue.tsx | 66 --------- .../overview/branches/MeasuresPanelCard.tsx | 43 ------ .../QualityGateCondition.tsx | 0 .../QualityGateConditions.tsx | 2 +- .../overview/branches/QualityGatePanel.tsx | 6 +- .../branches/QualityGatePanelSection.tsx | 2 +- .../QualityGateSimplifiedCondition.tsx | 0 .../QualityGateStatusHeader.tsx | 0 .../QualityGateStatusPassedView.tsx | 0 .../QualityGateStatusTitle.tsx | 0 .../SonarLintPromotion.tsx | 0 .../branches/__tests__/DebtValue-test.tsx | 72 --------- .../__tests__/QualityGateCondition-test.tsx | 0 .../__tests__/QualityGateConditions-test.tsx | 0 .../QualityGateSimplifiedCondition-test.tsx | 0 .../__tests__/SonarLintPromotion-test.tsx | 0 .../apps/overview/components/IssueLabel.tsx | 110 -------------- .../apps/overview/components/IssueRating.tsx | 84 ----------- .../overview/components/LeakPeriodLegend.tsx | 116 --------------- .../components/__tests__/IssueLabel-test.tsx | 108 -------------- .../components/__tests__/IssueRating-test.tsx | 60 -------- .../__tests__/LeakPeriodLegend-test.tsx | 140 ------------------ .../BranchQualityGate.tsx | 0 .../BranchQualityGateConditions.tsx | 0 .../pullRequests/PullRequestOverview.tsx | 2 +- .../__tests__/BranchQualityGate-it.tsx | 0 29 files changed, 8 insertions(+), 882 deletions(-) delete mode 100644 server/sonar-web/src/main/js/apps/overview/branches/DebtValue.tsx delete mode 100644 server/sonar-web/src/main/js/apps/overview/branches/DrilldownMeasureValue.tsx delete mode 100644 server/sonar-web/src/main/js/apps/overview/branches/MeasuresPanelCard.tsx rename server/sonar-web/src/main/js/apps/overview/{components => branches}/QualityGateCondition.tsx (100%) rename server/sonar-web/src/main/js/apps/overview/{components => branches}/QualityGateConditions.tsx (97%) rename server/sonar-web/src/main/js/apps/overview/{components => branches}/QualityGateSimplifiedCondition.tsx (100%) rename server/sonar-web/src/main/js/apps/overview/{components => branches}/QualityGateStatusHeader.tsx (100%) rename server/sonar-web/src/main/js/apps/overview/{components => branches}/QualityGateStatusPassedView.tsx (100%) rename server/sonar-web/src/main/js/apps/overview/{components => branches}/QualityGateStatusTitle.tsx (100%) rename server/sonar-web/src/main/js/apps/overview/{components => branches}/SonarLintPromotion.tsx (100%) delete mode 100644 server/sonar-web/src/main/js/apps/overview/branches/__tests__/DebtValue-test.tsx rename server/sonar-web/src/main/js/apps/overview/{components => branches}/__tests__/QualityGateCondition-test.tsx (100%) rename server/sonar-web/src/main/js/apps/overview/{components => branches}/__tests__/QualityGateConditions-test.tsx (100%) rename server/sonar-web/src/main/js/apps/overview/{components => branches}/__tests__/QualityGateSimplifiedCondition-test.tsx (100%) rename server/sonar-web/src/main/js/apps/overview/{components => branches}/__tests__/SonarLintPromotion-test.tsx (100%) delete mode 100644 server/sonar-web/src/main/js/apps/overview/components/IssueLabel.tsx delete mode 100644 server/sonar-web/src/main/js/apps/overview/components/IssueRating.tsx delete mode 100644 server/sonar-web/src/main/js/apps/overview/components/LeakPeriodLegend.tsx delete mode 100644 server/sonar-web/src/main/js/apps/overview/components/__tests__/IssueLabel-test.tsx delete mode 100644 server/sonar-web/src/main/js/apps/overview/components/__tests__/IssueRating-test.tsx delete mode 100644 server/sonar-web/src/main/js/apps/overview/components/__tests__/LeakPeriodLegend-test.tsx rename server/sonar-web/src/main/js/apps/overview/{components => pullRequests}/BranchQualityGate.tsx (100%) rename server/sonar-web/src/main/js/apps/overview/{components => pullRequests}/BranchQualityGateConditions.tsx (100%) rename server/sonar-web/src/main/js/apps/overview/{components => pullRequests}/__tests__/BranchQualityGate-it.tsx (100%) diff --git a/server/sonar-web/design-system/src/theme/light.ts b/server/sonar-web/design-system/src/theme/light.ts index d6ba2162d3b..dbce87280d1 100644 --- a/server/sonar-web/design-system/src/theme/light.ts +++ b/server/sonar-web/design-system/src/theme/light.ts @@ -532,7 +532,7 @@ export const lightTheme = { overviewCardSuccessIcon: COLORS.green[200], // overview software impact breakdown - overviewSoftwareImpactSeverityNeutral: [247, 249, 252], + overviewSoftwareImpactSeverityNeutral: COLORS.blueGrey[35], overviewSoftwareImpactSeverityHigh: COLORS.red[100], overviewSoftwareImpactSeverityMedium: COLORS.yellow[100], overviewSoftwareImpactSeverityLow: COLORS.blue[100], 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 4a2efcc260b..1a6e477c88b 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 @@ -39,7 +39,6 @@ import { Analysis, GraphType, MeasureHistory } from '../../../types/project-acti import { QualityGateStatus } from '../../../types/quality-gates'; import { Component, MeasureEnhanced, Metric, Period, QualityGate } from '../../../types/types'; import { AnalysisStatus } from '../components/AnalysisStatus'; -import SonarLintPromotion from '../components/SonarLintPromotion'; import { MeasuresTabs } from '../utils'; import ActivityPanel from './ActivityPanel'; import BranchMetaTopBar from './BranchMetaTopBar'; @@ -49,6 +48,7 @@ import NewCodeMeasuresPanel from './NewCodeMeasuresPanel'; import NoCodeWarning from './NoCodeWarning'; import OverallCodeMeasuresPanel from './OverallCodeMeasuresPanel'; import QualityGatePanel from './QualityGatePanel'; +import SonarLintPromotion from './SonarLintPromotion'; import { TabsPanel } from './TabsPanel'; export interface BranchOverviewRendererProps { diff --git a/server/sonar-web/src/main/js/apps/overview/branches/DebtValue.tsx b/server/sonar-web/src/main/js/apps/overview/branches/DebtValue.tsx deleted file mode 100644 index b719d2c281d..00000000000 --- a/server/sonar-web/src/main/js/apps/overview/branches/DebtValue.tsx +++ /dev/null @@ -1,75 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2024 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -import * as React from 'react'; -import { getLeakValue } from '../../../components/measure/utils'; -import DrilldownLink from '../../../components/shared/DrilldownLink'; -import { getLocalizedMetricName, translate, translateWithParameters } from '../../../helpers/l10n'; -import { findMeasure, formatMeasure, localizeMetric } from '../../../helpers/measures'; -import { BranchLike } from '../../../types/branch-like'; -import { MetricKey } from '../../../types/metrics'; -import { Component, MeasureEnhanced } from '../../../types/types'; - -export interface DebtValueProps { - branchLike?: BranchLike; - component: Component; - measures: MeasureEnhanced[]; - useDiffMetric?: boolean; -} - -export function DebtValue(props: DebtValueProps) { - const { branchLike, component, measures, useDiffMetric = false } = props; - const metricKey = useDiffMetric ? MetricKey.new_technical_debt : MetricKey.sqale_index; - const measure = findMeasure(measures, metricKey); - - let value; - let metricName; - if (measure) { - value = useDiffMetric ? getLeakValue(measure) : measure.value; - metricName = getLocalizedMetricName(measure.metric, true); - } else { - metricName = localizeMetric(metricKey); - } - const formattedValue = formatMeasure(value, 'WORK_DUR'); - - return ( - <> - {value === undefined ? ( - - ) : ( - - {formattedValue} - - )} - {metricName} - - ); -} - -export default React.memo(DebtValue); diff --git a/server/sonar-web/src/main/js/apps/overview/branches/DrilldownMeasureValue.tsx b/server/sonar-web/src/main/js/apps/overview/branches/DrilldownMeasureValue.tsx deleted file mode 100644 index 97dfdb5c5dc..00000000000 --- a/server/sonar-web/src/main/js/apps/overview/branches/DrilldownMeasureValue.tsx +++ /dev/null @@ -1,66 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2024 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -import { DrilldownLink } from 'design-system'; -import * as React from 'react'; -import { translateWithParameters } from '../../../helpers/l10n'; -import { findMeasure, formatMeasure, localizeMetric } from '../../../helpers/measures'; -import { getComponentDrilldownUrl } from '../../../helpers/urls'; -import { BranchLike } from '../../../types/branch-like'; -import { MetricKey, MetricType } from '../../../types/metrics'; -import { Component, MeasureEnhanced } from '../../../types/types'; - -export interface DrilldownMeasureValueProps { - branchLike?: BranchLike; - component: Component; - measures: MeasureEnhanced[]; - metric: MetricKey; -} - -export function DrilldownMeasureValue(props: DrilldownMeasureValueProps) { - const { branchLike, component, measures, metric } = props; - const measure = findMeasure(measures, metric); - - if (!measure || measure.value === undefined) { - return –; - } - - const url = getComponentDrilldownUrl({ - branchLike, - componentKey: component.key, - metric, - }); - - return ( - - - {formatMeasure(measure.value, MetricType.ShortInteger)} - - - ); -} - -export default React.memo(DrilldownMeasureValue); diff --git a/server/sonar-web/src/main/js/apps/overview/branches/MeasuresPanelCard.tsx b/server/sonar-web/src/main/js/apps/overview/branches/MeasuresPanelCard.tsx deleted file mode 100644 index dc0dba16ea4..00000000000 --- a/server/sonar-web/src/main/js/apps/overview/branches/MeasuresPanelCard.tsx +++ /dev/null @@ -1,43 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2024 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -import * as React from 'react'; - -interface Props { - category: React.ReactElement; - rating: React.ReactElement | null; -} - -export default function MeasuresPanelCard( - props: React.PropsWithChildren>, -) { - const { category, children, rating, ...attributes } = props; - - return ( -
-
-
{category}
- -
{children}
-
- -
{rating}
-
- ); -} diff --git a/server/sonar-web/src/main/js/apps/overview/components/QualityGateCondition.tsx b/server/sonar-web/src/main/js/apps/overview/branches/QualityGateCondition.tsx similarity index 100% rename from server/sonar-web/src/main/js/apps/overview/components/QualityGateCondition.tsx rename to server/sonar-web/src/main/js/apps/overview/branches/QualityGateCondition.tsx diff --git a/server/sonar-web/src/main/js/apps/overview/components/QualityGateConditions.tsx b/server/sonar-web/src/main/js/apps/overview/branches/QualityGateConditions.tsx similarity index 97% rename from server/sonar-web/src/main/js/apps/overview/components/QualityGateConditions.tsx rename to server/sonar-web/src/main/js/apps/overview/branches/QualityGateConditions.tsx index b74ffa88ca9..de461bfb406 100644 --- a/server/sonar-web/src/main/js/apps/overview/components/QualityGateConditions.tsx +++ b/server/sonar-web/src/main/js/apps/overview/branches/QualityGateConditions.tsx @@ -40,7 +40,7 @@ export interface QualityGateConditionsProps { const MAX_CONDITIONS = 5; -export function QualityGateConditions(props: QualityGateConditionsProps) { +export function QualityGateConditions(props: Readonly) { const { branchLike, collapsible, component, failedConditions, isBuiltInQualityGate } = props; const [collapsed, toggleCollapsed] = React.useState(Boolean(collapsible)); diff --git a/server/sonar-web/src/main/js/apps/overview/branches/QualityGatePanel.tsx b/server/sonar-web/src/main/js/apps/overview/branches/QualityGatePanel.tsx index 0118908120d..d752b0f4b23 100644 --- a/server/sonar-web/src/main/js/apps/overview/branches/QualityGatePanel.tsx +++ b/server/sonar-web/src/main/js/apps/overview/branches/QualityGatePanel.tsx @@ -23,12 +23,12 @@ import { ComponentQualifier, isApplication } from '../../../types/component'; import { QualityGateStatus } from '../../../types/quality-gates'; import { CaycStatus, Component, QualityGate } from '../../../types/types'; import IgnoredConditionWarning from '../components/IgnoredConditionWarning'; -import QualityGateStatusHeader from '../components/QualityGateStatusHeader'; -import QualityGateStatusPassedView from '../components/QualityGateStatusPassedView'; -import { QualityGateStatusTitle } from '../components/QualityGateStatusTitle'; import ApplicationNonCaycProjectWarning from './ApplicationNonCaycProjectWarning'; import CleanAsYouCodeWarning from './CleanAsYouCodeWarning'; import QualityGatePanelSection from './QualityGatePanelSection'; +import QualityGateStatusHeader from './QualityGateStatusHeader'; +import QualityGateStatusPassedView from './QualityGateStatusPassedView'; +import { QualityGateStatusTitle } from './QualityGateStatusTitle'; export interface QualityGatePanelProps { component: Pick; diff --git a/server/sonar-web/src/main/js/apps/overview/branches/QualityGatePanelSection.tsx b/server/sonar-web/src/main/js/apps/overview/branches/QualityGatePanelSection.tsx index 96a9057782c..d591c286381 100644 --- a/server/sonar-web/src/main/js/apps/overview/branches/QualityGatePanelSection.tsx +++ b/server/sonar-web/src/main/js/apps/overview/branches/QualityGatePanelSection.tsx @@ -27,8 +27,8 @@ import { QualityGateStatusConditionEnhanced, } from '../../../types/quality-gates'; import { QualityGate } from '../../../types/types'; -import QualityGateConditions from '../components/QualityGateConditions'; import ZeroNewIssuesSimplificationGuide from '../components/ZeroNewIssuesSimplificationGuide'; +import QualityGateConditions from './QualityGateConditions'; export interface QualityGatePanelSectionProps { branchLike?: BranchLike; diff --git a/server/sonar-web/src/main/js/apps/overview/components/QualityGateSimplifiedCondition.tsx b/server/sonar-web/src/main/js/apps/overview/branches/QualityGateSimplifiedCondition.tsx similarity index 100% rename from server/sonar-web/src/main/js/apps/overview/components/QualityGateSimplifiedCondition.tsx rename to server/sonar-web/src/main/js/apps/overview/branches/QualityGateSimplifiedCondition.tsx diff --git a/server/sonar-web/src/main/js/apps/overview/components/QualityGateStatusHeader.tsx b/server/sonar-web/src/main/js/apps/overview/branches/QualityGateStatusHeader.tsx similarity index 100% rename from server/sonar-web/src/main/js/apps/overview/components/QualityGateStatusHeader.tsx rename to server/sonar-web/src/main/js/apps/overview/branches/QualityGateStatusHeader.tsx diff --git a/server/sonar-web/src/main/js/apps/overview/components/QualityGateStatusPassedView.tsx b/server/sonar-web/src/main/js/apps/overview/branches/QualityGateStatusPassedView.tsx similarity index 100% rename from server/sonar-web/src/main/js/apps/overview/components/QualityGateStatusPassedView.tsx rename to server/sonar-web/src/main/js/apps/overview/branches/QualityGateStatusPassedView.tsx diff --git a/server/sonar-web/src/main/js/apps/overview/components/QualityGateStatusTitle.tsx b/server/sonar-web/src/main/js/apps/overview/branches/QualityGateStatusTitle.tsx similarity index 100% rename from server/sonar-web/src/main/js/apps/overview/components/QualityGateStatusTitle.tsx rename to server/sonar-web/src/main/js/apps/overview/branches/QualityGateStatusTitle.tsx diff --git a/server/sonar-web/src/main/js/apps/overview/components/SonarLintPromotion.tsx b/server/sonar-web/src/main/js/apps/overview/branches/SonarLintPromotion.tsx similarity index 100% rename from server/sonar-web/src/main/js/apps/overview/components/SonarLintPromotion.tsx rename to server/sonar-web/src/main/js/apps/overview/branches/SonarLintPromotion.tsx diff --git a/server/sonar-web/src/main/js/apps/overview/branches/__tests__/DebtValue-test.tsx b/server/sonar-web/src/main/js/apps/overview/branches/__tests__/DebtValue-test.tsx deleted file mode 100644 index e5286108b20..00000000000 --- a/server/sonar-web/src/main/js/apps/overview/branches/__tests__/DebtValue-test.tsx +++ /dev/null @@ -1,72 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2024 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -import { screen } from '@testing-library/react'; -import * as React from 'react'; -import { mockMainBranch } from '../../../../helpers/mocks/branch-like'; -import { mockComponent } from '../../../../helpers/mocks/component'; -import { mockMeasureEnhanced, mockMetric } from '../../../../helpers/testMocks'; -import { renderComponent } from '../../../../helpers/testReactTestingUtils'; -import { MetricKey } from '../../../../types/metrics'; -import { DebtValue, DebtValueProps } from '../DebtValue'; - -it('should render correctly', () => { - renderDebtValue(); - - expect( - screen.getByLabelText( - 'overview.see_more_details_on_x_of_y.work_duration.x_minutes.1.sqale_index', - ), - ).toBeInTheDocument(); - - expect(screen.getByText('sqale_index')).toBeInTheDocument(); -}); - -it('should render diff metric correctly', () => { - renderDebtValue({ useDiffMetric: true }); - - expect( - screen.getByLabelText( - 'overview.see_more_details_on_x_of_y.work_duration.x_minutes.1.new_technical_debt', - ), - ).toBeInTheDocument(); - - expect(screen.getByText('new_technical_debt')).toBeInTheDocument(); -}); - -it('should handle missing measure', () => { - renderDebtValue({ measures: [] }); - - expect(screen.getByLabelText('no_data')).toBeInTheDocument(); - expect(screen.getByText('metric.sqale_index.name')).toBeInTheDocument(); -}); - -function renderDebtValue(props: Partial = {}) { - return renderComponent( - , - ); -} diff --git a/server/sonar-web/src/main/js/apps/overview/components/__tests__/QualityGateCondition-test.tsx b/server/sonar-web/src/main/js/apps/overview/branches/__tests__/QualityGateCondition-test.tsx similarity index 100% rename from server/sonar-web/src/main/js/apps/overview/components/__tests__/QualityGateCondition-test.tsx rename to server/sonar-web/src/main/js/apps/overview/branches/__tests__/QualityGateCondition-test.tsx diff --git a/server/sonar-web/src/main/js/apps/overview/components/__tests__/QualityGateConditions-test.tsx b/server/sonar-web/src/main/js/apps/overview/branches/__tests__/QualityGateConditions-test.tsx similarity index 100% rename from server/sonar-web/src/main/js/apps/overview/components/__tests__/QualityGateConditions-test.tsx rename to server/sonar-web/src/main/js/apps/overview/branches/__tests__/QualityGateConditions-test.tsx diff --git a/server/sonar-web/src/main/js/apps/overview/components/__tests__/QualityGateSimplifiedCondition-test.tsx b/server/sonar-web/src/main/js/apps/overview/branches/__tests__/QualityGateSimplifiedCondition-test.tsx similarity index 100% rename from server/sonar-web/src/main/js/apps/overview/components/__tests__/QualityGateSimplifiedCondition-test.tsx rename to server/sonar-web/src/main/js/apps/overview/branches/__tests__/QualityGateSimplifiedCondition-test.tsx diff --git a/server/sonar-web/src/main/js/apps/overview/components/__tests__/SonarLintPromotion-test.tsx b/server/sonar-web/src/main/js/apps/overview/branches/__tests__/SonarLintPromotion-test.tsx similarity index 100% rename from server/sonar-web/src/main/js/apps/overview/components/__tests__/SonarLintPromotion-test.tsx rename to server/sonar-web/src/main/js/apps/overview/branches/__tests__/SonarLintPromotion-test.tsx diff --git a/server/sonar-web/src/main/js/apps/overview/components/IssueLabel.tsx b/server/sonar-web/src/main/js/apps/overview/components/IssueLabel.tsx deleted file mode 100644 index 6dd83fcd6d9..00000000000 --- a/server/sonar-web/src/main/js/apps/overview/components/IssueLabel.tsx +++ /dev/null @@ -1,110 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2024 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -import { DrilldownLink, HelperHintIcon, LightLabel } from 'design-system'; -import * as React from 'react'; -import HelpTooltip from '../../../components/controls/HelpTooltip'; -import Tooltip from '../../../components/controls/Tooltip'; -import { getLeakValue } from '../../../components/measure/utils'; -import { DEFAULT_ISSUES_QUERY } from '../../../components/shared/utils'; -import { getBranchLikeQuery } from '../../../helpers/branch-like'; -import { translate, translateWithParameters } from '../../../helpers/l10n'; -import { findMeasure, formatMeasure, localizeMetric } from '../../../helpers/measures'; -import { getComponentIssuesUrl, getComponentSecurityHotspotsUrl } from '../../../helpers/urls'; -import { BranchLike } from '../../../types/branch-like'; -import { ComponentQualifier } from '../../../types/component'; -import { IssueType } from '../../../types/issues'; -import { MetricType } from '../../../types/metrics'; -import { Component, MeasureEnhanced } from '../../../types/types'; -import { getIssueMetricKey } from '../utils'; -import { OverviewDisabledLinkTooltip } from './OverviewDisabledLinkTooltip'; - -export interface IssueLabelProps { - branchLike?: BranchLike; - component: Component; - helpTooltip?: string; - measures: MeasureEnhanced[]; - type: IssueType; - useDiffMetric?: boolean; -} - -export function IssueLabel(props: IssueLabelProps) { - const { branchLike, component, helpTooltip, measures, type, useDiffMetric = false } = props; - const metricKey = getIssueMetricKey(type, useDiffMetric); - const measure = findMeasure(measures, metricKey); - - let value; - - if (measure) { - value = useDiffMetric ? getLeakValue(measure) : measure.value; - } - - const params = { - ...getBranchLikeQuery(branchLike), - inNewCodePeriod: useDiffMetric ? 'true' : 'false', - ...DEFAULT_ISSUES_QUERY, - types: type, - }; - - const url = - type === IssueType.SecurityHotspot - ? getComponentSecurityHotspotsUrl(component.key, params) - : getComponentIssuesUrl(component.key, params); - - const disabled = - component.qualifier === ComponentQualifier.Application && component.needIssueSync; - - const drilldownLinkProps = disabled - ? { disabled, to: '' } - : { - 'aria-label': translateWithParameters( - 'overview.see_list_of_x_y_issues', - value as string, - localizeMetric(metricKey), - ), - to: url, - }; - - return ( -
- {value === undefined ? ( - — - ) : ( - } - > - - {formatMeasure(value, MetricType.ShortInteger)} - - - )} - - {localizeMetric(metricKey)} - - {helpTooltip && ( - - - - )} -
- ); -} - -export default React.memo(IssueLabel); diff --git a/server/sonar-web/src/main/js/apps/overview/components/IssueRating.tsx b/server/sonar-web/src/main/js/apps/overview/components/IssueRating.tsx deleted file mode 100644 index f22c3052bf9..00000000000 --- a/server/sonar-web/src/main/js/apps/overview/components/IssueRating.tsx +++ /dev/null @@ -1,84 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2024 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -/* eslint-disable react/no-unused-prop-types */ - -import { DiscreetLinkBox, MetricsRatingBadge } from 'design-system'; -import * as React from 'react'; -import Tooltip from '../../../components/controls/Tooltip'; -import RatingTooltipContent from '../../../components/measure/RatingTooltipContent'; -import { getLeakValue } from '../../../components/measure/utils'; -import { translateWithParameters } from '../../../helpers/l10n'; -import { findMeasure, formatRating } from '../../../helpers/measures'; -import { getComponentDrilldownUrl } from '../../../helpers/urls'; -import { BranchLike } from '../../../types/branch-like'; -import { IssueType } from '../../../types/issues'; -import { Component, MeasureEnhanced } from '../../../types/types'; -import { getIssueRatingMetricKey } from '../utils'; - -export interface IssueRatingProps { - branchLike?: BranchLike; - component: Component; - measures: MeasureEnhanced[]; - type: IssueType; - useDiffMetric?: boolean; -} - -export function IssueRating(props: IssueRatingProps) { - const { branchLike, component, useDiffMetric = false, measures, type } = props; - const ratingKey = getIssueRatingMetricKey(type, useDiffMetric); - const measure = findMeasure(measures, ratingKey); - const rawValue = measure && (useDiffMetric ? getLeakValue(measure) : measure.value); - const value = formatRating(rawValue); - - if (!ratingKey || !measure) { - return ; - } - - return ( - }> - - {value ? ( - - - - ) : ( - - )} - - - ); -} - -export default IssueRating; - -function NoRating() { - return
–
; -} diff --git a/server/sonar-web/src/main/js/apps/overview/components/LeakPeriodLegend.tsx b/server/sonar-web/src/main/js/apps/overview/components/LeakPeriodLegend.tsx deleted file mode 100644 index 02963e513d1..00000000000 --- a/server/sonar-web/src/main/js/apps/overview/components/LeakPeriodLegend.tsx +++ /dev/null @@ -1,116 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2024 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -import { differenceInDays } from 'date-fns'; -import * as React from 'react'; -import { injectIntl, WrappedComponentProps } from 'react-intl'; -import Tooltip from '../../../components/controls/Tooltip'; -import DateFormatter, { longFormatterOption } from '../../../components/intl/DateFormatter'; -import DateFromNow from '../../../components/intl/DateFromNow'; -import DateTimeFormatter, { formatterOption } from '../../../components/intl/DateTimeFormatter'; -import { translateWithParameters } from '../../../helpers/l10n'; -import { getNewCodePeriodDate, getNewCodePeriodLabel } from '../../../helpers/new-code-period'; -import { NewCodeDefinitionType } from '../../../types/new-code-definition'; -import { Dict, Period } from '../../../types/types'; - -interface Props { - period: Period; -} - -const MODE_INCLUDES_TIME: Dict = { - manual_baseline: true, - SPECIFIC_ANALYSIS: true, -}; - -export class LeakPeriodLegend extends React.PureComponent { - formatDate = (date: string) => { - return this.props.intl.formatDate(date, longFormatterOption); - }; - - formatDateTime = (date: string) => { - return this.props.intl.formatTime(date, formatterOption); - }; - - render() { - const { period } = this.props; - const leakPeriodLabel = getNewCodePeriodLabel( - period, - MODE_INCLUDES_TIME[period.mode] ? this.formatDateTime : this.formatDate, - ); - if (!leakPeriodLabel) { - return null; - } - - if (period.mode === 'days' || period.mode === NewCodeDefinitionType.NumberOfDays) { - return ( -
- {translateWithParameters('overview.new_code_period_x', leakPeriodLabel)} -
- ); - } - - const leakPeriodDate = getNewCodePeriodDate(period); - if (!leakPeriodDate) { - return null; - } - - const formattedDateFunction = (formattedLeakPeriodDate: string) => ( - - {translateWithParameters( - period.mode === 'previous_analysis' - ? 'overview.previous_analysis_on_x' - : 'overview.started_on_x', - formattedLeakPeriodDate, - )} - - ); - - const tooltip = - differenceInDays(new Date(), leakPeriodDate) < 1 ? ( - {formattedDateFunction} - ) : ( - - {formattedDateFunction} - - ); - - return ( - -
- {translateWithParameters('overview.new_code_period_x', leakPeriodLabel)} -
- - {(fromNow) => ( - - {translateWithParameters( - period.mode === 'previous_analysis' - ? 'overview.previous_analysis_x' - : 'overview.started_x', - fromNow, - )} - - )} - -
-
- ); - } -} - -export default injectIntl(LeakPeriodLegend); diff --git a/server/sonar-web/src/main/js/apps/overview/components/__tests__/IssueLabel-test.tsx b/server/sonar-web/src/main/js/apps/overview/components/__tests__/IssueLabel-test.tsx deleted file mode 100644 index fda48d8b007..00000000000 --- a/server/sonar-web/src/main/js/apps/overview/components/__tests__/IssueLabel-test.tsx +++ /dev/null @@ -1,108 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2024 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -import { screen } from '@testing-library/react'; -import * as React from 'react'; -import { mockPullRequest } from '../../../../helpers/mocks/branch-like'; -import { mockComponent } from '../../../../helpers/mocks/component'; -import { mockMeasureEnhanced, mockMetric } from '../../../../helpers/testMocks'; -import { renderComponent } from '../../../../helpers/testReactTestingUtils'; -import { ComponentQualifier } from '../../../../types/component'; -import { IssueType } from '../../../../types/issues'; -import { MetricKey } from '../../../../types/metrics'; -import { IssueLabel, IssueLabelProps } from '../IssueLabel'; - -it('should render correctly for bugs', async () => { - const measures = [ - mockMeasureEnhanced({ metric: mockMetric({ key: MetricKey.bugs }) }), - mockMeasureEnhanced({ metric: mockMetric({ key: MetricKey.new_bugs }) }), - ]; - - const rtl = renderIssueLabel({ measures }); - expect( - await screen.findByRole('link', { - name: 'overview.see_list_of_x_y_issues.1.0.metric.bugs.name', - }), - ).toBeInTheDocument(); - - rtl.unmount(); - - renderIssueLabel({ measures, useDiffMetric: true }); - - expect( - await screen.findByRole('link', { - name: 'overview.see_list_of_x_y_issues.1.0.metric.new_bugs.name', - }), - ).toBeInTheDocument(); -}); - -it('should render correctly for hotspots with tooltip', async () => { - const helpTooltip = 'tooltip text'; - const type = IssueType.SecurityHotspot; - const measures = [ - mockMeasureEnhanced({ metric: mockMetric({ key: MetricKey.security_hotspots }) }), - mockMeasureEnhanced({ metric: mockMetric({ key: MetricKey.new_security_hotspots }) }), - ]; - - renderIssueLabel({ - helpTooltip, - measures, - type, - }); - - expect( - await screen.findByRole('link', { - name: 'overview.see_list_of_x_y_issues.1.0.metric.security_hotspots.name', - }), - ).toBeInTheDocument(); - - expect(screen.getByText('tooltip text')).toBeInTheDocument(); -}); - -it('should render correctly for a re-indexing Application', () => { - const type = IssueType.SecurityHotspot; - const measures = [ - mockMeasureEnhanced({ metric: mockMetric({ key: MetricKey.security_hotspots }) }), - mockMeasureEnhanced({ metric: mockMetric({ key: MetricKey.new_security_hotspots }) }), - ]; - - renderIssueLabel({ - component: mockComponent({ needIssueSync: true, qualifier: ComponentQualifier.Application }), - measures, - type, - }); - - expect( - screen.queryByRole('link', { - name: 'overview.see_list_of_x_y_issues.1.0.metric.security_hotspots.name', - }), - ).not.toBeInTheDocument(); -}); - -function renderIssueLabel(props: Partial = {}) { - return renderComponent( - , - ); -} diff --git a/server/sonar-web/src/main/js/apps/overview/components/__tests__/IssueRating-test.tsx b/server/sonar-web/src/main/js/apps/overview/components/__tests__/IssueRating-test.tsx deleted file mode 100644 index d2d2f5ba9d1..00000000000 --- a/server/sonar-web/src/main/js/apps/overview/components/__tests__/IssueRating-test.tsx +++ /dev/null @@ -1,60 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2024 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -import { screen } from '@testing-library/react'; -import * as React from 'react'; -import { mockPullRequest } from '../../../../helpers/mocks/branch-like'; -import { mockComponent } from '../../../../helpers/mocks/component'; -import { mockMeasureEnhanced, mockMetric } from '../../../../helpers/testMocks'; -import { renderComponent } from '../../../../helpers/testReactTestingUtils'; -import { IssueType } from '../../../../types/issues'; -import { MetricKey } from '../../../../types/metrics'; -import { IssueRating, IssueRatingProps } from '../IssueRating'; - -it('should render correctly for vulnerabilities', async () => { - renderIssueRating({ type: IssueType.Vulnerability, useDiffMetric: true }); - expect(await screen.findByLabelText('metric.has_rating_X.A')).toBeInTheDocument(); - expect(await screen.findByText('metric.security_rating.tooltip.A')).toBeInTheDocument(); -}); - -it('should render correctly if no values are present', async () => { - renderIssueRating({ - measures: [mockMeasureEnhanced({ metric: mockMetric({ key: 'NONE' }) })], - }); - expect(await screen.findByText('–')).toBeInTheDocument(); -}); - -function renderIssueRating(props: Partial = {}) { - return renderComponent( - , - ); -} diff --git a/server/sonar-web/src/main/js/apps/overview/components/__tests__/LeakPeriodLegend-test.tsx b/server/sonar-web/src/main/js/apps/overview/components/__tests__/LeakPeriodLegend-test.tsx deleted file mode 100644 index 0d322aa8fb4..00000000000 --- a/server/sonar-web/src/main/js/apps/overview/components/__tests__/LeakPeriodLegend-test.tsx +++ /dev/null @@ -1,140 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2024 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -import { screen } from '@testing-library/react'; -import { differenceInDays } from 'date-fns'; -import * as React from 'react'; -import { IntlShape } from 'react-intl'; -import { renderComponent } from '../../../../helpers/testReactTestingUtils'; -import { Period } from '../../../../types/types'; -import { LeakPeriodLegend } from '../LeakPeriodLegend'; - -jest.mock('date-fns', () => { - const actual = jest.requireActual('date-fns'); - return { - ...actual, - differenceInDays: jest.fn().mockReturnValue(10), - differenceInYears: jest.fn().mockReturnValue(-9), - }; -}); - -it('10 days', async () => { - renderLeakPeriodLegend({ mode: 'days', parameter: '10' }); - - expect( - await screen.findByText('overview.new_code_period_x.overview.period.days.10'), - ).toBeInTheDocument(); -}); - -it('date', async () => { - renderLeakPeriodLegend({ mode: 'date', parameter: '2013-01-01' }); - - expect( - await screen.findByText('overview.new_code_period_x.overview.period.date.formatted.2013-01-01'), - ).toBeInTheDocument(); - expect(await screen.findByText('overview.started_x.9 years ago')).toBeInTheDocument(); - expect(await screen.findByText(/overview\.started_on_x\..*/)).toBeInTheDocument(); -}); - -it('version', async () => { - renderLeakPeriodLegend({ mode: 'version', parameter: '0.1' }); - - expect( - await screen.findByText('overview.new_code_period_x.overview.period.version.0.1'), - ).toBeInTheDocument(); - expect(await screen.findByText(/overview\.started_x\..*/)).toBeInTheDocument(); - expect(await screen.findByText(/overview\.started_on_x\..*/)).toBeInTheDocument(); -}); - -it('previous_version', async () => { - renderLeakPeriodLegend({ mode: 'previous_version' }); - - expect( - await screen.findByText( - 'overview.new_code_period_x.overview.period.previous_version_only_date', - ), - ).toBeInTheDocument(); - expect(await screen.findByText(/overview\.started_x\..*/)).toBeInTheDocument(); - expect(await screen.findByText(/overview\.started_on_x\..*/)).toBeInTheDocument(); -}); - -it('previous_analysis', async () => { - renderLeakPeriodLegend({ mode: 'previous_analysis' }); - - expect( - await screen.findByText('overview.new_code_period_x.overview.period.previous_analysis.'), - ).toBeInTheDocument(); - expect(await screen.findByText(/overview\.previous_analysis_x\..*/)).toBeInTheDocument(); - expect(await screen.findByText(/overview\.previous_analysis_x\..*/)).toBeInTheDocument(); -}); - -it('manual_baseline', async () => { - const rtl = renderLeakPeriodLegend({ mode: 'manual_baseline' }); - - expect( - await screen.findByText( - /overview\.new_code_period_x\.overview\.period\.manual_baseline\.formattedTime\..*/, - ), - ).toBeInTheDocument(); - expect(await screen.findByText(/overview\.started_x\..*/)).toBeInTheDocument(); - expect(await screen.findByText(/overview\.started_on_x\..*/)).toBeInTheDocument(); - - rtl.unmount(); - renderLeakPeriodLegend({ mode: 'manual_baseline', parameter: '1.1.2' }); - - expect( - await screen.findByText('overview.new_code_period_x.overview.period.manual_baseline.1.1.2'), - ).toBeInTheDocument(); - expect( - await screen.findByText('overview.new_code_period_x.overview.period.manual_baseline.1.1.2'), - ).toBeInTheDocument(); -}); - -it('should render a more precise date', async () => { - (differenceInDays as jest.Mock).mockReturnValueOnce(0); - - renderLeakPeriodLegend({ date: '2018-08-17T00:00:00+0200', mode: 'previous_version' }); - - expect( - await screen.findByText( - 'overview.new_code_period_x.overview.period.previous_version_only_date', - ), - ).toBeInTheDocument(); - expect(await screen.findByText(/overview\.started_x\..*/)).toBeInTheDocument(); - expect(await screen.findByText(/overview\.started_on_x\..*/)).toBeInTheDocument(); -}); - -function renderLeakPeriodLegend(period: Partial = {}) { - return renderComponent( - 'formatted.' + date, - formatTime: (date: string) => 'formattedTime.' + date, - } as IntlShape - } - period={{ - date: '2013-09-22T00:00:00+0200', - index: 0, - mode: 'version', - ...period, - }} - />, - ); -} diff --git a/server/sonar-web/src/main/js/apps/overview/components/BranchQualityGate.tsx b/server/sonar-web/src/main/js/apps/overview/pullRequests/BranchQualityGate.tsx similarity index 100% rename from server/sonar-web/src/main/js/apps/overview/components/BranchQualityGate.tsx rename to server/sonar-web/src/main/js/apps/overview/pullRequests/BranchQualityGate.tsx diff --git a/server/sonar-web/src/main/js/apps/overview/components/BranchQualityGateConditions.tsx b/server/sonar-web/src/main/js/apps/overview/pullRequests/BranchQualityGateConditions.tsx similarity index 100% rename from server/sonar-web/src/main/js/apps/overview/components/BranchQualityGateConditions.tsx rename to server/sonar-web/src/main/js/apps/overview/pullRequests/BranchQualityGateConditions.tsx diff --git a/server/sonar-web/src/main/js/apps/overview/pullRequests/PullRequestOverview.tsx b/server/sonar-web/src/main/js/apps/overview/pullRequests/PullRequestOverview.tsx index 5e7c411c033..476221616e7 100644 --- a/server/sonar-web/src/main/js/apps/overview/pullRequests/PullRequestOverview.tsx +++ b/server/sonar-web/src/main/js/apps/overview/pullRequests/PullRequestOverview.tsx @@ -29,11 +29,11 @@ import { useComponentQualityGateQuery } from '../../../queries/quality-gates'; import { PullRequest } from '../../../types/branch-like'; import { Component } from '../../../types/types'; import { AnalysisStatus } from '../components/AnalysisStatus'; -import BranchQualityGate from '../components/BranchQualityGate'; import IgnoredConditionWarning from '../components/IgnoredConditionWarning'; import ZeroNewIssuesSimplificationGuide from '../components/ZeroNewIssuesSimplificationGuide'; import '../styles.css'; import { PR_METRICS, Status } from '../utils'; +import BranchQualityGate from './BranchQualityGate'; import MeasuresCardPanel from './MeasuresCardPanel'; import PullRequestMetaTopBar from './PullRequestMetaTopBar'; import SonarLintAd from './SonarLintAd'; diff --git a/server/sonar-web/src/main/js/apps/overview/components/__tests__/BranchQualityGate-it.tsx b/server/sonar-web/src/main/js/apps/overview/pullRequests/__tests__/BranchQualityGate-it.tsx similarity index 100% rename from server/sonar-web/src/main/js/apps/overview/components/__tests__/BranchQualityGate-it.tsx rename to server/sonar-web/src/main/js/apps/overview/pullRequests/__tests__/BranchQualityGate-it.tsx -- 2.39.5