Skip to content
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
wants to merge 5 commits into
base: next
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions examples/expo-example/.storybook/preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ const preview: Preview = {
date: /Date$/,
},
},
options: {
storySort: {
method: 'alphabetical',
order: ['Notes example', 'TextInput'],
},
},
hideFullScreenButton: false,
noSafeArea: false,
my_param: 'anything',
Expand Down
14 changes: 7 additions & 7 deletions examples/expo-example/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "expo-example",
"version": "8.5.3",
"version": "8.5.4-alpha.0",
"private": true,
"main": "index.js",
"scripts": {
Expand Down Expand Up @@ -28,19 +28,19 @@
"@storybook/addon-essentials": "^8.5.1",
"@storybook/addon-interactions": "^8.5.1",
"@storybook/addon-links": "^8.5.1",
"@storybook/addon-ondevice-actions": "^8.5.3",
"@storybook/addon-ondevice-backgrounds": "^8.5.3",
"@storybook/addon-ondevice-controls": "^8.5.3",
"@storybook/addon-ondevice-notes": "^8.5.3",
"@storybook/addon-ondevice-actions": "^8.5.4-alpha.0",
"@storybook/addon-ondevice-backgrounds": "^8.5.4-alpha.0",
"@storybook/addon-ondevice-controls": "^8.5.4-alpha.0",
"@storybook/addon-ondevice-notes": "^8.5.4-alpha.0",
"@storybook/addon-react-native-server": "0.0.6",
"@storybook/addon-react-native-web": "^0.0.26",
"@storybook/addon-webpack5-compiler-babel": "^3.0.3",
"@storybook/blocks": "^8.5.1",
"@storybook/builder-webpack5": "^8.5.1",
"@storybook/global": "^5.0.0",
"@storybook/react": "^8.5.1",
"@storybook/react-native": "^8.5.3",
"@storybook/react-native-theming": "^8.5.3",
"@storybook/react-native": "^8.5.4-alpha.0",
"@storybook/react-native-theming": "^8.5.4-alpha.0",
"@storybook/react-webpack5": "^8.5.1",
"@storybook/test": "^8.5.1",
"expo": "~52.0.11",
Expand Down
2 changes: 1 addition & 1 deletion lerna.json
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"
}
2 changes: 1 addition & 1 deletion packages/ondevice-actions/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@storybook/addon-ondevice-actions",
"version": "8.5.3",
"version": "8.5.4-alpha.0",
"description": "Action Logger addon for react-native storybook",
"keywords": [
"storybook"
Expand Down
4 changes: 2 additions & 2 deletions packages/ondevice-backgrounds/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@storybook/addon-ondevice-backgrounds",
"version": "8.5.3",
"version": "8.5.4-alpha.0",
"description": "A react-native storybook addon to show different backgrounds for your preview",
"keywords": [
"addon",
Expand Down Expand Up @@ -33,7 +33,7 @@
},
"dependencies": {
"@storybook/core": "^8.5.1",
"@storybook/react-native-theming": "^8.5.3"
"@storybook/react-native-theming": "^8.5.4-alpha.0"
},
"devDependencies": {
"typescript": "^5.3.3"
Expand Down
6 changes: 3 additions & 3 deletions packages/ondevice-controls/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@storybook/addon-ondevice-controls",
"version": "8.5.3",
"version": "8.5.4-alpha.0",
"description": "Display storybook controls on your device.",
"keywords": [
"addon",
Expand Down Expand Up @@ -32,8 +32,8 @@
"dependencies": {
"@storybook/addon-controls": "^8.5.1",
"@storybook/core": "^8.5.1",
"@storybook/react-native-theming": "^8.5.3",
"@storybook/react-native-ui": "^8.5.3",
"@storybook/react-native-theming": "^8.5.4-alpha.0",
"@storybook/react-native-ui": "^8.5.4-alpha.0",
"deep-equal": "^1.0.1",
"prop-types": "^15.7.2",
"react-native-modal-datetime-picker": "^14.0.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/ondevice-notes/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@storybook/addon-ondevice-notes",
"version": "8.5.3",
"version": "8.5.4-alpha.0",
"description": "Write notes for your react-native Storybook stories.",
"keywords": [
"addon",
Expand Down Expand Up @@ -30,7 +30,7 @@
},
"dependencies": {
"@storybook/core": "^8.5.1",
"@storybook/react-native-theming": "^8.5.3",
"@storybook/react-native-theming": "^8.5.4-alpha.0",
"react-native-markdown-display": "^7.0.2"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/react-native-theming/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@storybook/react-native-theming",
"version": "8.5.3",
"version": "8.5.4-alpha.0",
"description": "A wrapper library around emotion 11 to provide theming support for react-native storybook",
"keywords": [
"react",
Expand Down
4 changes: 2 additions & 2 deletions packages/react-native-ui/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@storybook/react-native-ui",
"version": "8.5.3",
"version": "8.5.4-alpha.0",
"description": "ui components for react native storybook",
"keywords": [
"react",
Expand Down Expand Up @@ -60,7 +60,7 @@
"dependencies": {
"@storybook/core": "^8.5.1",
"@storybook/react": "^8.5.1",
"@storybook/react-native-theming": "^8.5.3",
"@storybook/react-native-theming": "^8.5.4-alpha.0",
"fuse.js": "^7.0.0",
"memoizerific": "^1.11.3",
"polished": "^4.3.1",
Expand Down
6 changes: 3 additions & 3 deletions packages/react-native/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@storybook/react-native",
"version": "8.5.3",
"version": "8.5.4-alpha.0",
"description": "A better way to develop React Native Components for your app",
"keywords": [
"react",
Expand Down Expand Up @@ -49,8 +49,8 @@
"@storybook/csf": "^0.1.13",
"@storybook/global": "^5.0.0",
"@storybook/react": "^8.5.1",
"@storybook/react-native-theming": "^8.5.3",
"@storybook/react-native-ui": "^8.5.3",
"@storybook/react-native-theming": "^8.5.4-alpha.0",
"@storybook/react-native-ui": "^8.5.4-alpha.0",
"commander": "^8.2.0",
"dedent": "^1.5.1",
"deepmerge": "^4.3.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/react-native/src/Start.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe('prepareStories', () => {
},
},
index: {
v: 4,
v: 5,
entries: {
'textinput--basic': {
id: 'textinput--basic',
Expand Down
45 changes: 39 additions & 6 deletions packages/react-native/src/Start.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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: {},
};

Expand Down Expand Up @@ -142,7 +149,20 @@ export function prepareStories({
});
});

return { index, importMap };
const sortableStories = Object.values(index.entries);

sortStoriesV7(
Copy link
Member Author

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

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 () =>
Expand Down Expand Up @@ -175,7 +195,13 @@ export function start({
annotations: any[];
options?: ReactNativeOptions;
}) {
const { index, importMap } = prepareStories({ storyEntries, options });
const composedAnnotations = composeConfigs<ReactRenderer>(annotations);
Copy link
Member Author

Choose a reason for hiding this comment

The 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' });

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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],
Expand Down
40 changes: 20 additions & 20 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5124,7 +5124,7 @@ __metadata:
languageName: node
linkType: hard

"@storybook/addon-ondevice-actions@npm:^8.5.3, @storybook/addon-ondevice-actions@workspace:packages/ondevice-actions":
"@storybook/addon-ondevice-actions@npm:^8.5.4-alpha.0, @storybook/addon-ondevice-actions@workspace:packages/ondevice-actions":
version: 0.0.0-use.local
resolution: "@storybook/addon-ondevice-actions@workspace:packages/ondevice-actions"
dependencies:
Expand All @@ -5139,27 +5139,27 @@ __metadata:
languageName: unknown
linkType: soft

"@storybook/addon-ondevice-backgrounds@npm:^8.5.3, @storybook/addon-ondevice-backgrounds@workspace:packages/ondevice-backgrounds":
"@storybook/addon-ondevice-backgrounds@npm:^8.5.4-alpha.0, @storybook/addon-ondevice-backgrounds@workspace:packages/ondevice-backgrounds":
version: 0.0.0-use.local
resolution: "@storybook/addon-ondevice-backgrounds@workspace:packages/ondevice-backgrounds"
dependencies:
"@storybook/core": "npm:^8.5.1"
"@storybook/react-native-theming": "npm:^8.5.3"
"@storybook/react-native-theming": "npm:^8.5.4-alpha.0"
typescript: "npm:^5.3.3"
peerDependencies:
react: "*"
react-native: "*"
languageName: unknown
linkType: soft

"@storybook/addon-ondevice-controls@npm:^8.5.3, @storybook/addon-ondevice-controls@workspace:packages/ondevice-controls":
"@storybook/addon-ondevice-controls@npm:^8.5.4-alpha.0, @storybook/addon-ondevice-controls@workspace:packages/ondevice-controls":
version: 0.0.0-use.local
resolution: "@storybook/addon-ondevice-controls@workspace:packages/ondevice-controls"
dependencies:
"@storybook/addon-controls": "npm:^8.5.1"
"@storybook/core": "npm:^8.5.1"
"@storybook/react-native-theming": "npm:^8.5.3"
"@storybook/react-native-ui": "npm:^8.5.3"
"@storybook/react-native-theming": "npm:^8.5.4-alpha.0"
"@storybook/react-native-ui": "npm:^8.5.4-alpha.0"
cross-env: "npm:^7.0.3"
deep-equal: "npm:^1.0.1"
prop-types: "npm:^15.7.2"
Expand All @@ -5176,12 +5176,12 @@ __metadata:
languageName: unknown
linkType: soft

"@storybook/addon-ondevice-notes@npm:^8.5.3, @storybook/addon-ondevice-notes@workspace:packages/ondevice-notes":
"@storybook/addon-ondevice-notes@npm:^8.5.4-alpha.0, @storybook/addon-ondevice-notes@workspace:packages/ondevice-notes":
version: 0.0.0-use.local
resolution: "@storybook/addon-ondevice-notes@workspace:packages/ondevice-notes"
dependencies:
"@storybook/core": "npm:^8.5.1"
"@storybook/react-native-theming": "npm:^8.5.3"
"@storybook/react-native-theming": "npm:^8.5.4-alpha.0"
react-native-markdown-display: "npm:^7.0.2"
typescript: "npm:^5.3.3"
peerDependencies:
Expand Down Expand Up @@ -5496,7 +5496,7 @@ __metadata:
languageName: node
linkType: hard

"@storybook/react-native-theming@npm:^8.5.3, @storybook/react-native-theming@workspace:packages/react-native-theming":
"@storybook/react-native-theming@npm:^8.5.4-alpha.0, @storybook/react-native-theming@workspace:packages/react-native-theming":
version: 0.0.0-use.local
resolution: "@storybook/react-native-theming@workspace:packages/react-native-theming"
dependencies:
Expand All @@ -5510,13 +5510,13 @@ __metadata:
languageName: unknown
linkType: soft

"@storybook/react-native-ui@npm:^8.5.3, @storybook/react-native-ui@workspace:packages/react-native-ui":
"@storybook/react-native-ui@npm:^8.5.4-alpha.0, @storybook/react-native-ui@workspace:packages/react-native-ui":
version: 0.0.0-use.local
resolution: "@storybook/react-native-ui@workspace:packages/react-native-ui"
dependencies:
"@storybook/core": "npm:^8.5.1"
"@storybook/react": "npm:^8.5.1"
"@storybook/react-native-theming": "npm:^8.5.3"
"@storybook/react-native-theming": "npm:^8.5.4-alpha.0"
"@types/jest": "npm:^29.4.3"
"@types/react": "npm:~18.3.12"
babel-jest: "npm:^29.7.0"
Expand All @@ -5540,16 +5540,16 @@ __metadata:
languageName: unknown
linkType: soft

"@storybook/react-native@npm:^8.5.3, @storybook/react-native@workspace:packages/react-native":
"@storybook/react-native@npm:^8.5.4-alpha.0, @storybook/react-native@workspace:packages/react-native":
version: 0.0.0-use.local
resolution: "@storybook/react-native@workspace:packages/react-native"
dependencies:
"@storybook/core": "npm:^8.5.1"
"@storybook/csf": "npm:^0.1.13"
"@storybook/global": "npm:^5.0.0"
"@storybook/react": "npm:^8.5.1"
"@storybook/react-native-theming": "npm:^8.5.3"
"@storybook/react-native-ui": "npm:^8.5.3"
"@storybook/react-native-theming": "npm:^8.5.4-alpha.0"
"@storybook/react-native-ui": "npm:^8.5.4-alpha.0"
"@types/jest": "npm:^29.4.3"
"@types/react": "npm:~18.3.12"
babel-jest: "npm:^29.7.0"
Expand Down Expand Up @@ -9977,19 +9977,19 @@ __metadata:
"@storybook/addon-essentials": "npm:^8.5.1"
"@storybook/addon-interactions": "npm:^8.5.1"
"@storybook/addon-links": "npm:^8.5.1"
"@storybook/addon-ondevice-actions": "npm:^8.5.3"
"@storybook/addon-ondevice-backgrounds": "npm:^8.5.3"
"@storybook/addon-ondevice-controls": "npm:^8.5.3"
"@storybook/addon-ondevice-notes": "npm:^8.5.3"
"@storybook/addon-ondevice-actions": "npm:^8.5.4-alpha.0"
"@storybook/addon-ondevice-backgrounds": "npm:^8.5.4-alpha.0"
"@storybook/addon-ondevice-controls": "npm:^8.5.4-alpha.0"
"@storybook/addon-ondevice-notes": "npm:^8.5.4-alpha.0"
"@storybook/addon-react-native-server": "npm:0.0.6"
"@storybook/addon-react-native-web": "npm:^0.0.26"
"@storybook/addon-webpack5-compiler-babel": "npm:^3.0.3"
"@storybook/blocks": "npm:^8.5.1"
"@storybook/builder-webpack5": "npm:^8.5.1"
"@storybook/global": "npm:^5.0.0"
"@storybook/react": "npm:^8.5.1"
"@storybook/react-native": "npm:^8.5.3"
"@storybook/react-native-theming": "npm:^8.5.3"
"@storybook/react-native": "npm:^8.5.4-alpha.0"
"@storybook/react-native-theming": "npm:^8.5.4-alpha.0"
"@storybook/react-webpack5": "npm:^8.5.1"
"@storybook/test": "npm:^8.5.1"
"@testing-library/react-native": "npm:12.4.3"
Expand Down