Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI: Fix edge case where only one legacy separator is defined #9425

Merged
merged 2 commits into from
Jan 14, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 33 additions & 30 deletions lib/api/src/modules/stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,23 +129,24 @@ const initStoriesApi = ({
return undefined;
};

const jumpToStory = (direction: Direction) => {
const { storiesHash, viewMode, storyId } = store.getState();

if (DOCS_MODE) {
jumpToComponent(direction);
return;
}
const jumpToComponent = (direction: Direction) => {
const state = store.getState();
const { storiesHash, viewMode, storyId } = state;

// cannot navigate when there's no current selection
if (!storyId || !storiesHash[storyId]) {
return;
}

const lookupList = Object.keys(storiesHash).filter(
k => !(storiesHash[k].children || Array.isArray(storiesHash[k]))
);
const index = lookupList.indexOf(storyId);
const lookupList = Object.entries(storiesHash).reduce((acc, i) => {
const value = i[1];
if (value.isComponent) {
acc.push([...i[1].children]);
}
return acc;
}, []);

const index = lookupList.findIndex(i => i.includes(storyId));

// cannot navigate beyond fist or last
if (index === lookupList.length - 1 && direction > 0) {
Expand All @@ -155,31 +156,28 @@ const initStoriesApi = ({
return;
}

const result = lookupList[index + direction];
const result = lookupList[index + direction][0];

if (viewMode && result) {
navigate(`/${viewMode}/${result}`);
}
navigate(`/${viewMode || 'story'}/${result}`);
};

const jumpToComponent = (direction: Direction) => {
const state = store.getState();
const { storiesHash, viewMode, storyId } = state;
const jumpToStory = (direction: Direction) => {
const { storiesHash, viewMode, storyId } = store.getState();

if (DOCS_MODE) {
jumpToComponent(direction);
return;
}

// cannot navigate when there's no current selection
if (!storyId || !storiesHash[storyId]) {
return;
}

const lookupList = Object.entries(storiesHash).reduce((acc, i) => {
const value = i[1];
if (value.isComponent) {
acc.push([...i[1].children]);
}
return acc;
}, []);

const index = lookupList.findIndex(i => i.includes(storyId));
const lookupList = Object.keys(storiesHash).filter(
k => !(storiesHash[k].children || Array.isArray(storiesHash[k]))
);
const index = lookupList.indexOf(storyId);

// cannot navigate beyond fist or last
if (index === lookupList.length - 1 && direction > 0) {
Expand All @@ -189,9 +187,11 @@ const initStoriesApi = ({
return;
}

const result = lookupList[index + direction][0];
const result = lookupList[index + direction];

navigate(`/${viewMode || 'story'}/${result}`);
if (viewMode && result) {
navigate(`/${viewMode}/${result}`);
}
};

const toKey = (input: string) =>
Expand Down Expand Up @@ -238,7 +238,10 @@ const initStoriesApi = ({
if (typeof rootSeparator !== 'undefined' || typeof groupSeparator !== 'undefined') {
warnRemovingHierarchySeparators();
if (usingShowRoots) warnUsingHierarchySeparatorsAndShowRoots();
({ root, groups } = parseKind(kind, { rootSeparator, groupSeparator }));
({ root, groups } = parseKind(kind, {
rootSeparator: rootSeparator || '|',
groupSeparator: groupSeparator || /\/|\./,
}));

// 2. If the user hasn't passed separators, but is using | or . in kinds, use the old behaviour but warn
} else if (anyKindMatchesOldHierarchySeparators && !usingShowRoots) {
Expand Down