From 5d495f294e758d34ed5263233e9d812e19a2d926 Mon Sep 17 00:00:00 2001 From: guillaume-peoch-sonarsource Date: Fri, 6 Jan 2023 16:13:31 +0100 Subject: [PATCH] SONAR-18166 User can't display all secondary location when coming from the code tab --- .../security-hotspots/SecurityHotspotsApp.tsx | 23 +------------------ .../SecurityHotspotsAppRenderer.tsx | 2 -- .../__tests__/SecurityHotspotsApp-test.tsx | 9 -------- .../SecurityHotspotsAppRenderer-test.tsx | 11 --------- .../SecurityHotspotsApp-test.tsx.snap | 1 - .../SecurityHotspotsAppRenderer-test.tsx.snap | 4 ---- .../components/FilterBar.tsx | 12 ++++------ .../components/__tests__/FilterBar-test.tsx | 7 ------ .../__snapshots__/FilterBar-test.tsx.snap | 14 ++++++----- server/sonar-web/src/main/js/helpers/urls.ts | 7 ++++++ 10 files changed, 20 insertions(+), 70 deletions(-) diff --git a/server/sonar-web/src/main/js/apps/security-hotspots/SecurityHotspotsApp.tsx b/server/sonar-web/src/main/js/apps/security-hotspots/SecurityHotspotsApp.tsx index d8758c9713c..91b675e28aa 100644 --- a/server/sonar-web/src/main/js/apps/security-hotspots/SecurityHotspotsApp.tsx +++ b/server/sonar-web/src/main/js/apps/security-hotspots/SecurityHotspotsApp.tsx @@ -24,7 +24,7 @@ import { getSecurityHotspotList, getSecurityHotspots } from '../../api/security- import withBranchStatusActions from '../../app/components/branch-status/withBranchStatusActions'; import withComponentContext from '../../app/components/componentContext/withComponentContext'; import withCurrentUserContext from '../../app/components/current-user/withCurrentUserContext'; -import { Location, Router, withRouter } from '../../components/hoc/withRouter'; +import { Location, withRouter } from '../../components/hoc/withRouter'; import { getLeakValue } from '../../components/measure/utils'; import { getBranchLikeQuery, isPullRequest, isSameBranchLike } from '../../helpers/branch-like'; import { isInput } from '../../helpers/keyboardEventHelpers'; @@ -55,7 +55,6 @@ interface OwnProps { currentUser: CurrentUser; component: Component; location: Location; - router: Router; } type Props = DispatchProps & OwnProps; @@ -450,25 +449,6 @@ export class SecurityHotspotsApp extends React.PureComponent { .then(this.fetchSecurityHotspotsReviewed); }; - handleShowAllHotspots = () => { - this.props.router.push({ - ...this.props.location, - query: { - ...this.props.location.query, - hotspots: undefined, - [SecurityStandard.CWE]: undefined, - [SecurityStandard.OWASP_TOP10]: undefined, - [SecurityStandard.SANS_TOP25]: undefined, - [SecurityStandard.SONARSOURCE]: undefined, - [SecurityStandard.OWASP_TOP10_2021]: undefined, - [SecurityStandard.PCI_DSS_3_2]: undefined, - [SecurityStandard.PCI_DSS_4_0]: undefined, - [SecurityStandard.OWASP_ASVS_4_0]: undefined, - file: undefined, - }, - }); - }; - handleLoadMore = () => { const { hotspots, hotspotsPageIndex: hotspotPages } = this.state; @@ -542,7 +522,6 @@ export class SecurityHotspotsApp extends React.PureComponent { onChangeFilters={this.handleChangeFilters} onHotspotClick={this.handleHotspotClick} onLoadMore={this.handleLoadMore} - onShowAllHotspots={this.handleShowAllHotspots} onSwitchStatusFilter={this.handleChangeStatusFilter} onUpdateHotspot={this.handleHotspotUpdate} onLocationClick={this.handleLocationClick} diff --git a/server/sonar-web/src/main/js/apps/security-hotspots/SecurityHotspotsAppRenderer.tsx b/server/sonar-web/src/main/js/apps/security-hotspots/SecurityHotspotsAppRenderer.tsx index c4fc16bbe4a..ba8b7c1bd9f 100644 --- a/server/sonar-web/src/main/js/apps/security-hotspots/SecurityHotspotsAppRenderer.tsx +++ b/server/sonar-web/src/main/js/apps/security-hotspots/SecurityHotspotsAppRenderer.tsx @@ -58,7 +58,6 @@ export interface SecurityHotspotsAppRendererProps { onHotspotClick: (hotspot: RawHotspot) => void; onLocationClick: (index?: number) => void; onLoadMore: () => void; - onShowAllHotspots: () => void; onSwitchStatusFilter: (option: HotspotStatusFilter) => void; onUpdateHotspot: (hotspotKey: string) => Promise; selectedHotspot?: RawHotspot; @@ -113,7 +112,6 @@ export default function SecurityHotspotsAppRenderer(props: SecurityHotspotsAppRe loadingMeasure={loadingMeasure} onBranch={isBranch(branchLike)} onChangeFilters={props.onChangeFilters} - onShowAllHotspots={props.onShowAllHotspots} /> {loading && ( diff --git a/server/sonar-web/src/main/js/apps/security-hotspots/__tests__/SecurityHotspotsApp-test.tsx b/server/sonar-web/src/main/js/apps/security-hotspots/__tests__/SecurityHotspotsApp-test.tsx index cdbc44541e3..7b0fbfa3c84 100644 --- a/server/sonar-web/src/main/js/apps/security-hotspots/__tests__/SecurityHotspotsApp-test.tsx +++ b/server/sonar-web/src/main/js/apps/security-hotspots/__tests__/SecurityHotspotsApp-test.tsx @@ -31,7 +31,6 @@ import { mockFlowLocation, mockLocation, mockLoggedInUser, - mockRouter, } from '../../../helpers/testMocks'; import { mockEvent, waitAndUpdate } from '../../../helpers/testUtils'; import { SecurityStandard } from '../../../types/security'; @@ -162,10 +161,8 @@ it('should load data correctly when hotspot key list is forced', async () => { }); const location = mockLocation({ query: { hotspots: hotspotKeys.join() } }); - const router = mockRouter(); const wrapper = shallowRender({ location, - router, }); await waitAndUpdate(wrapper); @@ -179,11 +176,6 @@ it('should load data correctly when hotspot key list is forced', async () => { // Reset (getSecurityHotspots as jest.Mock).mockClear(); (getSecurityHotspotList as jest.Mock).mockClear(); - wrapper.find(SecurityHotspotsAppRenderer).props().onShowAllHotspots(); - expect(router.push).toHaveBeenCalledWith({ - ...location, - query: { ...location.query, hotspots: undefined }, - }); // Simulate a new location wrapper.setProps({ @@ -476,7 +468,6 @@ function shallowRender(props: Partial = {}) { component={mockComponent()} currentUser={mockCurrentUser()} location={mockLocation()} - router={mockRouter()} {...props} /> ); diff --git a/server/sonar-web/src/main/js/apps/security-hotspots/__tests__/SecurityHotspotsAppRenderer-test.tsx b/server/sonar-web/src/main/js/apps/security-hotspots/__tests__/SecurityHotspotsAppRenderer-test.tsx index 144d42916b4..1e0594d62cb 100644 --- a/server/sonar-web/src/main/js/apps/security-hotspots/__tests__/SecurityHotspotsAppRenderer-test.tsx +++ b/server/sonar-web/src/main/js/apps/security-hotspots/__tests__/SecurityHotspotsAppRenderer-test.tsx @@ -25,7 +25,6 @@ import { mockRawHotspot, mockStandards } from '../../../helpers/mocks/security-h import { scrollToElement } from '../../../helpers/scrolling'; import { SecurityStandard } from '../../../types/security'; import { HotspotStatusFilter } from '../../../types/security-hotspots'; -import FilterBar from '../components/FilterBar'; import SecurityHotspotsAppRenderer, { SecurityHotspotsAppRendererProps, } from '../SecurityHotspotsAppRenderer'; @@ -92,15 +91,6 @@ it('should render correctly when filtered by category or cwe', () => { ).toMatchSnapshot('category'); }); -it('should properly propagate the "show all" call', () => { - const onShowAllHotspots = jest.fn(); - const wrapper = shallowRender({ onShowAllHotspots }); - - wrapper.find(FilterBar).props().onShowAllHotspots(); - - expect(onShowAllHotspots).toHaveBeenCalled(); -}); - describe('side effect', () => { const fakeElement = document.createElement('span'); const fakeParent = document.createElement('div'); @@ -152,7 +142,6 @@ function shallowRender(props: Partial = {}) { onChangeFilters={jest.fn()} onHotspotClick={jest.fn()} onLoadMore={jest.fn()} - onShowAllHotspots={jest.fn()} onSwitchStatusFilter={jest.fn()} onUpdateHotspot={jest.fn()} onLocationClick={jest.fn()} diff --git a/server/sonar-web/src/main/js/apps/security-hotspots/__tests__/__snapshots__/SecurityHotspotsApp-test.tsx.snap b/server/sonar-web/src/main/js/apps/security-hotspots/__tests__/__snapshots__/SecurityHotspotsApp-test.tsx.snap index eef0930b9f0..6c80b807c45 100644 --- a/server/sonar-web/src/main/js/apps/security-hotspots/__tests__/__snapshots__/SecurityHotspotsApp-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/security-hotspots/__tests__/__snapshots__/SecurityHotspotsApp-test.tsx.snap @@ -49,7 +49,6 @@ exports[`should render correctly 1`] = ` onHotspotClick={[Function]} onLoadMore={[Function]} onLocationClick={[Function]} - onShowAllHotspots={[Function]} onSwitchStatusFilter={[Function]} onUpdateHotspot={[Function]} securityCategories={{}} diff --git a/server/sonar-web/src/main/js/apps/security-hotspots/__tests__/__snapshots__/SecurityHotspotsAppRenderer-test.tsx.snap b/server/sonar-web/src/main/js/apps/security-hotspots/__tests__/__snapshots__/SecurityHotspotsAppRenderer-test.tsx.snap index 0d68028ec30..fa4d05d80fa 100644 --- a/server/sonar-web/src/main/js/apps/security-hotspots/__tests__/__snapshots__/SecurityHotspotsAppRenderer-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/security-hotspots/__tests__/__snapshots__/SecurityHotspotsAppRenderer-test.tsx.snap @@ -50,7 +50,6 @@ exports[`should render correctly 1`] = ` loadingMeasure={false} onBranch={false} onChangeFilters={[MockFunction]} - onShowAllHotspots={[MockFunction]} />
) => void; - onShowAllHotspots: () => void; } const statusOptions: Array<{ label: string; value: HotspotStatusFilter }> = [ @@ -85,14 +86,9 @@ export function FilterBar(props: FilterBarProps) {
{isStaticListOfHotspots ? ( - props.onShowAllHotspots()} - role="link" - tabIndex={0} - > + {translate('hotspot.filters.show_all')} - + ) : (
diff --git a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/FilterBar-test.tsx b/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/FilterBar-test.tsx index 6fd4ca0ac12..7318feaa0cd 100644 --- a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/FilterBar-test.tsx +++ b/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/FilterBar-test.tsx @@ -43,16 +43,10 @@ it('should render correctly', () => { }); it('should render correctly when the list of hotspot is static', () => { - const onShowAllHotspots = jest.fn(); - const wrapper = shallowRender({ isStaticListOfHotspots: true, - onShowAllHotspots, }); expect(wrapper).toMatchSnapshot(); - - wrapper.find('a').simulate('click'); - expect(onShowAllHotspots).toHaveBeenCalled(); }); it('should trigger onChange for status', () => { @@ -99,7 +93,6 @@ function shallowRender(props: Partial = {}) { loadingMeasure={false} onBranch={true} onChangeFilters={jest.fn()} - onShowAllHotspots={jest.fn()} {...props} /> ); diff --git a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/__snapshots__/FilterBar-test.tsx.snap b/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/__snapshots__/FilterBar-test.tsx.snap index c65451f405a..91edea01d57 100644 --- a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/__snapshots__/FilterBar-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/__snapshots__/FilterBar-test.tsx.snap @@ -10,14 +10,16 @@ exports[`should render correctly when the list of hotspot is static 1`] = `
diff --git a/server/sonar-web/src/main/js/helpers/urls.ts b/server/sonar-web/src/main/js/helpers/urls.ts index c967220797b..57d7ae2c12d 100644 --- a/server/sonar-web/src/main/js/helpers/urls.ts +++ b/server/sonar-web/src/main/js/helpers/urls.ts @@ -110,6 +110,13 @@ export function getProjectUrl( }; } +export function getProjectSecurityHotspots(project: string): To { + return { + pathname: '/security_hotspots', + search: queryToSearch({ id: project }), + }; +} + export function getProjectQueryUrl( project: string, branchParameters?: BranchParameters, -- 2.39.5