Fix v6 story sorting

This commit is contained in:
Michael Shilman 2021-09-21 17:51:55 +08:00
parent c6e20d9800
commit 666ad2a839
3 changed files with 11 additions and 6 deletions

View File

@ -110,6 +110,7 @@ export interface StoriesRaw {
type Path = string;
export interface StoryIndexStory {
id: StoryId;
name: StoryName;
title: ComponentTitle;
importPath: Path;

View File

@ -67,7 +67,7 @@ export class StoryStoreFacade<TFramework extends AnyFramework> {
const storyEntries = Object.entries(this.stories);
// Add the kind parameters and global parameters to each entry
const stories: [StoryId, Story<TFramework>, Parameters, Parameters][] = storyEntries.map(
const sortableV6: [StoryId, Story<TFramework>, Parameters, Parameters][] = storyEntries.map(
([storyId, { importPath }]) => {
const exports = this.csfExports[importPath];
const csfFile = store.processCSFFileWithCache<TFramework>(exports, exports.default.title);
@ -80,11 +80,14 @@ export class StoryStoreFacade<TFramework extends AnyFramework> {
}
);
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) {

View File

@ -23,6 +23,7 @@ export const sortStoriesV7 = (
(s1, s2) => fileNameOrder.indexOf(s1.importPath) - fileNameOrder.indexOf(s2.importPath)
);
}
return stories;
};
const toIndexEntry = (story: any): StoryIndexEntry => {