mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-09 00:19:13 +08:00
Addon-docs: Filter out docs-only stories from story_store.raw/extract by default
This commit is contained in:
parent
110b6eb05a
commit
8bd924db2a
@ -46,6 +46,21 @@ interface Selection {
|
||||
viewMode: string;
|
||||
}
|
||||
|
||||
interface StoryFilter {
|
||||
includeDocsOnly?: boolean;
|
||||
}
|
||||
|
||||
const isStoryDocsOnly = (parameters?: Parameters) => {
|
||||
return parameters && parameters.docsOnly;
|
||||
};
|
||||
|
||||
const includeStory = (story: StoreItem, filter: StoryFilter = { includeDocsOnly: false }) => {
|
||||
if (filter.includeDocsOnly) {
|
||||
return true;
|
||||
}
|
||||
return !isStoryDocsOnly(story.parameters);
|
||||
};
|
||||
|
||||
export default class StoryStore extends EventEmitter {
|
||||
_error?: ErrorLike;
|
||||
|
||||
@ -93,13 +108,14 @@ export default class StoryStore extends EventEmitter {
|
||||
}
|
||||
};
|
||||
|
||||
raw() {
|
||||
raw(filter?: StoryFilter) {
|
||||
return Object.values(this._data)
|
||||
.filter(i => !!i.getDecorated)
|
||||
.filter(i => includeStory(i, filter))
|
||||
.map(({ id }) => this.fromId(id));
|
||||
}
|
||||
|
||||
extract() {
|
||||
extract(filter?: StoryFilter) {
|
||||
const stories = Object.entries(this._data);
|
||||
// determine if we should apply a sort to the stories or just use default import order
|
||||
if (Object.values(this._data).length > 0) {
|
||||
@ -113,7 +129,10 @@ export default class StoryStore extends EventEmitter {
|
||||
}
|
||||
}
|
||||
// removes function values from all stories so they are safe to transport over the channel
|
||||
return stories.reduce((a, [k, v]) => Object.assign(a, { [k]: toExtracted(v) }), {});
|
||||
return stories.reduce(
|
||||
(a, [k, v]) => (includeStory(v, filter) ? Object.assign(a, { [k]: toExtracted(v) }) : a),
|
||||
{}
|
||||
);
|
||||
}
|
||||
|
||||
setSelection(data: Selection | undefined, error: ErrorLike): void {
|
||||
@ -204,7 +223,9 @@ export default class StoryStore extends EventEmitter {
|
||||
};
|
||||
|
||||
// LEGACY DATA
|
||||
this.addLegacyStory({ kind, name, storyFn, parameters });
|
||||
if (!isStoryDocsOnly(parameters)) {
|
||||
this.addLegacyStory({ kind, name, storyFn, parameters });
|
||||
}
|
||||
|
||||
// LET'S SEND IT TO THE MANAGER
|
||||
this.pushToManager();
|
||||
@ -212,7 +233,7 @@ export default class StoryStore extends EventEmitter {
|
||||
|
||||
pushToManager = debounce(() => {
|
||||
if (this._channel) {
|
||||
const stories = this.extract();
|
||||
const stories = this.extract({ includeDocsOnly: true });
|
||||
|
||||
// send to the parent frame.
|
||||
this._channel.emit(Events.SET_STORIES, { stories });
|
||||
|
Loading…
x
Reference in New Issue
Block a user