-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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: Fix api.selectStory
for component permalinks
#9054
Conversation
This pull request is being automatically deployed with ZEIT Now (learn more). 🔍 Inspect: https://zeit.co/storybook/monorepo/ozskfue97 |
api.selectStory
in the case of component permalinksapi.selectStory
for component permalinks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion to make it simpler
// Support legacy API with component permalinks, where kind is `x/y` but permalink is 'z' | ||
const k = storiesHash[sanitize(kindOrId)]; | ||
if (k && k.children) { | ||
const foundId = k.children.find(childId => storiesHash[childId].name === story); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be better to do:
// This kind has a custom id, look up the story using it
if (k && k.id !== sanitize(kindOrId))
return selectStory(k.id, story)
PS prefer kind
to k
if the code is more than one line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Unfortunately k.id is sanitize(kindOrId)
kind
was already in scope
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there nothing stored on the kind in the store to indicate its custom id? Should we change that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like this line of code is pretty dodgy and we'll regret it in the long run
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that the entire setup is lacking integrity, but I don't have a good idea for a better setup. Any suggestions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where would this get passed in:
storiesOf({ kind, componentId }, module).add(...);
storiesOf(kind, module).setComponentId(componentId);
???
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, so currently we don't store componentId
at all, we just change the individual stories id
s based on it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest setComponentId()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tmeasday there's no intermediate data structure in story_store
to hold this AFAIK. i feel like this is all getting out of scope.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, fair enough.
// Support legacy API with component permalinks, where kind is `x/y` but permalink is 'z' | ||
const k = storiesHash[sanitize(kindOrId)]; | ||
if (k && k.children) { | ||
const foundId = k.children.find(childId => storiesHash[childId].name === story); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there nothing stored on the kind in the store to indicate its custom id? Should we change that?
Issue: #8507 (follow-up)
What I did
Added some cases to take care of some
addon-links
bugs, which may also be broken in other uses of the API.How to test
See updated unit tests &
official-storybook