aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web
diff options
context:
space:
mode:
authorguillaume-peoch-sonarsource <guillaume.peoch@sonarsource.com>2023-01-06 16:13:31 +0100
committersonartech <sonartech@sonarsource.com>2023-01-10 20:03:01 +0000
commit5d495f294e758d34ed5263233e9d812e19a2d926 (patch)
tree2ce7154ac01f62766a1c8a5af620f195aefe5ce4 /server/sonar-web
parent10d21d89d286e8f7ef32ee01d3a616edf865c794 (diff)
downloadsonarqube-5d495f294e758d34ed5263233e9d812e19a2d926.tar.gz
sonarqube-5d495f294e758d34ed5263233e9d812e19a2d926.zip
SONAR-18166 User can't display all secondary location when coming from the code tab
Diffstat (limited to 'server/sonar-web')
-rw-r--r--server/sonar-web/src/main/js/apps/security-hotspots/SecurityHotspotsApp.tsx23
-rw-r--r--server/sonar-web/src/main/js/apps/security-hotspots/SecurityHotspotsAppRenderer.tsx2
-rw-r--r--server/sonar-web/src/main/js/apps/security-hotspots/__tests__/SecurityHotspotsApp-test.tsx9
-rw-r--r--server/sonar-web/src/main/js/apps/security-hotspots/__tests__/SecurityHotspotsAppRenderer-test.tsx11
-rw-r--r--server/sonar-web/src/main/js/apps/security-hotspots/__tests__/__snapshots__/SecurityHotspotsApp-test.tsx.snap1
-rw-r--r--server/sonar-web/src/main/js/apps/security-hotspots/__tests__/__snapshots__/SecurityHotspotsAppRenderer-test.tsx.snap4
-rw-r--r--server/sonar-web/src/main/js/apps/security-hotspots/components/FilterBar.tsx12
-rw-r--r--server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/FilterBar-test.tsx7
-rw-r--r--server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/__snapshots__/FilterBar-test.tsx.snap14
-rw-r--r--server/sonar-web/src/main/js/helpers/urls.ts7
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<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}
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<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 && (
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<SecurityHotspotsApp['props']> = {}) {
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<SecurityHotspotsAppRendererProps> = {}) {
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]}
/>
<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}
diff --git a/server/sonar-web/src/main/js/apps/security-hotspots/components/FilterBar.tsx b/server/sonar-web/src/main/js/apps/security-hotspots/components/FilterBar.tsx
index 10b74b2b2e2..3be25c9785e 100644
--- a/server/sonar-web/src/main/js/apps/security-hotspots/components/FilterBar.tsx
+++ b/server/sonar-web/src/main/js/apps/security-hotspots/components/FilterBar.tsx
@@ -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">
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<FilterBarProps> = {}) {
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`] = `
<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>
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,