]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-18166 User can't display all secondary location when coming from the code tab
authorguillaume-peoch-sonarsource <guillaume.peoch@sonarsource.com>
Fri, 6 Jan 2023 15:13:31 +0000 (16:13 +0100)
committersonartech <sonartech@sonarsource.com>
Tue, 10 Jan 2023 20:03:01 +0000 (20:03 +0000)
server/sonar-web/src/main/js/apps/security-hotspots/SecurityHotspotsApp.tsx
server/sonar-web/src/main/js/apps/security-hotspots/SecurityHotspotsAppRenderer.tsx
server/sonar-web/src/main/js/apps/security-hotspots/__tests__/SecurityHotspotsApp-test.tsx
server/sonar-web/src/main/js/apps/security-hotspots/__tests__/SecurityHotspotsAppRenderer-test.tsx
server/sonar-web/src/main/js/apps/security-hotspots/__tests__/__snapshots__/SecurityHotspotsApp-test.tsx.snap
server/sonar-web/src/main/js/apps/security-hotspots/__tests__/__snapshots__/SecurityHotspotsAppRenderer-test.tsx.snap
server/sonar-web/src/main/js/apps/security-hotspots/components/FilterBar.tsx
server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/FilterBar-test.tsx
server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/__snapshots__/FilterBar-test.tsx.snap
server/sonar-web/src/main/js/helpers/urls.ts

index d8758c9713cf392e738563ae2666c5e1b6bbef40..91b675e28aa6fecc4067cb29c0a48be216e5da55 100644 (file)
@@ -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<Props, State> {
       .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<Props, State> {
         onChangeFilters={this.handleChangeFilters}
         onHotspotClick={this.handleHotspotClick}
         onLoadMore={this.handleLoadMore}
-        onShowAllHotspots={this.handleShowAllHotspots}
         onSwitchStatusFilter={this.handleChangeStatusFilter}
         onUpdateHotspot={this.handleHotspotUpdate}
         onLocationClick={this.handleLocationClick}
index c4fc16bbe4a429b35e8d0376fd3f71d6fc2d9167..ba8b7c1bd9f441fa292c167484c6b457ba3ade6f 100644 (file)
@@ -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<void>;
   selectedHotspot?: RawHotspot;
@@ -113,7 +112,6 @@ export default function SecurityHotspotsAppRenderer(props: SecurityHotspotsAppRe
         loadingMeasure={loadingMeasure}
         onBranch={isBranch(branchLike)}
         onChangeFilters={props.onChangeFilters}
-        onShowAllHotspots={props.onShowAllHotspots}
       />
 
       {loading && (
index cdbc44541e36b17af75ffd231be19fd8e40f88cd..7b0fbfa3c84ca8553faf66e66c47bf86892ff4b0 100644 (file)
@@ -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<SecurityHotspotsApp['props']> = {}) {
       component={mockComponent()}
       currentUser={mockCurrentUser()}
       location={mockLocation()}
-      router={mockRouter()}
       {...props}
     />
   );
index 144d42916b43041b117d151ce3e124fdf2123d68..1e0594d62cb47d292ecec955aff460cd536593c7 100644 (file)
@@ -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<SecurityHotspotsAppRendererProps> = {}) {
       onChangeFilters={jest.fn()}
       onHotspotClick={jest.fn()}
       onLoadMore={jest.fn()}
-      onShowAllHotspots={jest.fn()}
       onSwitchStatusFilter={jest.fn()}
       onUpdateHotspot={jest.fn()}
       onLocationClick={jest.fn()}
index eef0930b9f08a6a1a6cf263a142b354766c0b6be..6c80b807c4514f019c9d63e490d51491bd416561 100644 (file)
@@ -49,7 +49,6 @@ exports[`should render correctly 1`] = `
   onHotspotClick={[Function]}
   onLoadMore={[Function]}
   onLocationClick={[Function]}
-  onShowAllHotspots={[Function]}
   onSwitchStatusFilter={[Function]}
   onUpdateHotspot={[Function]}
   securityCategories={{}}
index 0d68028ec307fafb8d082edd5330a6088e647ad6..fa4d05d80fa7e1fca006455e866760c65b02f540 100644 (file)
@@ -50,7 +50,6 @@ exports[`should render correctly 1`] = `
     loadingMeasure={false}
     onBranch={false}
     onChangeFilters={[MockFunction]}
-    onShowAllHotspots={[MockFunction]}
   />
   <EmptyHotspotsPage
     filterByFile={false}
@@ -407,7 +406,6 @@ exports[`should render correctly with hotspots 1`] = `
     loadingMeasure={false}
     onBranch={false}
     onChangeFilters={[MockFunction]}
-    onShowAllHotspots={[MockFunction]}
   />
   <EmptyHotspotsPage
     filterByFile={false}
@@ -544,7 +542,6 @@ exports[`should render correctly: loading 1`] = `
     loadingMeasure={false}
     onBranch={false}
     onChangeFilters={[MockFunction]}
-    onShowAllHotspots={[MockFunction]}
   />
   <div
     className="layout-page"
@@ -610,7 +607,6 @@ exports[`should render correctly: no hotspots with filters 1`] = `
     loadingMeasure={false}
     onBranch={false}
     onChangeFilters={[MockFunction]}
-    onShowAllHotspots={[MockFunction]}
   />
   <EmptyHotspotsPage
     filterByFile={false}
index 10b74b2b2e2fb58f58e8027d31bba10cf7717169..3be25c9785e03e4654d501b01c21ed5168d0ea7a 100644 (file)
@@ -19,6 +19,7 @@
  */
 import * as React from 'react';
 import withCurrentUserContext from '../../../app/components/current-user/withCurrentUserContext';
+import Link from '../../../components/common/Link';
 import ButtonToggle from '../../../components/controls/ButtonToggle';
 import HelpTooltip from '../../../components/controls/HelpTooltip';
 import Select from '../../../components/controls/Select';
@@ -26,6 +27,7 @@ import Measure from '../../../components/measure/Measure';
 import CoverageRating from '../../../components/ui/CoverageRating';
 import DeferredSpinner from '../../../components/ui/DeferredSpinner';
 import { translate } from '../../../helpers/l10n';
+import { getProjectSecurityHotspots } from '../../../helpers/urls';
 import { ComponentQualifier } from '../../../types/component';
 import { HotspotFilters, HotspotStatusFilter } from '../../../types/security-hotspots';
 import { Component } from '../../../types/types';
@@ -40,7 +42,6 @@ export interface FilterBarProps {
   loadingMeasure: boolean;
   onBranch: boolean;
   onChangeFilters: (filters: Partial<HotspotFilters>) => void;
-  onShowAllHotspots: () => void;
 }
 
 const statusOptions: Array<{ label: string; value: HotspotStatusFilter }> = [
@@ -85,14 +86,9 @@ export function FilterBar(props: FilterBarProps) {
       <div className="filter-bar">
         <div className="filter-bar-inner display-flex-center">
           {isStaticListOfHotspots ? (
-            <a
-              id="show_all_hotspot"
-              onClick={() => props.onShowAllHotspots()}
-              role="link"
-              tabIndex={0}
-            >
+            <Link to={getProjectSecurityHotspots(component.key)}>
               {translate('hotspot.filters.show_all')}
-            </a>
+            </Link>
           ) : (
             <div className="display-flex-space-between width-100">
               <div className="display-flex-center">
index 6fd4ca0ac12ef4fc5587761bff061231074f32fa..7318feaa0cd89e368b25836fc7127f53b5dcbde3 100644 (file)
@@ -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<FilterBarProps> = {}) {
       loadingMeasure={false}
       onBranch={true}
       onChangeFilters={jest.fn()}
-      onShowAllHotspots={jest.fn()}
       {...props}
     />
   );
index c65451f405a8967b698cc1913011dac9c48a36de..91edea01d5715e84f73f760a6ee762bb729b560a 100644 (file)
@@ -10,14 +10,16 @@ exports[`should render correctly when the list of hotspot is static 1`] = `
     <div
       className="filter-bar-inner display-flex-center"
     >
-      <a
-        id="show_all_hotspot"
-        onClick={[Function]}
-        role="link"
-        tabIndex={0}
+      <ForwardRef(Link)
+        to={
+          {
+            "pathname": "/security_hotspots",
+            "search": "?id=my-project",
+          }
+        }
       >
         hotspot.filters.show_all
-      </a>
+      </ForwardRef(Link)>
     </div>
   </div>
 </div>
index c967220797b0d0b5e5abcd6ff291b621b9b9c3c7..57d7ae2c12d7d7fdbee4a16718f1c9f879b192f0 100644 (file)
@@ -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,