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

Core: Allow linking to kind/component ID #7648

Merged
merged 10 commits into from
Oct 24, 2019

Conversation

lonyele
Copy link
Member

@lonyele lonyele commented Aug 1, 2019

Issue: #7582

What I did

I added the default route when story exists but child url is not specified

How to test

  • Is this testable with Jest or Chromatic screenshots? Yes!(I added)
  • Does this need a new example in the kitchen sink apps? No
  • Does this need an update to the documentation? No

@vercel
Copy link

vercel bot commented Aug 1, 2019

This pull request is being automatically deployed with ZEIT Now (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://zeit.co/storybook/monorepo/95v0zva8u
🌍 Preview: https://monorepo-git-fork-lonyele-feature-existing-story-default-route.storybook.now.sh

Copy link
Member

@tmeasday tmeasday left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems reasonable. Should we deprecate the --* syntax?

@@ -207,6 +207,25 @@ describe('stories API', () => {
expect(navigate).toHaveBeenCalledWith('/story/a--1');
});

it(
'navigates to the first child story of the parent story if a ' +
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lonyele what's up with this string concat?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not a prettier error(80 character) but this string became too long and I ended up concatenating like this. Is there a better way? maybe template literal?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed it to one line!

@@ -286,6 +286,11 @@ Did you create a path that uses the separator char accidentally, such as 'Vue <d
} else if (viewMode && firstLeaf) {
navigate(`/${viewMode}/${firstLeaf.id}`);
}
} else if (storiesHash[storyId] && storiesHash[storyId].children) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lonyele will this navigate multiple times if storyId is not immediately above the leaf?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SB-default-route

...if storyId not immediately above the leaf?

Did you mean by when story is nested in multiple times? such as screenshot(Form -> Select -> validations) If that's the case, I think it is ok since the url always will be a working one when inside of if/else

const firstLeafId = storiesHash[storyId].children[0];
navigate(`/${viewMode}/${firstLeafId}`);

If that's not the case, can you explain it more?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

storiesHash[storyId].children is not necessarily a leaf, is it? It's just a child node ID. What happens in the case that the child is not a leaf?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeap, you are right. It was only covering the case when given storyId is one depth parent from the leaf story. I change the logic so that it can find leaf story from any depth

@lonyele
Copy link
Member Author

lonyele commented Sep 11, 2019

@shilman just a gentle ping...

@shilman
Copy link
Member

shilman commented Sep 11, 2019

Thanks @lonyele! Will merge this into 5.3 after 5.2 is released later this week. 👍

@shilman shilman added this to the 5.3.0 milestone Sep 11, 2019
@vercel vercel bot temporarily deployed to staging September 11, 2019 15:48 Inactive
} else if (storiesHash[storyId]) {
// When story exists but if it is not the leaf story, it finds the proper
// leaf story from any depth.
const firstLeafStoryId = storiesHash[storyId].isLeaf
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const firstLeafStoryId = findLeafStoryId(storiesHash, storyId);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

@lonyele lonyele Sep 11, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shilman oh wait, I'm writing a test now. BTW, this comment is on the previous file change. Please refresh for the new one

@vercel vercel bot temporarily deployed to staging September 11, 2019 16:26 Inactive
@lonyele
Copy link
Member Author

lonyele commented Sep 11, 2019

@shilman It's much better now. It will navigate to the leaf story from any depth. Consider the cases through this screenshot.
SB-default-any-depth

Valid URL from the screenshot is /?path=/story/basics-form-select--validations but...

  • if given url is /?path=/story/basics-form-select then
    navigates to /?path=/story/basics-form-select--sizes
  • if given url is /?path=/story/basics-form then
    navigates to /?path=/story/basics-form-button--sizes
  • if given url is /?path=/story/basics then
    navigates to /?path=/story/basics-actionbar--single-item

btw, I added 2 test cases for different depth. If test case naming or too many cases, please let me know how to fix it(I think it is little bit weird now)

@ndelangen ndelangen self-assigned this Sep 27, 2019
@stale
Copy link

stale bot commented Oct 24, 2019

Hi everyone! Seems like there hasn't been much going on in this issue lately. If there are still questions, comments, or bugs, please feel free to continue the discussion. Unfortunately, we don't have time to get to every issue. We are always open to contributions so please send us a pull request if you would like to help. Inactive issues will be closed after 30 days. Thanks!

@stale stale bot added the inactive label Oct 24, 2019
@shilman shilman changed the title Add default route when child is not specified on existing story Core: Allow linking to kind/component ID Oct 24, 2019
@stale stale bot removed the inactive label Oct 24, 2019
@shilman shilman merged commit ef1d964 into storybookjs:next Oct 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants