aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web
diff options
context:
space:
mode:
authorStas Vilchik <vilchiks@gmail.com>2016-01-07 11:48:04 +0100
committerStas Vilchik <vilchiks@gmail.com>2016-01-07 11:48:04 +0100
commit7810d09da1bf3908ca190d5d1811fd8b58cc549b (patch)
tree76af758b9ec23cf152b9564fc19c3980569fa332 /server/sonar-web
parent0889052cc5a9963a3865d46e241553a4836c86fb (diff)
downloadsonarqube-7810d09da1bf3908ca190d5d1811fd8b58cc549b.tar.gz
sonarqube-7810d09da1bf3908ca190d5d1811fd8b58cc549b.zip
SONAR-7177 expand the root directory
Diffstat (limited to 'server/sonar-web')
-rw-r--r--server/sonar-web/src/main/js/apps/code/actions/index.js23
-rw-r--r--server/sonar-web/src/main/js/apps/code/reducers/index.js24
-rw-r--r--server/sonar-web/tests/apps/code/store-test.js14
3 files changed, 58 insertions, 3 deletions
diff --git a/server/sonar-web/src/main/js/apps/code/actions/index.js b/server/sonar-web/src/main/js/apps/code/actions/index.js
index d9edf8eca7b..1d3dfd73561 100644
--- a/server/sonar-web/src/main/js/apps/code/actions/index.js
+++ b/server/sonar-web/src/main/js/apps/code/actions/index.js
@@ -100,6 +100,23 @@ function getPath (componentKey) {
return '/' + encodeURIComponent(componentKey);
}
+function expandRootDir (components) {
+ const rootDir = components.find(component => component.qualifier === 'DIR' && component.name === '/');
+ if (rootDir) {
+ return getChildren(rootDir.key, METRICS_WITH_COVERAGE).then(files => {
+ return _.without([...components, ...files], rootDir);
+ });
+ } else {
+ return components;
+ }
+}
+
+function skipRootDir (breadcrumbs) {
+ return breadcrumbs.filter(component => {
+ return !(component.qualifier === 'DIR' && component.name === '/');
+ });
+}
+
function retrieveComponentBase (componentKey, candidate) {
return candidate ?
Promise.resolve(candidate) :
@@ -109,13 +126,15 @@ function retrieveComponentBase (componentKey, candidate) {
function retrieveComponentChildren (componentKey, candidate) {
return candidate && candidate.children ?
Promise.resolve(candidate.children) :
- getChildren(componentKey, METRICS_WITH_COVERAGE);
+ getChildren(componentKey, METRICS_WITH_COVERAGE).then(expandRootDir);
}
function retrieveComponentBreadcrumbs (componentKey, candidate) {
return candidate && candidate.breadcrumbs ?
Promise.resolve(candidate.breadcrumbs) :
- getComponentNavigation(componentKey).then(navigation => navigation.breadcrumbs);
+ getComponentNavigation(componentKey)
+ .then(navigation => navigation.breadcrumbs)
+ .then(skipRootDir);
}
function retrieveComponent (componentKey, bucket) {
diff --git a/server/sonar-web/src/main/js/apps/code/reducers/index.js b/server/sonar-web/src/main/js/apps/code/reducers/index.js
index 5e381b02968..2c8b31a1ebb 100644
--- a/server/sonar-web/src/main/js/apps/code/reducers/index.js
+++ b/server/sonar-web/src/main/js/apps/code/reducers/index.js
@@ -46,6 +46,28 @@ function merge (components, candidate) {
return [...(_.without(components, found)), newEntry];
}
+function compare (a, b) {
+ if (a === b) {
+ return 0;
+ }
+ return a > b ? 1 : -1;
+}
+
+function sortChildren (children) {
+ const QUALIFIERS_ORDER = ['DIR', 'FIL', 'UTS'];
+ const temp = [...children];
+ temp.sort((a, b) => {
+ const qualifierA = QUALIFIERS_ORDER.indexOf(a.qualifier);
+ const qualifierB = QUALIFIERS_ORDER.indexOf(b.qualifier);
+ if (qualifierA !== qualifierB) {
+ return compare(qualifierA, qualifierB);
+ } else {
+ return compare(a.name, b.name);
+ }
+ });
+ return temp;
+}
+
export const initialState = {
fetching: false,
@@ -70,7 +92,7 @@ export function current (state = initialState, action) {
return { ...state, coverageMetric, baseBreadcrumbs };
case BROWSE:
const baseComponent = hasSourceCode(action.component) ? null : action.component;
- const components = hasSourceCode(action.component) ? null : _.sortBy(action.children, 'name');
+ const components = hasSourceCode(action.component) ? null : sortChildren(action.children);
const baseBreadcrumbsLength = state.baseBreadcrumbs.length;
const breadcrumbs = action.breadcrumbs.slice(baseBreadcrumbsLength);
const sourceViewer = hasSourceCode(action.component) ? action.component : null;
diff --git a/server/sonar-web/tests/apps/code/store-test.js b/server/sonar-web/tests/apps/code/store-test.js
index f0a809996f7..e8b36a58e4b 100644
--- a/server/sonar-web/tests/apps/code/store-test.js
+++ b/server/sonar-web/tests/apps/code/store-test.js
@@ -72,6 +72,20 @@ describe('Code :: Store', () => {
.to.deep.equal(componentsAfter);
});
+ it('should sort components by qualifier and then by name', () => {
+ const component = {};
+ const componentsBefore = [
+ { key: 'A', name: 'A', qualifier: 'FIL' },
+ { key: 'B', name: 'B', qualifier: 'DIR' }
+ ];
+ const componentsAfter = [
+ { key: 'B', name: 'B', qualifier: 'DIR' },
+ { key: 'A', name: 'A', qualifier: 'FIL' }
+ ];
+ expect(current(initialState, browseAction(component, componentsBefore)).components)
+ .to.deep.equal(componentsAfter);
+ });
+
it('should not be set for components with source code', () => {
const file = { qualifier: 'FIL' };
expect(current(initialState, browseAction(file, exampleComponents)).components)