diff options
author | 7PH <benjamin.raymond@sonarsource.com> | 2024-01-29 14:21:35 +0100 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2024-01-31 20:03:37 +0000 |
commit | 5e66c60c4cc35a6023413324f56c46411e326d54 (patch) | |
tree | ae5fac28a5d41787b3f24052a58675ab78418446 /server | |
parent | 2f6c01779fcb9068e32e2659d5c8d5b11019fa57 (diff) | |
download | sonarqube-5e66c60c4cc35a6023413324f56c46411e326d54.tar.gz sonarqube-5e66c60c4cc35a6023413324f56c46411e326d54.zip |
SONAR-21455 Drop dead code & Re-organize branch/pr overview components to relevant folders
Diffstat (limited to 'server')
29 files changed, 8 insertions, 882 deletions
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 ? ( - <span aria-label={translate('no_data')} className="overview-measures-empty-value" /> - ) : ( - <DrilldownLink - ariaLabel={translateWithParameters( - 'overview.see_more_details_on_x_of_y', - formattedValue, - metricName, - )} - branchLike={branchLike} - className="overview-measures-value text-light" - component={component.key} - metric={metricKey} - > - {formattedValue} - </DrilldownLink> - )} - <span className="big-spacer-left">{metricName}</span> - </> - ); -} - -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 <span>–</span>; - } - - const url = getComponentDrilldownUrl({ - branchLike, - componentKey: component.key, - metric, - }); - - return ( - <span> - <DrilldownLink - aria-label={translateWithParameters( - 'overview.see_more_details_on_x_y', - measure.value, - localizeMetric(metric), - )} - to={url} - > - {formatMeasure(measure.value, MetricType.ShortInteger)} - </DrilldownLink> - </span> - ); -} - -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<Props & React.HTMLAttributes<HTMLDivElement>>, -) { - const { category, children, rating, ...attributes } = props; - - return ( - <div className="sw-flex sw-justify-between sw-items-center" {...attributes}> - <div className="sw-flex sw-flex-col sw-justify-between"> - <div className="sw-body-sm-highlight sw-flex sw-items-center">{category}</div> - - <div className="sw-mt-3">{children}</div> - </div> - - <div>{rating}</div> - </div> - ); -} 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 index dda75f63084..dda75f63084 100644 --- a/server/sonar-web/src/main/js/apps/overview/components/QualityGateCondition.tsx +++ b/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 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<QualityGateConditionsProps>) { 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<Component, 'key' | 'qualifier' | 'qualityGate'>; 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 index d4172a7110a..d4172a7110a 100644 --- a/server/sonar-web/src/main/js/apps/overview/components/QualityGateSimplifiedCondition.tsx +++ b/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 index c4eee2fd3ae..c4eee2fd3ae 100644 --- a/server/sonar-web/src/main/js/apps/overview/components/QualityGateStatusHeader.tsx +++ b/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 index 2a60ea651cb..2a60ea651cb 100644 --- a/server/sonar-web/src/main/js/apps/overview/components/QualityGateStatusPassedView.tsx +++ b/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 index 14e985cb86b..14e985cb86b 100644 --- a/server/sonar-web/src/main/js/apps/overview/components/QualityGateStatusTitle.tsx +++ b/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 index dbcf3ecb876..dbcf3ecb876 100644 --- a/server/sonar-web/src/main/js/apps/overview/components/SonarLintPromotion.tsx +++ b/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<DebtValueProps> = {}) { - return renderComponent( - <DebtValue - branchLike={mockMainBranch()} - component={mockComponent()} - measures={[ - mockMeasureEnhanced({ metric: mockMetric({ key: MetricKey.sqale_index }) }), - mockMeasureEnhanced({ metric: mockMetric({ key: MetricKey.new_technical_debt }) }), - ]} - {...props} - />, - ); -} 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 index 85d384bbae9..85d384bbae9 100644 --- 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 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 index 46697d0246d..46697d0246d 100644 --- 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 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 index fffc444c8d4..fffc444c8d4 100644 --- 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 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 index 25f8906e358..25f8906e358 100644 --- 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 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 ( - <div className="sw-body-md sw-flex sw-items-center"> - {value === undefined ? ( - <LightLabel aria-label={translate('no_data')}> — </LightLabel> - ) : ( - <Tooltip - classNameSpace={disabled ? 'tooltip' : 'sw-hidden'} - overlay={<OverviewDisabledLinkTooltip />} - > - <DrilldownLink className="it__overview-measures-value" {...drilldownLinkProps}> - {formatMeasure(value, MetricType.ShortInteger)} - </DrilldownLink> - </Tooltip> - )} - - <LightLabel className="sw-mx-2">{localizeMetric(metricKey)}</LightLabel> - - {helpTooltip && ( - <HelpTooltip overlay={helpTooltip}> - <HelperHintIcon aria-label={helpTooltip} /> - </HelpTooltip> - )} - </div> - ); -} - -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 <NoRating />; - } - - return ( - <Tooltip overlay={rawValue && <RatingTooltipContent metricKey={ratingKey} value={rawValue} />}> - <span> - {value ? ( - <DiscreetLinkBox - to={getComponentDrilldownUrl({ - branchLike, - componentKey: component.key, - metric: ratingKey, - listView: true, - })} - > - <MetricsRatingBadge - label={translateWithParameters('metric.has_rating_X', value)} - rating={value} - size="md" - /> - </DiscreetLinkBox> - ) : ( - <NoRating /> - )} - </span> - </Tooltip> - ); -} - -export default IssueRating; - -function NoRating() { - return <div className="sw-w-8 sw-h-8 sw-flex sw-justify-center sw-items-center">–</div>; -} 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<boolean> = { - manual_baseline: true, - SPECIFIC_ANALYSIS: true, -}; - -export class LeakPeriodLegend extends React.PureComponent<Props & WrappedComponentProps> { - 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 ( - <div className="overview-legend overview-legend-spaced-line"> - {translateWithParameters('overview.new_code_period_x', leakPeriodLabel)} - </div> - ); - } - - const leakPeriodDate = getNewCodePeriodDate(period); - if (!leakPeriodDate) { - return null; - } - - const formattedDateFunction = (formattedLeakPeriodDate: string) => ( - <span> - {translateWithParameters( - period.mode === 'previous_analysis' - ? 'overview.previous_analysis_on_x' - : 'overview.started_on_x', - formattedLeakPeriodDate, - )} - </span> - ); - - const tooltip = - differenceInDays(new Date(), leakPeriodDate) < 1 ? ( - <DateTimeFormatter date={leakPeriodDate}>{formattedDateFunction}</DateTimeFormatter> - ) : ( - <DateFormatter date={leakPeriodDate} long> - {formattedDateFunction} - </DateFormatter> - ); - - return ( - <Tooltip overlay={tooltip}> - <div className="overview-legend"> - {translateWithParameters('overview.new_code_period_x', leakPeriodLabel)} - <br /> - <DateFromNow date={leakPeriodDate}> - {(fromNow) => ( - <span className="note"> - {translateWithParameters( - period.mode === 'previous_analysis' - ? 'overview.previous_analysis_x' - : 'overview.started_x', - fromNow, - )} - </span> - )} - </DateFromNow> - </div> - </Tooltip> - ); - } -} - -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<IssueLabelProps> = {}) { - return renderComponent( - <IssueLabel - branchLike={mockPullRequest()} - component={mockComponent()} - measures={[]} - type={IssueType.Bug} - {...props} - />, - ); -} 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<IssueRatingProps> = {}) { - return renderComponent( - <IssueRating - branchLike={mockPullRequest()} - component={mockComponent()} - measures={[ - mockMeasureEnhanced({ metric: mockMetric({ key: MetricKey.new_reliability_rating }) }), - mockMeasureEnhanced({ metric: mockMetric({ key: MetricKey.reliability_rating }) }), - mockMeasureEnhanced({ metric: mockMetric({ key: MetricKey.new_maintainability_rating }) }), - mockMeasureEnhanced({ metric: mockMetric({ key: MetricKey.sqale_rating }) }), - mockMeasureEnhanced({ metric: mockMetric({ key: MetricKey.new_security_rating }) }), - mockMeasureEnhanced({ metric: mockMetric({ key: MetricKey.security_rating }) }), - ]} - type={IssueType.Bug} - {...props} - />, - ); -} 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<any>).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<Period> = {}) { - return renderComponent( - <LeakPeriodLegend - intl={ - { - formatDate: (date: string) => '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 index 2cb03cfc314..2cb03cfc314 100644 --- a/server/sonar-web/src/main/js/apps/overview/components/BranchQualityGate.tsx +++ b/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 index d3bfaa0bdad..d3bfaa0bdad 100644 --- a/server/sonar-web/src/main/js/apps/overview/components/BranchQualityGateConditions.tsx +++ b/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 index a841f4d4436..a841f4d4436 100644 --- 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 |