Skip to content

Commit

Permalink
Merge pull request #28649 from storybookjs/fix-new-story-snippet
Browse files Browse the repository at this point in the history
Onboarding: Fix code snippet when story name differs from export name
  • Loading branch information
shilman committed Jul 19, 2024
2 parents 0c91f47 + e33dc8d commit 2f38895
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
5 changes: 3 additions & 2 deletions code/addons/onboarding/src/Onboarding.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export default function Onboarding({ api }: { api: API }) {
const [createNewStoryForm, setCreateNewStoryForm] = useState<HTMLElement | null>();
const [createdStory, setCreatedStory] = useState<{
newStoryName: string;
newStoryExportName: string;
sourceFileContent: string;
sourceFileName: string;
} | null>();
Expand Down Expand Up @@ -158,8 +159,8 @@ export default function Onboarding({ api }: { api: API }) {
}

const source = createdStory?.sourceFileContent;
const startIndex = source?.lastIndexOf(`export const ${createdStory?.newStoryName}`);
const snippet = source?.slice(startIndex);
const startIndex = source?.lastIndexOf(`export const ${createdStory?.newStoryExportName}`);
const snippet = source?.slice(startIndex).trim();
const startingLineNumber = source?.slice(0, startIndex).split('\n').length;

const steps: StepDefinition[] = [
Expand Down
2 changes: 2 additions & 0 deletions code/core/src/core-events/data/save-story.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ export interface SaveStoryResponsePayload {
csfId: string;
newStoryId?: string;
newStoryName?: string;
newStoryExportName?: string;
sourceFileContent?: string;
sourceFileName?: string;
sourceStoryName?: string;
sourceStoryExportName?: string;
}
2 changes: 2 additions & 0 deletions code/core/src/core-server/utils/save-story/save-story.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,11 @@ export function initializeSaveStory(channel: Channel, options: Options, coreConf
csfId,
newStoryId,
newStoryName,
newStoryExportName: name,
sourceFileContent: code,
sourceFileName,
sourceStoryName,
sourceStoryExportName: storyName,
},
error: null,
} satisfies ResponseData<SaveStoryResponsePayload>);
Expand Down

0 comments on commit 2f38895

Please sign in to comment.