Skip to content

Commit ac09973

Browse files
fix: use storyNames in tree if available (#697)
Co-authored-by: Daniel Williams <[email protected]>
1 parent 3408db3 commit ac09973

File tree

2 files changed

+43
-5
lines changed

2 files changed

+43
-5
lines changed

packages/react-native-ui/src/Tree.stories.tsx

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { useState } from 'react';
22
import type { ComponentEntry, IndexHash } from '@storybook/core/manager-api';
33
import type { StoryObj, Meta } from '@storybook/react';
44
import { Tree } from './Tree';
5+
import type { Dataset } from './types';
56
import { index } from './mockdata.large';
67
import { DEFAULT_REF_ID } from './constants';
78
import { ScrollView, Text } from 'react-native';
@@ -138,3 +139,39 @@ export const SingleStoryComponents: Story = {
138139
);
139140
},
140141
};
142+
143+
const dataWithStoryName: Dataset = {
144+
images: {
145+
name: 'Testing storyNames support',
146+
id: 'images',
147+
depth: 0,
148+
children: [],
149+
type: 'component',
150+
tags: [],
151+
},
152+
};
153+
154+
export const WithStoryNames: Story = {
155+
storyName: 'Story with a storyName',
156+
args: {
157+
docsMode: false,
158+
isBrowsing: true,
159+
isMain: true,
160+
refId: DEFAULT_REF_ID,
161+
data: undefined,
162+
onSelectStoryId: () => {},
163+
selectedStoryId: 'some-component',
164+
status: undefined,
165+
},
166+
render: function Render(args) {
167+
const [selectedId, setSelectedId] = useState(storyId);
168+
return (
169+
<Tree
170+
{...args}
171+
data={dataWithStoryName}
172+
selectedStoryId={selectedId}
173+
onSelectStoryId={setSelectedId}
174+
/>
175+
);
176+
},
177+
};

packages/react-native/src/Start.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,27 +89,27 @@ export function prepareStories({
8989

9090
storyEntries.forEach((specifier) => {
9191
const { req, directory: root } = specifier;
92+
9293
req.keys().forEach((filename: string) => {
9394
try {
94-
// console.log('req', req.resolve(filename));
95-
// console.log('filename', filename);
9695
const fileExports = req(filename);
9796
// TODO: should this be here?
9897
if (!fileExports.default) return;
9998
const meta = fileExports.default;
99+
100100
Object.keys(fileExports).forEach((key) => {
101101
if (key === 'default') return;
102102
if (!isExportStory(key, fileExports.default)) return;
103103

104104
const exportValue = fileExports[key];
105105
if (!exportValue) return;
106106

107-
//FIXME: autotitle
108-
const name = storyNameFromExport(key);
109107
const title = makeTitle(filename, specifier, meta.title);
110108

111109
if (title) {
112-
const id = toId(title, name);
110+
const nameFromExport = storyNameFromExport(key);
111+
const id = toId(title, nameFromExport);
112+
const name = exportValue.storyName || nameFromExport;
113113

114114
index.entries[id] = {
115115
type: 'story',
@@ -124,6 +124,7 @@ export function prepareStories({
124124
const stories = Object.entries(importedStories).reduce(
125125
(carry, [storyKey, story]: [string, Readonly<Record<string, unknown>>]) => {
126126
if (!isExportStory(storyKey, fileExports.default)) return carry;
127+
127128
if (story.play && !options?.playFn) {
128129
// play functions are not yet fully supported on native.
129130
// There is a new option in main.js to turn them on for future use.

0 commit comments

Comments
 (0)