-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
Manager: Add tags property to GroupEntry objects #29672
Manager: Add tags property to GroupEntry objects #29672
Conversation
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.
4 file(s) reviewed, 2 comment(s)
Edit PR Review Bot Settings | Greptile
☁️ Nx Cloud ReportCI is running/has finished running commands for commit 8496e3e. As they complete they will appear below. Click to see the status, the terminal output, and the build insights. 📂 See all runs for this CI Pipeline Execution ✅ Successfully ran 1 targetSent with 💌 from NxCloud. |
@@ -21,6 +21,7 @@ export interface API_GroupEntry extends API_BaseEntry { | |||
type: 'group'; | |||
parent?: StoryId; | |||
children: StoryId[]; | |||
tags: Tag[]; |
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.
WDYT about updating API_BaseEntry
and propagating tags all the way up to the roots?
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 would make the TS API a bit cleaner indeed. But I doubt it would make sense as there's virtually no way the intersection of all stories' tags makes sense to compute. It would likely be a waste of CPU resources to compute.
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.
As far as I understand here, you are propagating N-2 levels up the tree. The roots add a single extra level, which means one extra intersection per root, which means almost no extra computation compared to this change. For the benefit of a cleaner, more consistent API.
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.
You're right that it doesn't cost that much and would simplify API for all users. Let me give it a go and see where it takes me!
I wonder if it would make sense to just document it as an empty array for 'root' entries, as that's what we expect would happen?
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 also realise that I do indeed go down N-2, which was not intended. I wanted tag intersections computed as an intersection of direct children for obvious performance reasons.
I'll rework the code to do all tag intersection in a separate pass, starting from leaves and going back up the tree.
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 ended up having to edit a few tests, because many test mock entries did not have tags defined in their input. This was a good opportunity to realise that tags, whilst mandatory on story entries, were never initialised and assumed to exist. I added an initialisation to an empty array when creating hash stories, prior to destructuring the index story item, to ensure types will remain valid in the future. Happy to remove that if you find it unnecessary.
What I did
I edited the code converting the story index to story hashes for use in the manager (transformStoryIndexToStoriesHash), to add a
tags
property for'group'
entries, which is the intersection of all their stories' hashes.This is the
'group'
counterpart of #29343. I am opening the PR because users of my addon have come to me requesting support for badges in group entries of the sidebar, which requires that tags are also computed for these: Sidnioulz/storybook-addon-tag-badges#20.Checklist for Contributors
Testing
The changes in this PR are covered in the following automated tests:
Manual testing
Add a tag 'new' to a component:
Add https://github.com/Sidnioulz/storybook-addon-tag-badges and verify that the tag shows up in the sidebar at the component level.
Add the tag
deprecated
to one of the stories, and verify that it shows up at the story level. Add the tagdeprecated
to all of the stories in the component and verify that it shows up at the component level in the sidebar.OR
renderLabel
function that prints all tagsstorybook:ui
instanceDocumentation
Still not sure how/where to document this, like I pointed out in the component PR.
Checklist for Maintainers
When this PR is ready for testing, make sure to add
ci:normal
,ci:merged
orci:daily
GH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found incode/lib/cli-storybook/src/sandbox-templates.ts
Make sure this PR contains one of the labels below:
Available labels
bug
: Internal changes that fixes incorrect behavior.maintenance
: User-facing maintenance tasks.dependencies
: Upgrading (sometimes downgrading) dependencies.build
: Internal-facing build tooling & test updates. Will not show up in release changelog.cleanup
: Minor cleanup style change. Will not show up in release changelog.documentation
: Documentation only changes. Will not show up in release changelog.feature request
: Introducing a new feature.BREAKING CHANGE
: Changes that break compatibility in some way with current major version.other
: Changes that don't fit in the above categories.🦋 Canary release
This PR does not have a canary release associated. You can request a canary release of this pull request by mentioning the
@storybookjs/core
team here.core team members can create a canary release here or locally with
gh workflow run --repo storybookjs/storybook canary-release-pr.yml --field pr=<PR_NUMBER>
Greptile Summary
Added support for tags in GroupEntry objects within the Storybook manager's sidebar, computing them as the intersection of child stories' tags.
tags
property toAPI_GroupEntry
interface incode/core/src/types/modules/api-stories.ts
intersect
utility incode/core/src/manager-api/lib/intersect.ts
with stricter array validationtransformStoryIndexToStoriesHash
incode/core/src/manager-api/lib/stories.ts
to compute group entry tagscode/core/src/manager-api/tests/stories.test.ts
verifying tag inheritance for group entries