-
-
Notifications
You must be signed in to change notification settings - Fork 161
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
fix: storysort #677
Open
dannyhw
wants to merge
5
commits into
next
Choose a base branch
from
dannyhw/fix-experimental-storysort
base: next
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+88
−49
Open
fix: storysort #677
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
94bdb87
first attempt to use sort stories
dannyhw 04352e4
fix: use compose config to get parameters
dannyhw 4cef4d6
fix: test fail
dannyhw 2c48f3c
v8.5.4-alpha.0
dannyhw 3ed55b9
Merge branch 'next' into dannyhw/fix-experimental-storysort
dannyhw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"npmClient": "yarn", | ||
"registry": "https://registry.npmjs.org", | ||
"version": "8.5.3" | ||
"version": "8.5.4-alpha.0" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,12 +21,17 @@ import { | |
composeConfigs, | ||
addons as previewAddons, | ||
PreviewWithSelection, | ||
sortStoriesV7, | ||
userOrAutoTitleFromSpecifier, | ||
} from '@storybook/core/preview-api'; | ||
import { isExportStory, storyNameFromExport, toId } from '@storybook/csf'; | ||
// NOTE this really should be exported from preview-api, but it's not | ||
import { createBrowserChannel } from '@storybook/core/channels'; | ||
import type { NormalizedStoriesSpecifier, StoryIndex } from '@storybook/core/types'; | ||
import type { | ||
Addon_StorySortParameterV7, | ||
NormalizedStoriesSpecifier, | ||
StoryIndex, | ||
} from '@storybook/core/types'; | ||
import type { ReactRenderer } from '@storybook/react'; | ||
import { View } from './View'; | ||
|
||
|
@@ -46,12 +51,14 @@ if (Platform.OS === 'web' && typeof globalThis.setImmediate === 'undefined') { | |
export function prepareStories({ | ||
storyEntries, | ||
options, | ||
storySort, | ||
}: { | ||
storyEntries: Array<NormalizedStoriesSpecifier & { req: any }>; | ||
options?: ReactNativeOptions; | ||
storySort?: Addon_StorySortParameterV7; | ||
}) { | ||
let index: StoryIndex = { | ||
v: 4, | ||
v: 5, | ||
entries: {}, | ||
}; | ||
|
||
|
@@ -142,7 +149,20 @@ export function prepareStories({ | |
}); | ||
}); | ||
|
||
return { index, importMap }; | ||
const sortableStories = Object.values(index.entries); | ||
|
||
sortStoriesV7( | ||
sortableStories, | ||
storySort, | ||
Object.values(index.entries).map((entry) => entry.importPath) | ||
); | ||
|
||
const sorted = sortableStories.reduce((acc, item) => { | ||
acc[item.id] = item; | ||
return acc; | ||
}, {} as StoryIndex['entries']); | ||
|
||
return { index: { v: 5, entries: sorted }, importMap }; | ||
} | ||
|
||
export const getProjectAnnotations = (view: View, annotations: any[]) => async () => | ||
|
@@ -175,7 +195,13 @@ export function start({ | |
annotations: any[]; | ||
options?: ReactNativeOptions; | ||
}) { | ||
const { index, importMap } = prepareStories({ storyEntries, options }); | ||
const composedAnnotations = composeConfigs<ReactRenderer>(annotations); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. using composeConfig lets us read the parameters synchronously |
||
|
||
const { index, importMap } = prepareStories({ | ||
storyEntries, | ||
options, | ||
storySort: composedAnnotations.parameters?.options?.storySort, | ||
}); | ||
|
||
const channel = createBrowserChannel({ page: 'preview' }); | ||
|
||
|
@@ -230,7 +256,6 @@ export function start({ | |
...annotations, | ||
]); | ||
|
||
// const preview = new PreviewWithSelection<ReactRenderer>(urlStore, previewView); | ||
const preview = new PreviewWithSelection<ReactRenderer>( | ||
async (importPath: string) => importMap[importPath], | ||
getProjectAnnotationsInitial, | ||
|
@@ -258,7 +283,15 @@ export function updateView( | |
normalizedStories: Array<NormalizedStoriesSpecifier & { req: any }>, | ||
options?: ReactNativeOptions | ||
) { | ||
const { importMap, index } = prepareStories({ storyEntries: normalizedStories, options }); | ||
const composedAnnotations = composeConfigs<ReactRenderer>(annotations); | ||
|
||
const storySort = composedAnnotations.parameters?.options?.storySort; | ||
|
||
const { importMap, index } = prepareStories({ | ||
storyEntries: normalizedStories, | ||
options, | ||
storySort, | ||
}); | ||
|
||
viewInstance._preview.onStoriesChanged({ | ||
importFn: async (importPath: string) => importMap[importPath], | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
pulling in sort stories from preview api to reuse sorting code