Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions code/core/src/core-server/utils/StoryIndexGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import type {
Path,
StoryIndex,
StoryIndexEntry,
StoryIndexInput,
StorybookConfigRaw,
Tag,
} from 'storybook/internal/types';
Expand Down Expand Up @@ -414,7 +415,9 @@ export class StoryIndexGenerator {

invariant(indexer, `No matching indexer found for ${absolutePath}`);

const indexInputs = await indexer.createIndex(absolutePath, { makeTitle: defaultMakeTitle });
const indexInputs = (await indexer.createIndex(absolutePath, {
makeTitle: defaultMakeTitle,
})) as StoryIndexInput[]; // we don't actually support DocsIndexInputs at runtime, although types say we do
const tsconfigPath = find.up('tsconfig.json', {
cwd: this.options.workingDir,
last: getProjectRoot(),
Expand All @@ -439,10 +442,11 @@ export class StoryIndexGenerator {

const id = input.__id ?? toId(input.metaId ?? title, storyNameFromExport(input.exportName));
const tags = combineTags(...projectTags, ...(input.tags ?? []));
const subtype = input.subtype ?? 'story';

return {
const entry: StoryIndexEntryWithExtra & { tags: Tag[] } = {
type: 'story',
subtype: input.type === 'story' ? input.subtype : 'story',
subtype,
id,
extra: {
metaId: input.metaId,
Expand All @@ -453,11 +457,17 @@ export class StoryIndexGenerator {
importPath,
componentPath,
tags,
...(input.type === 'story' && input.subtype === 'test'
? { parent: input.parent, parentName: input.parentName }
: {}),
...(input.exportName ? { exportName: input.exportName } : {}),
};

if (subtype === 'test') {
entry.parent = input.parent;
entry.parentName = input.parentName;
}
if (input.exportName) {
entry.exportName = input.exportName;
}

return entry;
}
);

Expand Down
4 changes: 3 additions & 1 deletion code/core/src/types/modules/indexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ export interface BaseIndexEntry {
export type StoryIndexEntry = BaseIndexEntry & {
type: 'story';
subtype: 'story' | 'test';
componentPath?: string;
exportName?: string;
parent?: StoryId; // exists only on tests
parentName?: StoryName; // exists only on tests
};
Expand Down Expand Up @@ -134,7 +136,7 @@ export type BaseIndexInput = {
/** The input for indexing a story entry. */
export type StoryIndexInput = BaseIndexInput & {
type: 'story';
subtype: 'story' | 'test';
subtype?: 'story' | 'test';
parent?: StoryId; // exists only on tests
parentName?: StoryName; // exists only on tests
};
Expand Down
1 change: 0 additions & 1 deletion code/renderers/server/src/preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ export const experimental_indexers: PresetProperty<'experimental_indexers'> = (
title: content.title,
tags,
type: 'story',
subtype: 'story',
};
});
},
Expand Down
13 changes: 12 additions & 1 deletion docs/api/main-config/main-config-indexers.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ Type:
exportName: string;
importPath: string;
type: 'story';
subtype?: 'story' | 'test';
rawComponentPath?: string;
metaId?: string;
name?: string;
Expand Down Expand Up @@ -130,6 +131,16 @@ Type: `'story'`

The type of entry.

##### `subtype`

(⚠️ **Experimental**)

Type: `'story' | 'test'`

Default: `'story'`

The subtype of the story entry when [`type`](#type) is `'story'`. Use this to mark an entry as a [_test_ (experimental)](https://github.com/storybookjs/storybook/discussions/30119). If not specified, defaults to `'story'`.

##### `rawComponentPath`

Type: `string`
Expand Down Expand Up @@ -487,4 +498,4 @@ Some example usages of custom indexers include:

This example's code and live demo are available on [StackBlitz](https://stackblitz.com/~/github.com/Sidnioulz/storybook-sidebar-urls).

</details>
</details>