-
-
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
Merged
Merged
Changes from 14 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
4304831
add a experimental API for adding sidebar filter functions at runtime
ndelangen cda5eed
Merge branch 'next' into norbert/sidebar-filter-api
ndelangen e92a19c
add support for setting filters in manager.ts & cleanup manager-api i…
ndelangen c3a88ec
Merge branch 'next' into norbert/sidebar-filter-api
ndelangen 3192b9b
fix up the test
ndelangen c9a5435
re-grouping code
ndelangen e5d6730
cleanup
ndelangen 9c16de6
Merge branch 'next' into norbert/sidebar-filter-api
ndelangen 664d60c
cleanup
ndelangen 5ebb31e
add tests
ndelangen 478046e
Merge branch 'next' into norbert/sidebar-filter-api
ndelangen 3afb02c
Merge branch 'norbert/fix-setConfig-execution-order' into norbert/sid…
ndelangen e812cd1
Merge branch 'norbert/fix-setConfig-execution-order' into norbert/sid…
ndelangen 6e4428d
Discard changes to code/lib/manager-api/src/lib/events.ts
ndelangen 12afa82
Update code/ui/.storybook/manager.tsx
ndelangen e135983
Merge branch 'next' into norbert/sidebar-filter-api
ndelangen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
import { addons, types } from '@storybook/manager-api'; | ||
import { IconButton, Icons } from '@storybook/components'; | ||
import startCase from 'lodash/startCase.js'; | ||
import React, { Fragment } from 'react'; | ||
|
||
addons.setConfig({ | ||
sidebar: { | ||
renderLabel: ({ name, type }) => (type === 'story' ? name : startCase(name)), | ||
// filters: { | ||
// a: (item) => item.depth === 2, | ||
// }, | ||
ndelangen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
import React from 'react'; | ||
import React, { useMemo } from 'react'; | ||
|
||
import type { Combo, StoriesHash } from '@storybook/manager-api'; | ||
import { Consumer } from '@storybook/manager-api'; | ||
|
||
import { Sidebar as SidebarComponent } from '../components/sidebar/Sidebar'; | ||
import { useMenu } from './menu'; | ||
import { getAncestorIds } from '../utils/tree'; | ||
|
||
export type Item = StoriesHash[keyof StoriesHash]; | ||
|
||
|
@@ -16,11 +17,12 @@ const Sidebar = React.memo(function Sideber() { | |
storyId, | ||
refId, | ||
layout: { showToolbar, isFullscreen, showPanel, showNav }, | ||
index, | ||
index: originalIndex, | ||
status, | ||
indexError, | ||
previewInitialized, | ||
refs, | ||
filters, | ||
} = state; | ||
|
||
const menu = useMenu( | ||
|
@@ -36,6 +38,34 @@ const Sidebar = React.memo(function Sideber() { | |
const whatsNewNotificationsEnabled = | ||
state.whatsNewData?.status === 'SUCCESS' && !state.disableWhatsNewNotifications; | ||
|
||
const index = useMemo(() => { | ||
if (!originalIndex) { | ||
return originalIndex; | ||
} | ||
|
||
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 commentThe reason will be displayed to describe this comment to others. Learn more. Can result be called something more explicit? |
||
|
||
Object.values(filters).forEach((filter) => { | ||
if (result === true) { | ||
result = filter({ ...item, status: status[item.id] }); | ||
} | ||
}); | ||
|
||
if (result) { | ||
filtered.add(item.id); | ||
getAncestorIds(originalIndex, item.id).forEach((id) => { | ||
filtered.add(id); | ||
}); | ||
} | ||
} | ||
}); | ||
|
||
return Object.fromEntries(Object.entries(originalIndex).filter(([key]) => filtered.has(key))); | ||
}, [originalIndex, filters, status]); | ||
|
||
return { | ||
title: name, | ||
url, | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.