From e97b716f283471f2f3335843861b520cdc772fba Mon Sep 17 00:00:00 2001 From: Wouter Admiraal Date: Tue, 3 May 2022 16:38:56 +0200 Subject: [PATCH] SONAR-16118 Sort PRs numerically instead of alphabetically --- .../branch-like/__tests__/Menu-test.tsx | 2 +- .../__snapshots__/Menu-test.tsx.snap | 16 ++++---- .../__snapshots__/MenuItemList-test.tsx.snap | 12 +++--- .../js/helpers/__tests__/branch-like-test.ts | 38 +++++++++---------- .../src/main/js/helpers/branch-like.ts | 4 +- 5 files changed, 37 insertions(+), 35 deletions(-) diff --git a/server/sonar-web/src/main/js/app/components/nav/component/branch-like/__tests__/Menu-test.tsx b/server/sonar-web/src/main/js/app/components/nav/component/branch-like/__tests__/Menu-test.tsx index 4a159facf71..91a78560011 100644 --- a/server/sonar-web/src/main/js/app/components/nav/component/branch-like/__tests__/Menu-test.tsx +++ b/server/sonar-web/src/main/js/app/components/nav/component/branch-like/__tests__/Menu-test.tsx @@ -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 } })); diff --git a/server/sonar-web/src/main/js/app/components/nav/component/branch-like/__tests__/__snapshots__/Menu-test.tsx.snap b/server/sonar-web/src/main/js/app/components/nav/component/branch-like/__tests__/__snapshots__/Menu-test.tsx.snap index bd782844113..ce2339c7560 100644 --- a/server/sonar-web/src/main/js/app/components/nav/component/branch-like/__tests__/__snapshots__/Menu-test.tsx.snap +++ b/server/sonar-web/src/main/js/app/components/nav/component/branch-like/__tests__/__snapshots__/Menu-test.tsx.snap @@ -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", }, ], }, diff --git a/server/sonar-web/src/main/js/app/components/nav/component/branch-like/__tests__/__snapshots__/MenuItemList-test.tsx.snap b/server/sonar-web/src/main/js/app/components/nav/component/branch-like/__tests__/__snapshots__/MenuItemList-test.tsx.snap index 2698ccdc7b1..363ffb08062 100644 --- a/server/sonar-web/src/main/js/app/components/nav/component/branch-like/__tests__/__snapshots__/MenuItemList-test.tsx.snap +++ b/server/sonar-web/src/main/js/app/components/nav/component/branch-like/__tests__/__snapshots__/MenuItemList-test.tsx.snap @@ -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]} diff --git a/server/sonar-web/src/main/js/helpers/__tests__/branch-like-test.ts b/server/sonar-web/src/main/js/helpers/__tests__/branch-like-test.ts index 639a3ea96b6..314efb1c3b5 100644 --- a/server/sonar-web/src/main/js/helpers/__tests__/branch-like-test.ts +++ b/server/sonar-web/src/main/js/helpers/__tests__/branch-like-test.ts @@ -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] }); }); }); diff --git a/server/sonar-web/src/main/js/helpers/branch-like.ts b/server/sonar-web/src/main/js/helpers/branch-like.ts index ce6cc4ec13f..8df94c21614 100644 --- a/server/sonar-web/src/main/js/helpers/branch-like.ts +++ b/server/sonar-web/src/main/js/helpers/branch-like.ts @@ -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) ); -- 2.39.5