Skip to content

Commit

Permalink
extracted main root is first of hierarchies
Browse files Browse the repository at this point in the history
  • Loading branch information
havelaer committed Dec 10, 2017
1 parent 306dfd5 commit df1694e
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions lib/ui/src/modules/ui/libs/hierarchy.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ function fillHierarchy(namespaces, hierarchy, story) {
fillHierarchy(namespaces.slice(1), childHierarchy, story);
}

function ensureMainRootIsFirst(hierarchies) {
const mainRoot = hierarchies.find(hierarchy => hierarchy.name === '');
const mainRootIndex = hierarchies.indexOf(mainRoot);
if (mainRootIndex > -1) {
hierarchies.unshift(...hierarchies.splice(mainRootIndex, 1));
}
return hierarchies;
}

export function createHierarchyRoot(name = '') {
return {
isNamespace: true,
Expand All @@ -69,16 +78,7 @@ export function createHierarchies(stories) {
});
}

const rootNames = Object.keys(rootMap);
const hierarchies = rootNames.map(rootName => rootMap[rootName]);

// make sure the main root is the first
const mainRootIndex = rootNames.indexOf('');
if (mainRootIndex > -1) {
Array.prototype.unshift.apply(hierarchies, hierarchies.splice(mainRootIndex, 1));
}

return hierarchies;
return ensureMainRootIsFirst(Object.values(rootMap));
}

export function resolveStoryHierarchyRoots(storyName = '', hierarchyRootSeparator) {
Expand Down

0 comments on commit df1694e

Please sign in to comment.