]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-16245 Place others category at the end
authorJeremy Davis <jeremy.davis@sonarsource.com>
Tue, 24 May 2022 16:23:29 +0000 (18:23 +0200)
committersonartech <sonartech@sonarsource.com>
Wed, 25 May 2022 20:03:16 +0000 (20:03 +0000)
server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/__snapshots__/HotspotList-test.tsx.snap
server/sonar-web/src/main/js/apps/security-hotspots/utils.ts

index 92c180c0403d16d4216f08b2c4ac947ec37b7c61..f526a63a918341e10b6f5c8a1529f122b3422dc2 100644 (file)
@@ -106,23 +106,23 @@ exports[`should render correctly with hotspots: no pagination 1`] = `
       <ul>
         <li
           className="spacer-bottom"
-          key="cat2"
+          key="cat1"
         >
           <HotspotCategory
-            categoryKey="cat2"
+            categoryKey="cat1"
             hotspots={
               Array [
                 Object {
                   "author": "Developer 1",
                   "component": "com.github.kevinsawicki:http-request:com.github.kevinsawicki.http.HttpRequest",
                   "creationDate": "2013-05-13T17:55:39+0200",
-                  "key": "h1",
+                  "key": "h2",
                   "line": 81,
                   "message": "'3' is a magic number.",
                   "project": "com.github.kevinsawicki:http-request",
                   "resolution": undefined,
                   "rule": "checkstyle:com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck",
-                  "securityCategory": "cat2",
+                  "securityCategory": "cat1",
                   "status": "TO_REVIEW",
                   "updateDate": "2013-05-13T17:55:39+0200",
                   "vulnerabilityProbability": "HIGH",
@@ -151,28 +151,28 @@ exports[`should render correctly with hotspots: no pagination 1`] = `
                 "vulnerabilityProbability": "HIGH",
               }
             }
-            title="cat2"
+            title="cat1"
           />
         </li>
         <li
           className="spacer-bottom"
-          key="cat1"
+          key="cat2"
         >
           <HotspotCategory
-            categoryKey="cat1"
+            categoryKey="cat2"
             hotspots={
               Array [
                 Object {
                   "author": "Developer 1",
                   "component": "com.github.kevinsawicki:http-request:com.github.kevinsawicki.http.HttpRequest",
                   "creationDate": "2013-05-13T17:55:39+0200",
-                  "key": "h2",
+                  "key": "h1",
                   "line": 81,
                   "message": "'3' is a magic number.",
                   "project": "com.github.kevinsawicki:http-request",
                   "resolution": undefined,
                   "rule": "checkstyle:com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck",
-                  "securityCategory": "cat1",
+                  "securityCategory": "cat2",
                   "status": "TO_REVIEW",
                   "updateDate": "2013-05-13T17:55:39+0200",
                   "vulnerabilityProbability": "HIGH",
@@ -201,7 +201,7 @@ exports[`should render correctly with hotspots: no pagination 1`] = `
                 "vulnerabilityProbability": "HIGH",
               }
             }
-            title="cat1"
+            title="cat2"
           />
         </li>
       </ul>
@@ -386,23 +386,23 @@ exports[`should render correctly with hotspots: pagination 1`] = `
       <ul>
         <li
           className="spacer-bottom"
-          key="cat2"
+          key="cat1"
         >
           <HotspotCategory
-            categoryKey="cat2"
+            categoryKey="cat1"
             hotspots={
               Array [
                 Object {
                   "author": "Developer 1",
                   "component": "com.github.kevinsawicki:http-request:com.github.kevinsawicki.http.HttpRequest",
                   "creationDate": "2013-05-13T17:55:39+0200",
-                  "key": "h1",
+                  "key": "h2",
                   "line": 81,
                   "message": "'3' is a magic number.",
                   "project": "com.github.kevinsawicki:http-request",
                   "resolution": undefined,
                   "rule": "checkstyle:com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck",
-                  "securityCategory": "cat2",
+                  "securityCategory": "cat1",
                   "status": "TO_REVIEW",
                   "updateDate": "2013-05-13T17:55:39+0200",
                   "vulnerabilityProbability": "HIGH",
@@ -431,28 +431,28 @@ exports[`should render correctly with hotspots: pagination 1`] = `
                 "vulnerabilityProbability": "HIGH",
               }
             }
-            title="cat2"
+            title="cat1"
           />
         </li>
         <li
           className="spacer-bottom"
-          key="cat1"
+          key="cat2"
         >
           <HotspotCategory
-            categoryKey="cat1"
+            categoryKey="cat2"
             hotspots={
               Array [
                 Object {
                   "author": "Developer 1",
                   "component": "com.github.kevinsawicki:http-request:com.github.kevinsawicki.http.HttpRequest",
                   "creationDate": "2013-05-13T17:55:39+0200",
-                  "key": "h2",
+                  "key": "h1",
                   "line": 81,
                   "message": "'3' is a magic number.",
                   "project": "com.github.kevinsawicki:http-request",
                   "resolution": undefined,
                   "rule": "checkstyle:com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck",
-                  "securityCategory": "cat1",
+                  "securityCategory": "cat2",
                   "status": "TO_REVIEW",
                   "updateDate": "2013-05-13T17:55:39+0200",
                   "vulnerabilityProbability": "HIGH",
@@ -481,7 +481,7 @@ exports[`should render correctly with hotspots: pagination 1`] = `
                 "vulnerabilityProbability": "HIGH",
               }
             }
-            title="cat1"
+            title="cat2"
           />
         </li>
       </ul>
index b0275f40751ea4e3b75eccfa52b970eb3f41741a..42b83d6517a38951745ae049bb43efe03b74ce1f 100644 (file)
@@ -44,6 +44,8 @@ import {
   StandardSecurityCategories
 } from '../../types/types';
 
+const OTHERS_SECURITY_CATEGORY = 'others';
+
 export const RISK_EXPOSURE_LEVELS = [RiskExposure.HIGH, RiskExposure.MEDIUM, RiskExposure.LOW];
 export const SECURITY_STANDARDS = [
   SecurityStandard.SONARSOURCE,
@@ -74,11 +76,19 @@ export function groupByCategory(
 ) {
   const groups = groupBy(hotspots, h => h.securityCategory);
 
-  return Object.keys(groups).map(key => ({
+  const groupList = Object.keys(groups).map(key => ({
     key,
     title: getCategoryTitle(key, securityCategories),
     hotspots: groups[key]
   }));
+
+  return [
+    ...sortBy(
+      groupList.filter(group => group.key !== OTHERS_SECURITY_CATEGORY),
+      group => group.title
+    ),
+    ...groupList.filter(({ key }) => key === OTHERS_SECURITY_CATEGORY)
+  ];
 }
 
 export function sortHotspots(hotspots: RawHotspot[], securityCategories: Dict<{ title: string }>) {