-
-
Notifications
You must be signed in to change notification settings - Fork 9.2k
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
Addon-docs: Fix 'show source' for stories with dynamic title #10959
Addon-docs: Fix 'show source' for stories with dynamic title #10959
Conversation
(snapshots were updated and manually compared because cases were reordered due to change in id (title was removed from key)
@@ -0,0 +1,7 @@ | |||
const getTitle = () => `Addons/Docs/${['dynamic title'][0]}`; |
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.
we can use something more 'dynamic' but I think this is enough
@@ -292,7 +292,28 @@ storiesOf('Custom|ng-content', module).addParameters({ storySource: { source: __ | |||
" | |||
`; | |||
|
|||
exports[`inject-decorator positive - flow calculates "adds" map 1`] = `Object {}`; | |||
exports[`inject-decorator positive - flow calculates "adds" map 1`] = ` |
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.
looks like it also fixed existing snapshot that was false positive
* Replaces full story id name like: story-kind--story-name -> story-name | ||
* @param id | ||
*/ | ||
const storyIdToSanitizedStoryName = (id: string) => id.replace(/^.*?--/, ''); |
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 don't like this function but we can't use context.name as it can be overriden by CSF. The id is the only place that contains original sanitized name but it also contains story title (before -- double dash).
So I simply remove sanitized story title from id and get sanitized name
@@ -393,25 +414,7 @@ storiesOf('ngrx|Store', module).addParameters({ storySource: { source: __STORY__ | |||
|
|||
exports[`inject-decorator positive calculates "adds" map 1`] = ` |
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.
checked this snapshot manually, we see lot of changes only because items in object were reordered because key was renamed and it orders it alphabetically
@shilman are you going to review this soon? I want to prepare PR to stable version as well after successful merge of this one. Do you need any more discussion? |
Yes I’ll review it in the next week |
@shilman can you just have a quick look for this and say if this is on acceptable level? |
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 need to test but looks OK to me on quick inspection. I don’t want to release this in 5.x: it’s painful and time consuming if anything goes wrong in a patch release. 6.0 is closing in on RC so it’s a natural fit there.
const getTitle = () => `Addons/Docs/${['dynamic title'][0]}`; | ||
|
||
export default { | ||
title: getTitle(), |
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.
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 think that dynamic story titles are very common. Especially in big monorepo projects. The proposed PR doesn't directly support this it only fills the gap. I didn't see any docs in storybook about limitations to title, but indeed I could see a section in docs about using babel macros to generate title. So now it looks like feature gap.
Please look at this:
https://storybook.js.org/docs/basics/writing-stories/#generating-nesting-path-based-on-__dirname
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 think the last discussion we had about it we were tending to lean towards rather than allowing fully dynamic titles to instead to look at common systems of generating them. The primary one is of course setting titles based on filesystem paths -- are there other ways people are setting dynamic titles apart from purely based on the path of the file?
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.
We also include package.json name.
But is this PR relevant place to discuss it?
I understand that you discuss about the approach to generate titles but I don't see any other ways to fix the source code button rather than not relying on final id because looks like it is not necessary. Even if you decide to limit somehow the freedom of generating titles.
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'm guessing we should merge this and discuss options on what to do with the above
Hi. Can you share your plans regarding to this bugfix? It is very important for us |
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.
@adamborowski thanks for your patience on this and for the solid PR.
We don't want to support fully dynamic titles in CSF/MDX. But given that there is not yet any alternative, this is a good fix for the current situation.
The plan:
- Merge now & release on beta. RC in ~2 wks.
- Explore stylized alternatives fully dynamic titles at some point in the 6.x cycle.
- Possibly remove support for fully dynamic titles in 7.0 (be forewarned).
Thanks for cooperation. I am very interested to see how you imagine maintaining story tree in big monorepos. Do you plan to make some RFC in the future? We can show how we organize story tree using our Babel macro, that may clarify some future requirements. |
@adamborowski would love to see your requirements. i've created a placeholder issue here #11186 cc @ndelangen @tmeasday |
Issue: #9582
What I did
Do not refer to story title in addsMap keys - they are not needed.
Instead use just sanitized story name.
Snapshots were updated and manually compared because cases were reordered due to change in id (title was removed from key)
How to test
Yes, tests are updated
Yes, one story was added to how dynamic title exapmle
No this is a bug
If your answer is yes to any of these, please make sure to include it in your PR.