From c0b537fa9aabfe07c6e85e5f8379419df806e30a Mon Sep 17 00:00:00 2001 From: Mathieu Suen Date: Tue, 24 Aug 2021 12:19:21 +0200 Subject: [PATCH] SONAR-12019 Fix counter in measure page for Application and Portfolio --- .../components/MeasureContent.tsx | 1 + .../components/MeasureOverview.tsx | 1 + .../MeasureContent-test.tsx.snap | 1 + .../main/js/components/ui/FilesCounter.tsx | 45 ------------------- .../src/main/js/components/ui/PageActions.tsx | 21 +++++++-- .../ui/__tests__/FilesCounter-test.tsx | 30 ------------- .../ui/__tests__/PageActions-test.tsx | 5 ++- .../__snapshots__/FilesCounter-test.tsx.snap | 25 ----------- .../__snapshots__/PageActions-test.tsx.snap | 27 ++++++++--- 9 files changed, 44 insertions(+), 112 deletions(-) delete mode 100644 server/sonar-web/src/main/js/components/ui/FilesCounter.tsx delete mode 100644 server/sonar-web/src/main/js/components/ui/__tests__/FilesCounter-test.tsx delete mode 100644 server/sonar-web/src/main/js/components/ui/__tests__/__snapshots__/FilesCounter-test.tsx.snap diff --git a/server/sonar-web/src/main/js/apps/component-measures/components/MeasureContent.tsx b/server/sonar-web/src/main/js/apps/component-measures/components/MeasureContent.tsx index cbae3063422..a117429d6fa 100644 --- a/server/sonar-web/src/main/js/apps/component-measures/components/MeasureContent.tsx +++ b/server/sonar-web/src/main/js/apps/component-measures/components/MeasureContent.tsx @@ -340,6 +340,7 @@ export default class MeasureContent extends React.PureComponent { /> { } right={ diff --git a/server/sonar-web/src/main/js/apps/component-measures/components/__tests__/__snapshots__/MeasureContent-test.tsx.snap b/server/sonar-web/src/main/js/apps/component-measures/components/__tests__/__snapshots__/MeasureContent-test.tsx.snap index 7f0e11a7aa3..0a0d342d3e4 100644 --- a/server/sonar-web/src/main/js/apps/component-measures/components/__tests__/__snapshots__/MeasureContent-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/component-measures/components/__tests__/__snapshots__/MeasureContent-test.tsx.snap @@ -185,6 +185,7 @@ exports[`should render correctly for a project 1`] = ` view="list" /> diff --git a/server/sonar-web/src/main/js/components/ui/FilesCounter.tsx b/server/sonar-web/src/main/js/components/ui/FilesCounter.tsx deleted file mode 100644 index 60b96c223fa..00000000000 --- a/server/sonar-web/src/main/js/components/ui/FilesCounter.tsx +++ /dev/null @@ -1,45 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2021 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 { translate } from '../../helpers/l10n'; -import { formatMeasure } from '../../helpers/measures'; - -interface Props { - className?: string; - current?: number; - total: number; -} - -export default function FilesCounter({ className, current, total }: Props) { - return ( - - - {current !== undefined && ( - - {formatMeasure(current, 'INT')} - {' / '} - - )} - {formatMeasure(total, 'INT')} - {' '} - {translate('component_measures.files')} - - ); -} diff --git a/server/sonar-web/src/main/js/components/ui/PageActions.tsx b/server/sonar-web/src/main/js/components/ui/PageActions.tsx index 8c2e4106b16..f367fafc18d 100644 --- a/server/sonar-web/src/main/js/components/ui/PageActions.tsx +++ b/server/sonar-web/src/main/js/components/ui/PageActions.tsx @@ -19,16 +19,18 @@ */ import * as React from 'react'; import { translate } from '../../helpers/l10n'; -import FilesCounter from './FilesCounter'; +import { formatMeasure } from '../../helpers/measures'; +import { ComponentQualifier } from '../../types/component'; export interface Props { + componentQualifier?: string; current?: number; showShortcuts?: boolean; total?: number; } export default function PageActions(props: Props) { - const { current, showShortcuts, total = 0 } = props; + const { componentQualifier, current, showShortcuts, total = 0 } = props; return (
@@ -47,9 +49,20 @@ export default function PageActions(props: Props) { )} - {total > 0 && ( + {total > 0 && componentQualifier === ComponentQualifier.Project && (
- + + + {current !== undefined && ( + + {formatMeasure(current, 'INT')} + {' / '} + + )} + {formatMeasure(total, 'INT')} + {' '} + {translate('component_measures.files')} +
)}
diff --git a/server/sonar-web/src/main/js/components/ui/__tests__/FilesCounter-test.tsx b/server/sonar-web/src/main/js/components/ui/__tests__/FilesCounter-test.tsx deleted file mode 100644 index 2f020368cdb..00000000000 --- a/server/sonar-web/src/main/js/components/ui/__tests__/FilesCounter-test.tsx +++ /dev/null @@ -1,30 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2021 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 { shallow } from 'enzyme'; -import * as React from 'react'; -import FilesCounter from '../FilesCounter'; - -it('should display x files on y total', () => { - expect(shallow()).toMatchSnapshot(); -}); - -it('should display only total of files', () => { - expect(shallow()).toMatchSnapshot(); -}); diff --git a/server/sonar-web/src/main/js/components/ui/__tests__/PageActions-test.tsx b/server/sonar-web/src/main/js/components/ui/__tests__/PageActions-test.tsx index 46594418d3a..7ed01f8018a 100644 --- a/server/sonar-web/src/main/js/components/ui/__tests__/PageActions-test.tsx +++ b/server/sonar-web/src/main/js/components/ui/__tests__/PageActions-test.tsx @@ -19,6 +19,7 @@ */ import { shallow } from 'enzyme'; import * as React from 'react'; +import { ComponentQualifier } from '../../../types/component'; import PageActions, { Props } from '../PageActions'; it('should render correctly', () => { @@ -28,5 +29,7 @@ it('should render correctly', () => { }); function shallowRender(props: Partial = {}) { - return shallow(); + return shallow( + + ); } diff --git a/server/sonar-web/src/main/js/components/ui/__tests__/__snapshots__/FilesCounter-test.tsx.snap b/server/sonar-web/src/main/js/components/ui/__tests__/__snapshots__/FilesCounter-test.tsx.snap deleted file mode 100644 index bb01a6121da..00000000000 --- a/server/sonar-web/src/main/js/components/ui/__tests__/__snapshots__/FilesCounter-test.tsx.snap +++ /dev/null @@ -1,25 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`should display only total of files 1`] = ` - - - 123,455 - - - component_measures.files - -`; - -exports[`should display x files on y total 1`] = ` - - - - 12 - / - - 123,455 - - - component_measures.files - -`; diff --git a/server/sonar-web/src/main/js/components/ui/__tests__/__snapshots__/PageActions-test.tsx.snap b/server/sonar-web/src/main/js/components/ui/__tests__/__snapshots__/PageActions-test.tsx.snap index bb220fbacaf..67239391cc4 100644 --- a/server/sonar-web/src/main/js/components/ui/__tests__/__snapshots__/PageActions-test.tsx.snap +++ b/server/sonar-web/src/main/js/components/ui/__tests__/__snapshots__/PageActions-test.tsx.snap @@ -78,10 +78,15 @@ exports[`should render correctly 2`] = `
- + > + + 10 + + + component_measures.files +
`; @@ -93,11 +98,19 @@ exports[`should render correctly 3`] = `
- + > + + + 12 + / + + 120 + + + component_measures.files +
`; -- 2.39.5