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

Addon-docs: Fix 'show source' for stories with dynamic title #10959

Merged

Conversation

adamborowski
Copy link
Contributor

@adamborowski adamborowski commented May 28, 2020

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

  • Is this testable with Jest or Chromatic screenshots?
    Yes, tests are updated
  • Does this need a new example in the kitchen sink apps?
    Yes, one story was added to how dynamic title exapmle
  • Does this need an update to the documentation?
    No this is a bug

If your answer is yes to any of these, please make sure to include it in your PR.

(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]}`;
Copy link
Contributor Author

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`] = `
Copy link
Contributor Author

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(/^.*?--/, '');
Copy link
Contributor Author

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`] = `
Copy link
Contributor Author

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

@adamborowski
Copy link
Contributor Author

@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?
Also I see many jobs failing but looking at the logs it is more related to temporary environment issues not the code.

@shilman
Copy link
Member

shilman commented May 30, 2020

Yes I’ll review it in the next week

@adamborowski
Copy link
Contributor Author

adamborowski commented Jun 3, 2020

@shilman can you just have a quick look for this and say if this is on acceptable level?
If yes, I will prepare PR for v5 as well as we really want to get this fixed in v5 without creating our own fork

Copy link
Member

@shilman shilman left a 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(),
Copy link
Member

Choose a reason for hiding this comment

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

I personally think this is a bad idea, sure it's expressive, but we're trying to make CSF simple and statically analyzable as much as possible.

@shilman @tmeasday what are your opinion on supporting this?

Does supporting this add complexity?
Is it worth it?
To what degree are dynamic titles ok?

Copy link
Contributor Author

@adamborowski adamborowski Jun 5, 2020

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

#9582

Copy link
Member

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?

Copy link
Contributor Author

@adamborowski adamborowski Jun 9, 2020

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.

Copy link
Member

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

@adamborowski adamborowski changed the title #9582 support dynamic title for stories #9582 support 'show source' for stories with dynamic titles Jun 5, 2020
@adamborowski adamborowski changed the title #9582 support 'show source' for stories with dynamic titles #9582 support 'show source' for stories with dynamic title Jun 5, 2020
@shilman shilman changed the title #9582 support 'show source' for stories with dynamic title Source: Support 'show source' for stories with dynamic title Jun 9, 2020
@shilman shilman changed the title Source: Support 'show source' for stories with dynamic title Source: Fix 'show source' for stories with dynamic title Jun 9, 2020
@adamborowski
Copy link
Contributor Author

Hi. Can you share your plans regarding to this bugfix? It is very important for us

Copy link
Member

@shilman shilman left a 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).

@shilman shilman added this to the 6.0 docs milestone Jun 16, 2020
@shilman shilman changed the title Source: Fix 'show source' for stories with dynamic title Source-loader: Fix 'show source' for stories with dynamic title Jun 16, 2020
@shilman shilman changed the title Source-loader: Fix 'show source' for stories with dynamic title Addon-docs: Fix 'show source' for stories with dynamic title Jun 16, 2020
@shilman shilman merged commit 912ad04 into storybookjs:next Jun 16, 2020
@adamborowski
Copy link
Contributor Author

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.

@shilman
Copy link
Member

shilman commented Jun 16, 2020

@adamborowski would love to see your requirements. i've created a placeholder issue here #11186 cc @ndelangen @tmeasday

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.

None yet

4 participants