From e33dc8df881c1c566ace98a64b449ea92caa2e00 Mon Sep 17 00:00:00 2001 From: Gert Hengeveld Date: Thu, 18 Jul 2024 18:08:17 +0200 Subject: [PATCH] Fix source code snippet for newly created stories with a space in their name --- code/addons/onboarding/src/Onboarding.tsx | 5 +++-- code/core/src/core-events/data/save-story.ts | 2 ++ code/core/src/core-server/utils/save-story/save-story.ts | 2 ++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/code/addons/onboarding/src/Onboarding.tsx b/code/addons/onboarding/src/Onboarding.tsx index e387659cf7ce..fde1526aa483 100644 --- a/code/addons/onboarding/src/Onboarding.tsx +++ b/code/addons/onboarding/src/Onboarding.tsx @@ -75,6 +75,7 @@ export default function Onboarding({ api }: { api: API }) { const [createNewStoryForm, setCreateNewStoryForm] = useState(); const [createdStory, setCreatedStory] = useState<{ newStoryName: string; + newStoryExportName: string; sourceFileContent: string; sourceFileName: string; } | null>(); @@ -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[] = [ diff --git a/code/core/src/core-events/data/save-story.ts b/code/core/src/core-events/data/save-story.ts index 8bb4091e513e..0162ecdb0819 100644 --- a/code/core/src/core-events/data/save-story.ts +++ b/code/core/src/core-events/data/save-story.ts @@ -9,7 +9,9 @@ export interface SaveStoryResponsePayload { csfId: string; newStoryId?: string; newStoryName?: string; + newStoryExportName?: string; sourceFileContent?: string; sourceFileName?: string; sourceStoryName?: string; + sourceStoryExportName?: string; } diff --git a/code/core/src/core-server/utils/save-story/save-story.ts b/code/core/src/core-server/utils/save-story/save-story.ts index 8ad7ef738ff3..5369d99a4cba 100644 --- a/code/core/src/core-server/utils/save-story/save-story.ts +++ b/code/core/src/core-server/utils/save-story/save-story.ts @@ -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);