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

docs(storybook): fix code tab #1607

Merged
merged 1 commit into from
Sep 25, 2024
Merged

docs(storybook): fix code tab #1607

merged 1 commit into from
Sep 25, 2024

Conversation

kabaros
Copy link
Collaborator

@kabaros kabaros commented Sep 24, 2024

fixes LIBS-672 - you can verify the working code tabs on the preview link: https://pr-1607--dhis2-ui.netlify.app/demo


  • My first attempt to fix this was to get the official addons/storysource to work but failed to. From what I see in its code, I think it would require that we manually add a storySource attribute to the components which we could probably use a library like react-to-jsx to automate but it's still a significant change.

    I can't imagine that this is the default way for displaying components source code so should investigate more. (the other likely cause is our webpack config and the way we load stories - few discussions online point to that direction) but I tried different changes there and didn't manage to get the addon working.

  • My second attempt was to update storybook-addon-jsx which we used previously before updating StoryBook. That addon was not updated for storybook@7 or 8 and it breaks as it requires an internal API no longer available. I found a thread here where someone created an alternative package. It's not a widely used package but it does the job of the previous addon.

So maybe we can use it as a stopgap until we figure how to get StorySource working.


❓ Another approach we could consider, is to embed the source code with the docs, like this one here - we could then maybe get rid of /demo entirely? @Topener

@dhis2-bot
Copy link
Contributor

dhis2-bot commented Sep 24, 2024

🚀 Deployed on https://pr-1607--dhis2-ui.netlify.app

@dhis2-bot dhis2-bot temporarily deployed to netlify September 24, 2024 17:14 Inactive
@kabaros kabaros force-pushed the fix/storybook-code-tab branch 3 times, most recently from 8204664 to a229b01 Compare September 24, 2024 19:19
@kabaros kabaros marked this pull request as ready for review September 24, 2024 19:23
@kabaros kabaros requested a review from a team as a code owner September 24, 2024 19:23
@dhis2-bot dhis2-bot temporarily deployed to netlify September 24, 2024 19:25 Inactive
@kabaros kabaros requested review from Topener, Mohammer5 and a team September 24, 2024 19:28
@kabaros kabaros force-pushed the fix/storybook-code-tab branch 2 times, most recently from c40e93b to ac24f0e Compare September 24, 2024 19:53
@dhis2-bot dhis2-bot temporarily deployed to netlify September 24, 2024 19:58 Inactive
Copy link
Contributor

@Topener Topener left a comment

Choose a reason for hiding this comment

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

LGTM! The code samples even change when changing the controls which is excellent. This is also why I wouldn't want to get rid of the code blocks, as they do not show interactivity that way. Codesandbox or similar would be another possible solution in that case. Let's try to keep Storybook working for now!

Copy link
Contributor

@Mohammer5 Mohammer5 left a comment

Choose a reason for hiding this comment

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

+1 to what @Topener said

Copy link
Contributor

@KaiVandivier KaiVandivier left a comment

Choose a reason for hiding this comment

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

Nice 🙂 just a question below

P.S. This could be a docs: commit

import '@storybook/addon-console'
const { withJsx } = require('@mihkeleidast/storybook-addon-source')
Copy link
Contributor

Choose a reason for hiding this comment

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

I tried out using an import locally to see if it would work, and it does, but eslint complains:

Unable to resolve path to module '@mihkeleidast/storybook-addon-source'. eslint import/no-unresolved

Is that why this is a require?

It works though! 🙂

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yeah it is .. do you prefer we just disable the rule for that line?

@kabaros kabaros force-pushed the fix/storybook-code-tab branch from ac24f0e to 7722ebd Compare September 25, 2024 16:54
@kabaros kabaros changed the title fix(storybook): fix code tab docs(storybook): fix code tab Sep 25, 2024
@kabaros kabaros enabled auto-merge (squash) September 25, 2024 16:57
@dhis2-bot dhis2-bot temporarily deployed to netlify September 25, 2024 16:58 Inactive
@kabaros kabaros merged commit 37d0b5a into master Sep 25, 2024
17 checks passed
@kabaros kabaros deleted the fix/storybook-code-tab branch September 25, 2024 17:02
@dhis2-bot
Copy link
Contributor

🎉 This PR is included in version 9.11.5 🎉

The release is available on:

Your semantic-release bot 📦🚀

@dhis2-bot
Copy link
Contributor

🎉 This PR is included in version 10.0.0-alpha.7 🎉

The release is available on:

Your semantic-release bot 📦🚀

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.

5 participants