From 8d8f01a13a6e960b34dc2c805faeeccbc89c8ab9 Mon Sep 17 00:00:00 2001 From: Jeremy Davis Date: Thu, 9 Jan 2020 14:07:10 +0100 Subject: [PATCH] SONAR-12797 Message when no hotspots found (list of keys) --- .../SecurityHotspotsAppRenderer.tsx | 52 ++++-------- .../SecurityHotspotsAppRenderer-test.tsx.snap | 61 ++------------ .../components/EmptyHotspotsPage.tsx | 64 ++++++++++++++ .../__tests__/EmptyHotspotsPage-test.tsx | 32 +++++++ .../EmptyHotspotsPage-test.tsx.snap | 83 +++++++++++++++++++ .../resources/org/sonar/l10n/core.properties | 2 + 6 files changed, 204 insertions(+), 90 deletions(-) create mode 100644 server/sonar-web/src/main/js/apps/securityHotspots/components/EmptyHotspotsPage.tsx create mode 100644 server/sonar-web/src/main/js/apps/securityHotspots/components/__tests__/EmptyHotspotsPage-test.tsx create mode 100644 server/sonar-web/src/main/js/apps/securityHotspots/components/__tests__/__snapshots__/EmptyHotspotsPage-test.tsx.snap diff --git a/server/sonar-web/src/main/js/apps/securityHotspots/SecurityHotspotsAppRenderer.tsx b/server/sonar-web/src/main/js/apps/securityHotspots/SecurityHotspotsAppRenderer.tsx index d22c07cba21..3e3b800bc96 100644 --- a/server/sonar-web/src/main/js/apps/securityHotspots/SecurityHotspotsAppRenderer.tsx +++ b/server/sonar-web/src/main/js/apps/securityHotspots/SecurityHotspotsAppRenderer.tsx @@ -19,16 +19,20 @@ */ import * as React from 'react'; import { Helmet } from 'react-helmet-async'; -import { Link } from 'react-router'; import DeferredSpinner from 'sonar-ui-common/components/ui/DeferredSpinner'; import { translate } from 'sonar-ui-common/helpers/l10n'; -import { getBaseUrl } from 'sonar-ui-common/helpers/urls'; import A11ySkipTarget from '../../app/components/a11y/A11ySkipTarget'; import Suggestions from '../../app/components/embed-docs-modal/Suggestions'; import ScreenPositionHelper from '../../components/common/ScreenPositionHelper'; import { isBranch } from '../../helpers/branch-like'; import { BranchLike } from '../../types/branch-like'; -import { HotspotFilters, HotspotUpdate, RawHotspot } from '../../types/security-hotspots'; +import { + HotspotFilters, + HotspotStatusFilter, + HotspotUpdate, + RawHotspot +} from '../../types/security-hotspots'; +import EmptyHotspotsPage from './components/EmptyHotspotsPage'; import FilterBar from './components/FilterBar'; import HotspotList from './components/HotspotList'; import HotspotViewer from './components/HotspotViewer'; @@ -51,37 +55,6 @@ export interface SecurityHotspotsAppRendererProps { securityCategories: T.StandardSecurityCategories; } -function renderNoHotspots(filtered: boolean) { - return ( -
- {translate('hotspots.page')} -

- {filtered - ? translate('hotspots.no_hotspots_for_filters.title') - : translate('hotspots.no_hotspots.title')} -

-
- {filtered - ? translate('hotspots.no_hotspots_for_filters.description') - : translate('hotspots.no_hotspots.description')} -
- {!filtered && ( - - {translate('hotspots.learn_more')} - - )} -
- ); -} - export default function SecurityHotspotsAppRenderer(props: SecurityHotspotsAppRendererProps) { const { branchLike, @@ -117,9 +90,14 @@ export default function SecurityHotspotsAppRenderer(props: SecurityHotspotsAppRe ) : ( <> {hotspots.length === 0 ? ( - renderNoHotspots( - filters.assignedToMe || (filters.sinceLeakPeriod && isBranch(branchLike)) - ) + ) : (
diff --git a/server/sonar-web/src/main/js/apps/securityHotspots/__tests__/__snapshots__/SecurityHotspotsAppRenderer-test.tsx.snap b/server/sonar-web/src/main/js/apps/securityHotspots/__tests__/__snapshots__/SecurityHotspotsAppRenderer-test.tsx.snap index c24e160260d..a99469f0413 100644 --- a/server/sonar-web/src/main/js/apps/securityHotspots/__tests__/__snapshots__/SecurityHotspotsAppRenderer-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/securityHotspots/__tests__/__snapshots__/SecurityHotspotsAppRenderer-test.tsx.snap @@ -209,39 +209,10 @@ exports[`should render correctly: no hotspots 1`] = ` -
- hotspots.page -

- hotspots.no_hotspots.title -

-
- hotspots.no_hotspots.description -
- - hotspots.learn_more - -
+
`; @@ -267,26 +238,10 @@ exports[`should render correctly: no hotspots with filters 1`] = ` -
- hotspots.page -

- hotspots.no_hotspots_for_filters.title -

-
- hotspots.no_hotspots_for_filters.description -
-
+ `; diff --git a/server/sonar-web/src/main/js/apps/securityHotspots/components/EmptyHotspotsPage.tsx b/server/sonar-web/src/main/js/apps/securityHotspots/components/EmptyHotspotsPage.tsx new file mode 100644 index 00000000000..a178c3bbb8b --- /dev/null +++ b/server/sonar-web/src/main/js/apps/securityHotspots/components/EmptyHotspotsPage.tsx @@ -0,0 +1,64 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 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 { Link } from 'react-router'; +import { translate } from 'sonar-ui-common/helpers/l10n'; +import { getBaseUrl } from 'sonar-ui-common/helpers/urls'; + +export interface EmptyHotspotsPageProps { + filtered: boolean; + isStaticListOfHotspots: boolean; +} + +export default function EmptyHotspotsPage(props: EmptyHotspotsPageProps) { + const { filtered, isStaticListOfHotspots } = props; + + let translationRoot; + if (isStaticListOfHotspots) { + translationRoot = 'no_hotspots_for_keys'; + } else if (filtered) { + translationRoot = 'no_hotspots_for_filters'; + } else { + translationRoot = 'no_hotspots'; + } + + return ( +
+ {translate('hotspots.page')} +

{translate(`hotspots.${translationRoot}.title`)}

+
+ {translate(`hotspots.${translationRoot}.description`)} +
+ {!(filtered || isStaticListOfHotspots) && ( + + {translate('hotspots.learn_more')} + + )} +
+ ); +} diff --git a/server/sonar-web/src/main/js/apps/securityHotspots/components/__tests__/EmptyHotspotsPage-test.tsx b/server/sonar-web/src/main/js/apps/securityHotspots/components/__tests__/EmptyHotspotsPage-test.tsx new file mode 100644 index 00000000000..bbeb14429c5 --- /dev/null +++ b/server/sonar-web/src/main/js/apps/securityHotspots/components/__tests__/EmptyHotspotsPage-test.tsx @@ -0,0 +1,32 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 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 EmptyHotspotsPage, { EmptyHotspotsPageProps } from '../EmptyHotspotsPage'; + +it('should render correctly', () => { + expect(shallowRender()).toMatchSnapshot(); + expect(shallowRender({ filtered: true })).toMatchSnapshot('filtered'); + expect(shallowRender({ isStaticListOfHotspots: true })).toMatchSnapshot('keys'); +}); + +function shallowRender(props: Partial = {}) { + return shallow(); +} diff --git a/server/sonar-web/src/main/js/apps/securityHotspots/components/__tests__/__snapshots__/EmptyHotspotsPage-test.tsx.snap b/server/sonar-web/src/main/js/apps/securityHotspots/components/__tests__/__snapshots__/EmptyHotspotsPage-test.tsx.snap new file mode 100644 index 00000000000..b90efd1eb50 --- /dev/null +++ b/server/sonar-web/src/main/js/apps/securityHotspots/components/__tests__/__snapshots__/EmptyHotspotsPage-test.tsx.snap @@ -0,0 +1,83 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`should render correctly 1`] = ` +
+ hotspots.page +

+ hotspots.no_hotspots.title +

+
+ hotspots.no_hotspots.description +
+ + hotspots.learn_more + +
+`; + +exports[`should render correctly: filtered 1`] = ` +
+ hotspots.page +

+ hotspots.no_hotspots_for_filters.title +

+
+ hotspots.no_hotspots_for_filters.description +
+
+`; + +exports[`should render correctly: keys 1`] = ` +
+ hotspots.page +

+ hotspots.no_hotspots_for_keys.title +

+
+ hotspots.no_hotspots_for_keys.description +
+
+`; diff --git a/sonar-core/src/main/resources/org/sonar/l10n/core.properties b/sonar-core/src/main/resources/org/sonar/l10n/core.properties index 13856539bd7..0e17f23518b 100644 --- a/sonar-core/src/main/resources/org/sonar/l10n/core.properties +++ b/sonar-core/src/main/resources/org/sonar/l10n/core.properties @@ -649,6 +649,8 @@ hotspots.no_hotspots.title=There are no Security Hotspots to review. hotspots.no_hotspots.description=Next time you analyse a piece of code that contains a potential security risk, it will show up here. hotspots.no_hotspots_for_filters.title=We couldn't find any results matching the selected criteria. hotspots.no_hotspots_for_filters.description=Try changing the filters to get some results. +hotspots.no_hotspots_for_keys.title=The requested hotspots no longer exist. +hotspots.no_hotspots_for_keys.description=They have been closed because the code involved has been changed or removed. hotspots.learn_more=Learn more about Security Hotspots hotspots.list_title={0} Security Hotspots hotspots.list_title.TO_REVIEW={0} Security Hotspots to review -- 2.39.5