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

Allow browsing to a kind and get the first story #6720

Merged
merged 1 commit into from
May 6, 2019
Merged
Show file tree
Hide file tree
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
11 changes: 10 additions & 1 deletion lib/api/src/modules/stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,16 @@ Did you create a path that uses the separator char accidentally, such as 'Vue <d

const { storyId, viewMode } = store.getState();

if (!storyId || !storiesHash[storyId]) {
if (storyId && storyId.match(/--\*$/)) {
const idStart = storyId.slice(0, -1); // drop the * at the end
const firstKindLeaf = Object.values(storiesHash).find(
(s: Story | Group) => !s.children && s.id.substring(0, idStart.length) === idStart
);

if (viewMode && firstKindLeaf) {
navigate(`/${viewMode}/${firstKindLeaf.id}`);
}
} else if (!storyId || storyId === '*' || !storiesHash[storyId]) {
// when there's no storyId or the storyId item doesn't exist
// we pick the first leaf and navigate
const firstLeaf = Object.values(storiesHash).find((s: Story | Group) => !s.children);
Expand Down
4 changes: 4 additions & 0 deletions lib/api/src/modules/url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ const initialUrlSupport = ({ navigate, location, path }: Module) => {
if (selectedKind && selectedStory) {
const storyId = toId(selectedKind, selectedStory);
setTimeout(() => navigate(`/story/${storyId}`, { replace: true }), 1);
} else if (selectedKind) {
// Create a "storyId" of the form `kind-sanitized--*`
const standInId = toId(selectedKind, 'star').replace(/star$/, '*');
setTimeout(() => navigate(`/story/${standInId}`, { replace: true }), 1);
} else if (!queryPath || queryPath === '/') {
setTimeout(() => navigate(`/story/*`, { replace: true }), 1);
} else if (Object.keys(query).length > 1) {
Expand Down