-
Notifications
You must be signed in to change notification settings - Fork 204
chore(storybook): add migrated components list #3745
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
chore(storybook): add migrated components list #3745
Conversation
|
🚀 Deployed on https://pr-3745--spectrum-css.netlify.app |
File metricsSummaryTotal size: 1.43 MB* 🎉 No changes detected in any packages * Size is the sum of all main files for packages in the library.* An ASCII character in UTF-8 is 8 bits or 1 byte. |
83e37cf
to
17e141a
Compare
|
||
This is a list of all components that have been fully migrated to Spectrum 2. | ||
|
||
<MigratedComponentsList /> |
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.
😍
package.json
Outdated
@@ -15,7 +15,7 @@ | |||
"scripts": { | |||
"build": "yarn builder tag:component,ui-icons", | |||
"build:docs": "yarn build:preview --output-dir ../dist/", | |||
"build:preview": "yarn report && nx build storybook", | |||
"build:preview": "yarn report && yarn component:data && nx build storybook", |
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 wonder if there's a way to include this task as a storybook report. In the storybook project.json, if we use this script as the report, would it get run automatically with the others? What's the downside of doing that, maybe it's run more than it needs to be?
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 picturing you could run it like nx report storybook
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.
Left you a comment! #3745 (comment)
8425ef1
to
5d64978
Compare
📚 Branch previewPR #3745 has been deployed to Azure Blob Storage: https://spectrumcss.z13.web.core.windows.net/pr-3745/index.html. |
5d64978
to
0bd74e6
Compare
"report": { | ||
"executor": "nx:run-commands", | ||
"options": { | ||
"commands": [ | ||
"node tasks/migrated-component-scanner.js --output=.storybook/data/migrated-components.json" | ||
], | ||
"cwd": "{workspaceRoot}" | ||
} |
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.
@castastrophe I added a report
target to the storybook/project.json. Is that sort of what you were going for?
Right now, we can trigger this manually with yarn nx run .storybook:report
According to Cursor, yes it could run more than it needs to.
you can add it as a dependency for other targets (like "build" or "start"), so it runs automatically before those.
Example, to run it before build:
"build": { ... "dependsOn": ["report", ...] }
Downsides / Considerations
Performance: If you add "report" as a dependency for "build" or "start", it will run every time you build or start Storybook, even if the component list hasn't changed. This could be unnecessary if the migration status doesn't change often.
Redundancy: If the script is slow or does heavy file I/O, it could slow down your workflow.Best Practice: Only add "report" as a dependency if you want the report to always be up-to-date for every build. Otherwise, run it manually or as part of CI.
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.
Does that mean that we'd have to run yarn nx run .storybook:report
in order to get a component added/removed from the migrated-components.json
? I noticed I did have a difficult time trying to remove accordion from the json file after I removed the migrated status/tags but see that running report works (guess I should have read the validation instructions first 😏). I can see us easily forgetting to update the migrated list once we merge a migration if it's not a part of our regular workflows.
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.
Right now, yes. We would have to run this manually. I was also curious about this report should be incorporated.
We could add it as a dependency to the build task I think, but that would/could make it run more. I'm thinking maybe we err on the side of running as part of our CI workflow when we try to merge to spectrum-two
. I wanted to explore if we can make it a GH action that would commit the changes if there are any?
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.
This feels separate-ticket worthy to figure out how we keep the list up-to-date without having to manually do it. In the CI would be good, or if we can run it when we run yarn start
locally, then we remember to commit the changes to that file like we do to metadata.json, that would work too.
195b688
to
8e250a8
Compare
8e250a8
to
45b8911
Compare
45b8911
to
7fa91f2
Compare
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.
Works as expected, but I had some other questions related to the code!
// Dynamic loading as fallback | ||
const migrated = getComponentsByStatus({ statusType: 'migrated' }); | ||
|
||
if (migrated && migrated.length > 0) { | ||
setComponents(migrated); |
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.
It seems like this part of the code might be unreachable? If I comment out the previous if block to force the fallback to work, I get an error that this getComponentsByStatus can only be used in a Node.js environment.
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 get that error, but I also don't get anything else. 😭

I think this question and your other question are sort of related. Forgive me if I am restating things you already know.
So I think this is doing exactly what it should- this getComponentsByStatus
is the wrapper, which detects the environment. There isn't really a situation where this would run outside of Node, except possibly with unit testing or SSR I believe. The utility wrapper getComponentByStatus
basically just detects the environment and then passes off any actual logic to the getComponentByStatus
in the migrated-components-scanner.js
file. So if we bypass the logic with the JSON file, the browser returns an empty array and we get the Node warning. According to Cursor, it sounds like it's not expected to work in the browser. And that utility wrapper (at least as it is right now) is basically a fallback for only Node contexts like testing or SSR.
Also Cursor seems to think we should keep that JSON data committed. 😆
</ul> | ||
</> | ||
) : ( | ||
<Body>Loading migrated components...</Body> |
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.
If the fallback to load dynamically doesn't work and we're always pulling from the json file, it might be worth another look to determine if we need a loading state.
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.
Good call. I think that depends on whether we want to commit that JSON file, right? I had some other questions about that file, but this is another good one.
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.
Because, yes, if we always pull from that file, I don't think we need the fallback. 👍
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.
Yep. It's not hurting anything to keep the loading state logic but as it is right now, I don't think there's a situation where we'd see the loading state in the UI.
Now, it is also fair to say we don't have a way to handle if the json file somehow fails after the build (if it's somehow missing when ComponentDetails reaches for it, right now this causes an error; or if the components array is empty, or the components property is missing altogether, which makes the list empty, which is okay)...
And yeah, I'd agree, I think we do want to commit the json file unless it's set up to automatically regenerate when you start storybook?
"report": { | ||
"executor": "nx:run-commands", | ||
"options": { | ||
"commands": [ | ||
"node tasks/migrated-component-scanner.js --output=.storybook/data/migrated-components.json" | ||
], | ||
"cwd": "{workspaceRoot}" | ||
} |
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.
Does that mean that we'd have to run yarn nx run .storybook:report
in order to get a component added/removed from the migrated-components.json
? I noticed I did have a difficult time trying to remove accordion from the json file after I removed the migrated status/tags but see that running report works (guess I should have read the validation instructions first 😏). I can see us easily forgetting to update the migrated list once we merge a migration if it's not a part of our regular workflows.
7fa91f2
to
2871f37
Compare
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.
Just a few more little things! I called out the console.log issue when running the script in the terminal, but I think the main thing that may need addressing is ensuring that we have both text field and text area on the list, or at least minimally, we want text field showing up on the list instead of text area.
Also we'll want to have a follow-up ticket to make sure that we continue to update the list as new components are added!
tasks/migrated-component-scanner.js
Outdated
console.log(`Found ${report.migrated} migrated components out of ${report.total} total components.`); | ||
} else { | ||
console.log("Migrated Components:"); | ||
console.log(report.components.join(", ")); |
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.
If I run this in the terminal, I get a lot of [object Object]
for the list of migrated components, would it be possible to update to something like this to get a readable list there?
console.log(report.components.join(", ")); | |
const componentNames = report.components.map(component => component.title || component.name || component); | |
console.log(componentNames.join(", ")); |
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.
{ | ||
"name": "textfield", | ||
"title": "Text area", | ||
"url": "text-area" | ||
}, |
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.
Hmmm, I was wondering why textfield didn't show up on the list for me, and it is here... just pretending to be text area instead?
tasks/migrated-component-scanner.js
Outdated
const storyFiles = fs.readdirSync(storiesDir).filter(file => file.endsWith(".stories.js")); | ||
let title = null; | ||
for (const file of storyFiles) { | ||
title = extractTitleFromStoryFile(path.join(storiesDir, file)); | ||
if (title) break; |
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 logic around here needs updating if we want to be able to pick up both text field and text area. When I log storyFiles
for text field I get [ 'textarea.stories.js', 'textfield.stories.js' ]
, but then we have it set up to only extract one title and in this weird edge case we have two.
I think that's the only place where we have that situation though. I wonder if there are other places where this is potentially causing an issue? If so we could consider modifying the way textfield and textarea are packaged?
My vote based on what I know currently would be trying to update the logic here rather than doing 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.
"name": "stepper", | ||
"title": "Number field", | ||
"url": "number-field" |
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.
It's probably because only that component's title
in Storybook is Number field- it's package and component name that we ship are still Stepper.
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.
Yeah, we could do something to sort it alphabetically by title if we want it to be ordered in a more expected way, or potentially put the name
in parentheses so it reads "Number field (stepper)" (I'm thinking without looking closely at the code that you'd do this in any situation where the lowercased joined/no-space/no-punctuation title is different from the name, so it would catch this and also breadcrumbs/breadcrumb), but it's also ok as is.
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.
"report": { | ||
"executor": "nx:run-commands", | ||
"options": { | ||
"commands": [ | ||
"node tasks/migrated-component-scanner.js --output=.storybook/data/migrated-components.json" | ||
], | ||
"cwd": "{workspaceRoot}" | ||
} |
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.
This feels separate-ticket worthy to figure out how we keep the list up-to-date without having to manually do it. In the CI would be good, or if we can run it when we run yarn start
locally, then we remember to commit the changes to that file like we do to metadata.json, that would work too.
- adds a MigratedComponentsList() block to ComponentDetails.jsx. That block gets used in the S2 Migration guide MDX file - adds a migrated-component-scanner.js task to scan the components directory and generate a list of migrated components based on their status (status: type: "migrated") - adds a migrated-components.json file to the .storybook/data directory - updates the package.json scripts to include the new migrated-component-scanner.js task so that it builds and captures the migration status when storybook is started
- captures the component title so it displays with proper capitalization in the list - generate a component url so it can be used to link to component docs
- in .storybook/project.json, a report script generates the migrated components list - yarn nx run .storybook:report can manually run migrated-component- scanner.js - removes component:data sripts from package.json commands
- alphabetically sort console output - handle directories that have multiple story files with different components/titles - add code comments/documentation
6b38dbe
to
5c7f567
Compare
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 I'm going to close this, just in case we ever want to come back to this script (that feels unlikely, but you never know!) I'll open a new branch to document the filtering-by-tag functionality better. That will be loads easier and will remove the extra work we identified in this PR related to keeping the list up to date. Thanks @rise-erpelding and @castastrophe! |
Description
DISCLAIMER: MOST CODE GENERATED BY CURSOR
report
target that runsmigrated-component-scanner.js
so that it builds and captures the migration statusJira/Specs
CSS-1259
How and where has this been tested?
Please tag yourself on the tests you've marked complete to confirm the tests have been run by someone other than the author.
Validation steps
yarn nx run .storybook:report
should run themigrated-component-status.js
task. You should get some feedback like this in the terminal: [@rise-erpelding]Don't be alarmed if you see changes in the
migrated-components.json
file- new components merged so that's a good sign that this script is working!Regression testing
Validate:
Screenshots
Screen.Recording.2025-07-25.at.12.41.55.PM.mov
To-do list