-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
UI: Add an experimental API for adding sidebar filter functions at runtime #23722
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.
Can we have some tests please!
Some questions:
- How do you remove a filter?
- What do you do when some external variable that affects the filter changes? Should you remove the filter and re-add it?
* | ||
* @param {string} addonId - The ID of the addon to update. | ||
* @param {API_FilterFunction} filterFunction - A function that returns a boolean based on the story, index and status. | ||
* @returns {Promise<void>} A promise that resolves when the state has been updated. |
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.
Maybe it should return an off
function.
…nit so less race conditions happen
I had imagined you cannot remove the filter, I figured that you'd set a new filter that just always return I added tests! |
I don't really understand though. If you set >1 filter, don't they both apply? So wouldn't adding a
Can we split the PR up and just do this bit first? I'd like to go over this one together in more detail because as I said elsewhere, I think the approach of doing the filtering in the nodes isn't the right approach, we should filter right at the top in the store. Otherwise we'll constantly be having to refilter everytime we interact with the stories hash, eg in keyboard shortcuts or when addons get the story list, etc. |
Did you forget to push this bit? |
I split the PRs apart @tmeasday |
const filtered = new Set(); | ||
Object.values(originalIndex).forEach((item) => { | ||
if (item.type === 'story' || item.type === 'docs') { | ||
let result = true; |
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.
Can result be called something more explicit?
Co-authored-by: Yann Braga <yannbf@gmail.com>
Telescoped off: #23802
What I did
I introduced a new manager API!
It's marked as experimental for now.
The purpose is to allow users and addon-creators to inject (dynamically at runtime) filter functions that filter the list of stories in the sidebar. I know this has been a feature that has been requested many times for a varied use-cases.
I've implemented the actual filtering in the sidebar, but this code will likely need optimization.
And with this optimization there will be assumptions in when the filters are re-evaluated.
A
FilterFunction
receives an (with status extended)IndexHash_Item
and returns a boolean.Storybook will only ask to filter leaf-items (story and docs).
Storybook will filter out empty components/groups/roots for you.
How to test
This API can be used via from
manager.ts
:The expected result is that the sidebar stories are filtered.
Checklist
MIGRATION.MD
Maintainers
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/src/sandbox-templates.ts
["cleanup", "BREAKING CHANGE", "feature request", "bug", "build", "documentation", "maintenance", "dependencies", "other"]
🦋 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>