From 089f2c5c875aeae33288ea01441c306ffbad4549 Mon Sep 17 00:00:00 2001 From: Jeppe Reinhold Date: Thu, 2 May 2024 13:41:28 +0200 Subject: [PATCH] improve default title and name typesafety --- .../src/modules/store/csf/portable-stories.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/code/lib/preview-api/src/modules/store/csf/portable-stories.ts b/code/lib/preview-api/src/modules/store/csf/portable-stories.ts index 97237003ab44..9c18e46a6c79 100644 --- a/code/lib/preview-api/src/modules/store/csf/portable-stories.ts +++ b/code/lib/preview-api/src/modules/store/csf/portable-stories.ts @@ -29,6 +29,9 @@ import { normalizeProjectAnnotations } from './normalizeProjectAnnotations'; let globalProjectAnnotations: ProjectAnnotations = {}; +const DEFAULT_TITLE = 'ComposedStory'; +const DEFAULT_NAME = 'Unnamed Story'; + function extractAnnotation( annotation: NamedOrDefaultProjectAnnotations ) { @@ -63,7 +66,7 @@ export function composeStory(componentAnnotations); @@ -72,7 +75,7 @@ export function composeStory( storyName, @@ -126,11 +129,11 @@ export function composeStory 0 && !previousCleanupsDone) { let humanReadableIdentifier = storyName; - if (story.title !== 'ComposedStory') { + if (story.title !== DEFAULT_TITLE) { // prefix with title unless it's the generic ComposedStory title humanReadableIdentifier = `${story.title} - ${humanReadableIdentifier}`; } - if (storyName === 'Unnamed Story' && Object.keys(context.args).length > 0) { + if (storyName === DEFAULT_NAME && Object.keys(context.args).length > 0) { // suffix with args if it's an unnamed story and there are args humanReadableIdentifier = `${humanReadableIdentifier} (${Object.keys(context.args).join( ', '