-
-
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
Addon-docs: Support docs-only MDX && update docs mode nav UI #7302
Conversation
This pull request is automatically deployed with Now. Latest deployment for this branch: https://monorepo-git-6644-docs-only-stories.storybook.now.sh |
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 there is a bug here
const { id, isLeaf, parent } = story; | ||
if (isLeaf) { | ||
if (!filtered[parent].isLeaf) { | ||
filtered[parent].isLeaf = 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.
This logic seems wrong. It is possible to have both leaves and non leaves as children. For instance
GroupA
|-- GroupB
| \-- Story1
\-- Story 2
I think there are some more complex examples in the code base, eg. in https://github.com/storybookjs/storybook/blob/next/lib/ui/src/components/sidebar/treeview/treeview.mockdata.js#L1.
I think to be correct, you'd need to delete story
from parent.children
, then set it to isLeaf
if it is empty
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 just do this (without clone) in a fairly simple way?:
return stories.filter(s => !s.isLeaf).map(({ children, ...story }) => {
const newChildren = children.filter(s => !s.isLeaf);
return newChildren.length === 0 ?
{...story, isLeaf: true } :
{...story, children: newChildren};
});
} | ||
}; | ||
|
||
export const removeDocsOnlyStories = stories => { |
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.
What is this for? It only seems to be used in tests?
const { id, isLeaf, parent, parameters } = story; | ||
if (isLeaf && parameters && parameters.docsOnly) { | ||
if (!filtered[parent].isLeaf) { | ||
filtered[parent].isLeaf = 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.
In theory this has the same problem as removeLeafStories
.
Also you could probably do a no-cloneDeep
version very similar to below
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.
In fact a removeLeaves(stories, predicate?)
function would make sense and remove the need for the duplicate logic.
Issue: #6644
What I did
DOCS_MODE
UI to show only component-level nodesofficial-storybook
Here's how a docs-only node shows up in the UI:
Here's how the tree looks in
--docs
mode:How to test