From: Stas Vilchik Date: Thu, 28 Sep 2017 13:22:15 +0000 (+0200) Subject: SONAR-9702 expand root dir with branch on code page X-Git-Tag: 6.6-RC1~115 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=b33f90019d9a122b6e8bbbe66a0c9c018b9f00ec;p=sonarqube.git SONAR-9702 expand root dir with branch on code page --- diff --git a/server/sonar-web/src/main/js/apps/code/utils.ts b/server/sonar-web/src/main/js/apps/code/utils.ts index cd60dff2dd9..9e8c7c3ceb6 100644 --- a/server/sonar-web/src/main/js/apps/code/utils.ts +++ b/server/sonar-web/src/main/js/apps/code/utils.ts @@ -54,11 +54,12 @@ const PAGE_SIZE = 100; function requestChildren( componentKey: string, metrics: string[], - page: number + page: number, + branch?: string ): Promise { - return getChildren(componentKey, metrics, { p: page, ps: PAGE_SIZE }).then(r => { + return getChildren(componentKey, metrics, { branch, p: page, ps: PAGE_SIZE }).then(r => { if (r.paging.total > r.paging.pageSize * r.paging.pageIndex) { - return requestChildren(componentKey, metrics, page + 1).then(moreComponents => { + return requestChildren(componentKey, metrics, page + 1, branch).then(moreComponents => { return [...r.components, ...moreComponents]; }); } @@ -66,8 +67,12 @@ function requestChildren( }); } -function requestAllChildren(componentKey: string, metrics: string[]): Promise { - return requestChildren(componentKey, metrics, 1); +function requestAllChildren( + componentKey: string, + metrics: string[], + branch?: string +): Promise { + return requestChildren(componentKey, metrics, 1, branch); } interface Children { @@ -80,13 +85,13 @@ interface ExpandRootDirFunc { (children: Children): Promise; } -function expandRootDir(metrics: string[]): ExpandRootDirFunc { +function expandRootDir(metrics: string[], branch?: string): ExpandRootDirFunc { return function({ components, total, ...other }) { const rootDir = components.find( (component: Component) => component.qualifier === 'DIR' && component.name === '/' ); if (rootDir) { - return requestAllChildren(rootDir.key, metrics).then(rootDirComponents => { + return requestAllChildren(rootDir.key, metrics, branch).then(rootDirComponents => { const nextComponents = without([...rootDirComponents, ...components], rootDir); const nextTotal = total + rootDirComponents.length - /* root dir */ 1; return { components: nextComponents, total: nextTotal, ...other }; @@ -161,7 +166,7 @@ export function retrieveComponentChildren( return getChildren(componentKey, metrics, { branch, ps: PAGE_SIZE, s: 'qualifier,name' }) .then(prepareChildren) - .then(expandRootDir(metrics)) + .then(expandRootDir(metrics, branch)) .then(r => { addComponentChildren(componentKey, r.components, r.total, r.page); storeChildrenBase(r.components); @@ -223,7 +228,7 @@ export function loadMoreChildren( return getChildren(componentKey, metrics, { branch, ps: PAGE_SIZE, p: page }) .then(prepareChildren) - .then(expandRootDir(metrics)) + .then(expandRootDir(metrics, branch)) .then(r => { addComponentChildren(componentKey, r.components, r.total, r.page); storeChildrenBase(r.components);