diff --git a/lib/api/src/lib/stories.ts b/lib/api/src/lib/stories.ts index b27abb07373..7f0d63730fd 100644 --- a/lib/api/src/lib/stories.ts +++ b/lib/api/src/lib/stories.ts @@ -110,6 +110,7 @@ export interface StoriesRaw { type Path = string; export interface StoryIndexStory { + id: StoryId; name: StoryName; title: ComponentTitle; importPath: Path; diff --git a/lib/client-api/src/StoryStoreFacade.ts b/lib/client-api/src/StoryStoreFacade.ts index f7ad304c2d6..daf8824e1a7 100644 --- a/lib/client-api/src/StoryStoreFacade.ts +++ b/lib/client-api/src/StoryStoreFacade.ts @@ -67,7 +67,7 @@ export class StoryStoreFacade { const storyEntries = Object.entries(this.stories); // Add the kind parameters and global parameters to each entry - const stories: [StoryId, Story, Parameters, Parameters][] = storyEntries.map( + const sortableV6: [StoryId, Story, Parameters, Parameters][] = storyEntries.map( ([storyId, { importPath }]) => { const exports = this.csfExports[importPath]; const csfFile = store.processCSFFileWithCache(exports, exports.default.title); @@ -80,11 +80,14 @@ export class StoryStoreFacade { } ); - return { - v: 3, - // NOTE: the sortStoriesV6 version returns the v7 data format. confusing but more convenient! - stories: sortStoriesV6(stories, storySortParameter, fileNameOrder), - }; + // NOTE: the sortStoriesV6 version returns the v7 data format. confusing but more convenient! + const sortedV7 = sortStoriesV6(sortableV6, storySortParameter, fileNameOrder); + const stories = sortedV7.reduce((acc, s) => { + acc[s.id] = s; + return acc; + }, {} as StoryIndex['stories']); + + return { v: 3, stories }; } clearFilenameExports(fileName: Path) { diff --git a/lib/store/src/sortStories.ts b/lib/store/src/sortStories.ts index 2dc580754f4..acc9692443c 100644 --- a/lib/store/src/sortStories.ts +++ b/lib/store/src/sortStories.ts @@ -23,6 +23,7 @@ export const sortStoriesV7 = ( (s1, s2) => fileNameOrder.indexOf(s1.importPath) - fileNameOrder.indexOf(s2.importPath) ); } + return stories; }; const toIndexEntry = (story: any): StoryIndexEntry => {