From 1a3ff367b206fefd992efc8abc86e284c233fa29 Mon Sep 17 00:00:00 2001 From: Jeremy Davis Date: Mon, 6 Jan 2020 17:30:48 +0100 Subject: [PATCH] SONAR-12717 Only first category starts expanded --- .../SecurityHotspotsAppRenderer.tsx | 90 +++--- .../SecurityHotspotsAppRenderer-test.tsx.snap | 288 ++++++++---------- .../components/HotspotCategory.tsx | 12 +- .../components/HotspotList.tsx | 7 +- .../__tests__/HotspotCategory-test.tsx | 6 +- .../HotspotCategory-test.tsx.snap | 32 +- .../__snapshots__/HotspotList-test.tsx.snap | 64 +--- 7 files changed, 241 insertions(+), 258 deletions(-) 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 4e815b87701..527dc9b8c98 100644 --- a/server/sonar-web/src/main/js/apps/securityHotspots/SecurityHotspotsAppRenderer.tsx +++ b/server/sonar-web/src/main/js/apps/securityHotspots/SecurityHotspotsAppRenderer.tsx @@ -81,54 +81,58 @@ export default function SecurityHotspotsAppRenderer(props: SecurityHotspotsAppRe - - {hotspots.length === 0 ? ( -
- {translate('hotspots.page')} -

{translate('hotspots.no_hotspots.title')}

-
- {translate('hotspots.no_hotspots.description')} -
- - {translate('hotspots.learn_more')} - -
- ) : ( -
-
- + ) : ( + <> + {hotspots.length === 0 ? ( +
+ {translate('hotspots.page')} +

{translate('hotspots.no_hotspots.title')}

+
+ {translate('hotspots.no_hotspots.description')} +
+ + {translate('hotspots.learn_more')} +
-
- {selectedHotspotKey && ( - +
+ - )} +
+
+ {selectedHotspotKey && ( + + )} +
-
- )} - + )} + + )}
)} 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 c9336052d04..01dc28affce 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 @@ -44,45 +44,39 @@ exports[`should render correctly 2`] = ` - + hotspots.page +

+ hotspots.no_hotspots.title +

- hotspots.page -

- hotspots.no_hotspots.title -

-
- hotspots.no_hotspots.description -
- - hotspots.learn_more - + hotspots.no_hotspots.description
-
+ + hotspots.learn_more + + `; @@ -108,66 +102,60 @@ exports[`should render correctly with hotspots 1`] = ` -
-
- -
-
- +
+
`; @@ -193,73 +181,67 @@ exports[`should render correctly with hotspots 2`] = ` -
-
- -
-
- -
+ +
+
+
-
+ `; diff --git a/server/sonar-web/src/main/js/apps/securityHotspots/components/HotspotCategory.tsx b/server/sonar-web/src/main/js/apps/securityHotspots/components/HotspotCategory.tsx index 91b142503e4..be732964b3b 100644 --- a/server/sonar-web/src/main/js/apps/securityHotspots/components/HotspotCategory.tsx +++ b/server/sonar-web/src/main/js/apps/securityHotspots/components/HotspotCategory.tsx @@ -25,19 +25,17 @@ import { RawHotspot } from '../../../types/security-hotspots'; import HotspotListItem from './HotspotListItem'; export interface HotspotCategoryProps { - category: { - key: string; - title: string; - }; hotspots: RawHotspot[]; onHotspotClick: (key: string) => void; selectedHotspotKey: string | undefined; + startsExpanded: boolean; + title: string; } export default function HotspotCategory(props: HotspotCategoryProps) { - const { category, hotspots, selectedHotspotKey } = props; + const { hotspots, selectedHotspotKey, startsExpanded, title } = props; - const [expanded, setExpanded] = React.useState(true); + const [expanded, setExpanded] = React.useState(startsExpanded); if (hotspots.length < 1) { return null; @@ -51,7 +49,7 @@ export default function HotspotCategory(props: HotspotCategoryProps) { className="hotspot-category-header display-flex-space-between display-flex-center" href="#" onClick={() => setExpanded(!expanded)}> - {category.title} + {title} {hotspots.length} {expanded ? ( diff --git a/server/sonar-web/src/main/js/apps/securityHotspots/components/HotspotList.tsx b/server/sonar-web/src/main/js/apps/securityHotspots/components/HotspotList.tsx index d6b31fb2042..286e9a30b85 100644 --- a/server/sonar-web/src/main/js/apps/securityHotspots/components/HotspotList.tsx +++ b/server/sonar-web/src/main/js/apps/securityHotspots/components/HotspotList.tsx @@ -73,7 +73,7 @@ export default function HotspotList(props: HotspotListProps) { )}
    - {groupedHotspots.map(riskGroup => ( + {groupedHotspots.map((riskGroup, groupIndex) => (
  • {translate('hotspots.risk_exposure')} @@ -82,13 +82,14 @@ export default function HotspotList(props: HotspotListProps) {
      - {riskGroup.categories.map(cat => ( + {riskGroup.categories.map((cat, catIndex) => (
    • ))} diff --git a/server/sonar-web/src/main/js/apps/securityHotspots/components/__tests__/HotspotCategory-test.tsx b/server/sonar-web/src/main/js/apps/securityHotspots/components/__tests__/HotspotCategory-test.tsx index 757850291aa..99a432c2b5d 100644 --- a/server/sonar-web/src/main/js/apps/securityHotspots/components/__tests__/HotspotCategory-test.tsx +++ b/server/sonar-web/src/main/js/apps/securityHotspots/components/__tests__/HotspotCategory-test.tsx @@ -23,12 +23,13 @@ import { mockRawHotspot } from '../../../../helpers/mocks/security-hotspots'; import HotspotCategory, { HotspotCategoryProps } from '../HotspotCategory'; it('should render correctly', () => { - expect(shallowRender()).toMatchSnapshot(); + expect(shallowRender()).toMatchSnapshot('empty'); }); it('should render correctly with hotspots', () => { const hotspots = [mockRawHotspot({ key: 'h1' }), mockRawHotspot({ key: 'h2' })]; expect(shallowRender({ hotspots })).toMatchSnapshot(); + expect(shallowRender({ hotspots, startsExpanded: false })).toMatchSnapshot('collapsed'); }); it('should handle collapse and expand', () => { @@ -46,10 +47,11 @@ it('should handle collapse and expand', () => { function shallowRender(props: Partial = {}) { return shallow( ); diff --git a/server/sonar-web/src/main/js/apps/securityHotspots/components/__tests__/__snapshots__/HotspotCategory-test.tsx.snap b/server/sonar-web/src/main/js/apps/securityHotspots/components/__tests__/__snapshots__/HotspotCategory-test.tsx.snap index 66a40e18e94..a075d958dfe 100644 --- a/server/sonar-web/src/main/js/apps/securityHotspots/components/__tests__/__snapshots__/HotspotCategory-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/securityHotspots/components/__tests__/__snapshots__/HotspotCategory-test.tsx.snap @@ -83,8 +83,6 @@ exports[`should handle collapse and expand 2`] = ` `; -exports[`should render correctly 1`] = `""`; - exports[`should render correctly with hotspots 1`] = `
      `; + +exports[`should render correctly with hotspots: collapsed 1`] = ` + +`; + +exports[`should render correctly: empty 1`] = `""`; diff --git a/server/sonar-web/src/main/js/apps/securityHotspots/components/__tests__/__snapshots__/HotspotList-test.tsx.snap b/server/sonar-web/src/main/js/apps/securityHotspots/components/__tests__/__snapshots__/HotspotList-test.tsx.snap index 872890c7764..07c77d60fa5 100644 --- a/server/sonar-web/src/main/js/apps/securityHotspots/components/__tests__/__snapshots__/HotspotList-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/securityHotspots/components/__tests__/__snapshots__/HotspotList-test.tsx.snap @@ -105,12 +105,6 @@ exports[`should render correctly with hotspots: no pagination 1`] = ` key="cat1" >
    @@ -192,12 +184,6 @@ exports[`should render correctly with hotspots: no pagination 1`] = ` key="cat1" >
@@ -318,12 +302,6 @@ exports[`should render correctly with hotspots: pagination 1`] = ` key="cat1" >
  • @@ -405,12 +381,6 @@ exports[`should render correctly with hotspots: pagination 1`] = ` key="cat1" >
  • -- 2.39.5