]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-16118 Sort PRs numerically instead of alphabetically
authorWouter Admiraal <wouter.admiraal@sonarsource.com>
Tue, 3 May 2022 14:38:56 +0000 (16:38 +0200)
committersonartech <sonartech@sonarsource.com>
Thu, 5 May 2022 20:02:57 +0000 (20:02 +0000)
server/sonar-web/src/main/js/app/components/nav/component/branch-like/__tests__/Menu-test.tsx
server/sonar-web/src/main/js/app/components/nav/component/branch-like/__tests__/__snapshots__/Menu-test.tsx.snap
server/sonar-web/src/main/js/app/components/nav/component/branch-like/__tests__/__snapshots__/MenuItemList-test.tsx.snap
server/sonar-web/src/main/js/helpers/__tests__/branch-like-test.ts
server/sonar-web/src/main/js/helpers/branch-like.ts

index 4a159facf716a02b280f8beaa988017204a4039e..91a7856001177aca5cd15fa9858c648d3127694d 100644 (file)
@@ -94,7 +94,7 @@ it('should handle keyboard shortcut correctly', () => {
   const { onKeyDown } = wrapper.find(SearchBox).props();
 
   onKeyDown!(mockEvent({ nativeEvent: { code: KeyboardCodes.UpArrow } }));
-  expect(wrapper.state().selectedBranchLike).toBe(branchLikes[5]);
+  expect(wrapper.state().selectedBranchLike).toBe(branchLikes[3]);
 
   onKeyDown!(mockEvent({ nativeEvent: { code: KeyboardCodes.DownArrow } }));
   onKeyDown!(mockEvent({ nativeEvent: { code: KeyboardCodes.DownArrow } }));
index bd7828441133e36661ebd5dfa52fd8b5688a82a5..ce2339c7560d1b1300321a1a363d9517a33c7538 100644 (file)
@@ -81,17 +81,17 @@ exports[`should render correctly 1`] = `
                 "analysisDate": "2018-01-01",
                 "base": "master",
                 "branch": "feature/foo/bar",
-                "key": "1",
+                "key": "2",
                 "target": "master",
-                "title": "PR-1",
+                "title": "PR-2",
               },
               Object {
                 "analysisDate": "2018-01-01",
                 "base": "master",
                 "branch": "feature/foo/bar",
-                "key": "2",
+                "key": "1",
                 "target": "master",
-                "title": "PR-2",
+                "title": "PR-1",
               },
             ],
           },
@@ -246,17 +246,17 @@ exports[`should render correctly with no current branch like 1`] = `
                 "analysisDate": "2018-01-01",
                 "base": "master",
                 "branch": "feature/foo/bar",
-                "key": "1",
+                "key": "2",
                 "target": "master",
-                "title": "PR-1",
+                "title": "PR-2",
               },
               Object {
                 "analysisDate": "2018-01-01",
                 "base": "master",
                 "branch": "feature/foo/bar",
-                "key": "2",
+                "key": "1",
                 "target": "master",
-                "title": "PR-2",
+                "title": "PR-1",
               },
             ],
           },
index 2698ccdc7b19783c86fa3b2af2fc0bc1dc433c87..363ffb08062df1cc822b7981dcfebc13254b3e8e 100644 (file)
@@ -64,9 +64,9 @@ exports[`should render correctly 1`] = `
         "analysisDate": "2018-01-01",
         "base": "master",
         "branch": "feature/foo/bar",
-        "key": "1",
+        "key": "2",
         "target": "master",
-        "title": "PR-1",
+        "title": "PR-2",
       }
     }
     component={
@@ -92,7 +92,7 @@ exports[`should render correctly 1`] = `
       }
     }
     indent={true}
-    key="pull-request-1"
+    key="pull-request-2"
     onSelect={[MockFunction]}
     selected={false}
     setSelectedNode={[Function]}
@@ -103,9 +103,9 @@ exports[`should render correctly 1`] = `
         "analysisDate": "2018-01-01",
         "base": "master",
         "branch": "feature/foo/bar",
-        "key": "2",
+        "key": "1",
         "target": "master",
-        "title": "PR-2",
+        "title": "PR-1",
       }
     }
     component={
@@ -131,7 +131,7 @@ exports[`should render correctly 1`] = `
       }
     }
     indent={true}
-    key="pull-request-2"
+    key="pull-request-1"
     onSelect={[MockFunction]}
     selected={false}
     setSelectedNode={[Function]}
index 639a3ea96b6cbd0eb1df5a0374391d52ebba71ac..314efb1c3b53cbd3282b020d200977811fa2f555 100644 (file)
@@ -28,16 +28,16 @@ describe('#getBrancheLikesAsTree', () => {
     const branch3 = mockBranch({ name: 'branch-3' });
     const branch4 = mockBranch({ name: 'branch-4' });
 
-    const mainPr1 = mockPullRequest({ base: main.name, key: 'PR1' });
-    const mainPr2 = mockPullRequest({ base: main.name, key: 'PR2' });
-    const llb1Pr1 = mockPullRequest({ base: branch1.name, key: 'PR1' });
-    const llb1Pr2 = mockPullRequest({ base: branch1.name, key: 'PR2' });
-    const llb2Pr1 = mockPullRequest({ base: branch2.name, key: 'PR1' });
-    const llb2Pr2 = mockPullRequest({ base: branch2.name, key: 'PR1' });
-    const orphanPR1 = mockPullRequest({ isOrphan: true, key: 'PR1' });
-    const orphanPR2 = mockPullRequest({ isOrphan: true, key: 'PR2' });
-    const parentlessPR1 = mockPullRequest({ base: 'not_present_branch_1', key: 'PR1' });
-    const parentlessPR2 = mockPullRequest({ base: 'not_present_branch_2', key: 'PR2' });
+    const mainPr1 = mockPullRequest({ base: main.name, key: '1' });
+    const mainPr2 = mockPullRequest({ base: main.name, key: '2' });
+    const branch1Pr1 = mockPullRequest({ base: branch1.name, key: '3' });
+    const branch1Pr2 = mockPullRequest({ base: branch1.name, key: '4' });
+    const branch2Pr1 = mockPullRequest({ base: branch2.name, key: '5' });
+    const branch2Pr2 = mockPullRequest({ base: branch2.name, key: '6' });
+    const orphanPR1 = mockPullRequest({ isOrphan: true, key: '7' });
+    const orphanPR2 = mockPullRequest({ isOrphan: true, key: '8' });
+    const parentlessPR1 = mockPullRequest({ base: 'not_present_branch_1', key: '9' });
+    const parentlessPR2 = mockPullRequest({ base: 'not_present_branch_2', key: '10' });
 
     expect(
       getBrancheLikesAsTree([
@@ -52,24 +52,24 @@ describe('#getBrancheLikesAsTree', () => {
         mainPr1,
         parentlessPR2,
         parentlessPR1,
-        llb2Pr2,
-        llb2Pr1,
-        llb1Pr2,
-        llb1Pr1
+        branch2Pr2,
+        branch2Pr1,
+        branch1Pr2,
+        branch1Pr1
       ])
     ).toEqual({
       mainBranchTree: {
         branch: main,
-        pullRequests: [mainPr1, mainPr2]
+        pullRequests: [mainPr2, mainPr1]
       },
       branchTree: [
-        { branch: branch1, pullRequests: [llb1Pr1, llb1Pr2] },
-        { branch: branch2, pullRequests: [llb2Pr1, llb2Pr1] },
+        { branch: branch1, pullRequests: [branch1Pr2, branch1Pr1] },
+        { branch: branch2, pullRequests: [branch2Pr2, branch2Pr1] },
         { branch: branch3, pullRequests: [] },
         { branch: branch4, pullRequests: [] }
       ],
-      parentlessPullRequests: [parentlessPR1, parentlessPR2],
-      orphanPullRequests: [orphanPR1, orphanPR2]
+      parentlessPullRequests: [parentlessPR2, parentlessPR1],
+      orphanPullRequests: [orphanPR2, orphanPR1]
     });
   });
 });
index ce6cc4ec13f8cdd36b7fcc6389da95eb6979928e..8df94c21614df0b72198decbe7d9f4d5830eb72b 100644 (file)
@@ -87,7 +87,9 @@ export function getBrancheLikesAsTree(branchLikes: BranchLike[]): BranchLikeTree
     branchLikes.filter(isBranch).filter(b => !isMainBranch(b)),
     b => b.name
   );
-  const pullRequests = orderBy(branchLikes.filter(isPullRequest), b => b.key);
+  const pullRequests = orderBy(branchLikes.filter(isPullRequest), b => parseInt(b.key, 10), [
+    'desc'
+  ]);
   const parentlessPullRequests = pullRequests.filter(
     pr => !pr.isOrphan && ![mainBranch, ...branches].find(b => !!b && b.name === pr.base)
   );