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

Makes name argument for 'toId' optional #17

Merged
merged 2 commits into from
Oct 1, 2021
Merged

Makes name argument for 'toId' optional #17

merged 2 commits into from
Oct 1, 2021

Conversation

unematiii
Copy link
Contributor

This PR allows generating storybook ID only from a component/kind and would help getting this fixed.

src/index.ts Outdated
`${sanitizeSafe(kind, 'kind')}--${sanitizeSafe(name, 'name')}`;
export const toId = (kind: string, name?: string) =>
`${sanitizeSafe(kind, 'kind')}${
typeof name === 'string' ? `--${sanitizeSafe(name, 'name')}` : ''
Copy link

Choose a reason for hiding this comment

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

I think it's enough to check if name exists here. You can skip typecheking here. WDYT?

name ? `--${sanitizeSafe(name, 'name')}` : ''

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I thought so too, but there's a test case for throwing an exception should the argument (name) be empty string. Without typecheking, an empty string would never be passed to sanitizeSafe and the function will not throw. Wasn't sure, if I should keep this behavior (throwing an exception)... Then again, the whole issue here is making the name arg optional...

Copy link
Contributor

Choose a reason for hiding this comment

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

I went ahead and allowed '' as story. We're intentionally adding support for this, so the test had to change.

Copy link
Contributor

@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.

LGTM, makes sense I think

@karmasalad
Copy link

Will this be merged soon? We need this update to fix the related Storybook bug in our implementation.

@shilman
Copy link
Contributor

shilman commented Apr 3, 2023

🚀 PR was released in v0.1.0 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants