From: Revanshu Paliwal Date: Thu, 13 Oct 2022 13:08:57 +0000 (+0200) Subject: SONAR-17455 Navigate to hotspot page with files param from code tab X-Git-Tag: 9.7.0.61563~13 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=a6c2784ec425431f4f899c2595ae6deb5c4b255c;p=sonarqube.git SONAR-17455 Navigate to hotspot page with files param from code tab --- 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 60206865f5c..3854bc3e60d 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 @@ -120,7 +120,7 @@ export class SecurityHotspotsApp extends React.PureComponent { this.props.component.key !== previous.component.key || this.props.location.query.hotspots !== previous.location.query.hotspots || SECURITY_STANDARDS.some(s => this.props.location.query[s] !== previous.location.query[s]) || - this.props.location.query.file !== previous.location.query.file + this.props.location.query.files !== previous.location.query.files ) { this.fetchInitialData(); } @@ -317,7 +317,7 @@ export class SecurityHotspotsApp extends React.PureComponent { const filterByCWE: string | undefined = location.query.cwe; - const filterByFile: string | undefined = location.query.file; + const filterByFile: string | undefined = location.query.files; this.setState({ filterByCategory, filterByCWE, filterByFile, hotspotKeys }); 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 afa9a24a863..b754c6629e4 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 @@ -144,7 +144,7 @@ it('should handle file request', () => { const filepath = 'src/path/to/file.java'; shallowRender({ - location: mockLocation({ query: { file: filepath } }) + location: mockLocation({ query: { files: filepath } }) }); expect(getSecurityHotspots).toBeCalledWith(expect.objectContaining({ files: filepath })); diff --git a/server/sonar-web/src/main/js/components/SourceViewer/SourceViewerHeader.tsx b/server/sonar-web/src/main/js/components/SourceViewer/SourceViewerHeader.tsx index 3b701394c64..214f55f1419 100644 --- a/server/sonar-web/src/main/js/components/SourceViewer/SourceViewerHeader.tsx +++ b/server/sonar-web/src/main/js/components/SourceViewer/SourceViewerHeader.tsx @@ -36,11 +36,13 @@ import { getBranchLikeUrl, getCodeUrl, getComponentIssuesUrl, + getComponentSecurityHotspotsUrl, getPathUrlAsString } from '../../helpers/urls'; import { BranchLike } from '../../types/branch-like'; import { ComponentQualifier } from '../../types/component'; -import { IssueType, Measure, SourceViewerFile } from '../../types/types'; +import { IssueType } from '../../types/issues'; +import { Measure, SourceViewerFile } from '../../types/types'; import Link from '../common/Link'; import { WorkspaceContextShape } from '../workspace/context'; import MeasuresOverlay from './components/MeasuresOverlay'; @@ -94,15 +96,19 @@ export default class SourceViewerHeader extends React.PureComponent m.metric === ISSUETYPE_METRIC_KEYS_MAP[type].metric ); + + const linkUrl = + type === IssueType.SecurityHotspot + ? getComponentSecurityHotspotsUrl(sourceViewerFile.project, params) + : getComponentIssuesUrl(sourceViewerFile.project, params); + return (
{translate('issue.type', type)} - - {formatMeasure((measure && measure.value) || 0, 'INT')} - + {formatMeasure((measure && measure.value) || 0, 'INT')}
); diff --git a/server/sonar-web/src/main/js/components/SourceViewer/__tests__/__snapshots__/SourceViewerHeader-test.tsx.snap b/server/sonar-web/src/main/js/components/SourceViewer/__tests__/__snapshots__/SourceViewerHeader-test.tsx.snap index 032a2196c26..7b0b435b8e6 100644 --- a/server/sonar-web/src/main/js/components/SourceViewer/__tests__/__snapshots__/SourceViewerHeader-test.tsx.snap +++ b/server/sonar-web/src/main/js/components/SourceViewer/__tests__/__snapshots__/SourceViewerHeader-test.tsx.snap @@ -442,8 +442,8 @@ exports[`should render correctly if issue details are passed 1`] = ` to={ Object { "hash": "", - "pathname": "/project/issues", - "search": "?files=foo%2Fbar.ts&resolved=false&types=SECURITY_HOTSPOT&id=project", + "pathname": "/security_hotspots", + "search": "?id=project&files=foo%2Fbar.ts", } } > diff --git a/server/sonar-web/src/main/js/helpers/urls.ts b/server/sonar-web/src/main/js/helpers/urls.ts index d8ccb3ecb8b..e8f4b31b742 100644 --- a/server/sonar-web/src/main/js/helpers/urls.ts +++ b/server/sonar-web/src/main/js/helpers/urls.ts @@ -195,7 +195,7 @@ export function getComponentIssuesUrl(componentKey: string, query?: Query): Path * Generate URL for a component's security hotspot page */ export function getComponentSecurityHotspotsUrl(componentKey: string, query: Query = {}): Path { - const { branch, pullRequest, inNewCodePeriod, hotspots, assignedToMe, file } = query; + const { branch, pullRequest, inNewCodePeriod, hotspots, assignedToMe, files } = query; return { pathname: '/security_hotspots', search: queryToSearch({ @@ -205,7 +205,7 @@ export function getComponentSecurityHotspotsUrl(componentKey: string, query: Que inNewCodePeriod, hotspots, assignedToMe, - file, + files, ...pick(query, [ SecurityStandard.OWASP_TOP10_2021, SecurityStandard.OWASP_TOP10,