]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-17455 Navigate to hotspot page with files param from code tab
authorRevanshu Paliwal <revanshu.paliwal@sonarsource.com>
Thu, 13 Oct 2022 13:08:57 +0000 (15:08 +0200)
committersonartech <sonartech@sonarsource.com>
Fri, 14 Oct 2022 20:03:03 +0000 (20:03 +0000)
server/sonar-web/src/main/js/apps/security-hotspots/SecurityHotspotsApp.tsx
server/sonar-web/src/main/js/apps/security-hotspots/__tests__/SecurityHotspotsApp-test.tsx
server/sonar-web/src/main/js/components/SourceViewer/SourceViewerHeader.tsx
server/sonar-web/src/main/js/components/SourceViewer/__tests__/__snapshots__/SourceViewerHeader-test.tsx.snap
server/sonar-web/src/main/js/helpers/urls.ts

index 60206865f5c227dd5ac2973473cb06cd0f7ebffd..3854bc3e60d4fc5eda65a42693e86fb8e4d07e4b 100644 (file)
@@ -120,7 +120,7 @@ export class SecurityHotspotsApp extends React.PureComponent<Props, State> {
       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<Props, State> {
 
     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 });
 
index afa9a24a86320fb249694860aa2a7bae351e918d..b754c6629e4852e59f9714f00373a3e8a5367913 100644 (file)
@@ -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 }));
index 3b701394c641bb64cefb021828f6bf6b77f9b5f0..214f55f14195b56baf8462611315cf4903cff163 100644 (file)
@@ -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<Props, State
             const measure = componentMeasures.find(
               m => m.metric === ISSUETYPE_METRIC_KEYS_MAP[type].metric
             );
+
+            const linkUrl =
+              type === IssueType.SecurityHotspot
+                ? getComponentSecurityHotspotsUrl(sourceViewerFile.project, params)
+                : getComponentIssuesUrl(sourceViewerFile.project, params);
+
             return (
               <div className="source-viewer-header-measure" key={type}>
                 <span className="source-viewer-header-measure-label">
                   {translate('issue.type', type)}
                 </span>
                 <span className="source-viewer-header-measure-value">
-                  <Link to={getComponentIssuesUrl(sourceViewerFile.project, params)}>
-                    {formatMeasure((measure && measure.value) || 0, 'INT')}
-                  </Link>
+                  <Link to={linkUrl}>{formatMeasure((measure && measure.value) || 0, 'INT')}</Link>
                 </span>
               </div>
             );
index 032a2196c26e6b2344f8cf10973da1ddd71659a6..7b0b435b8e62cb6f18feef4bbcadab4854dd5f10 100644 (file)
@@ -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",
             }
           }
         >
index d8ccb3ecb8bba2067e52c7e8da7a1972d88eafdb..e8f4b31b742bef956a100542cf1b632ddf0f3f33 100644 (file)
@@ -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,