Skip to content

Commit

Permalink
improve default title and name typesafety
Browse files Browse the repository at this point in the history
  • Loading branch information
JReinhold committed May 2, 2024
1 parent 8a22135 commit 089f2c5
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions code/lib/preview-api/src/modules/store/csf/portable-stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ import { normalizeProjectAnnotations } from './normalizeProjectAnnotations';

let globalProjectAnnotations: ProjectAnnotations<any> = {};

const DEFAULT_TITLE = 'ComposedStory';
const DEFAULT_NAME = 'Unnamed Story';

function extractAnnotation<TRenderer extends Renderer = Renderer>(
annotation: NamedOrDefaultProjectAnnotations<TRenderer>
) {
Expand Down Expand Up @@ -63,7 +66,7 @@ export function composeStory<TRenderer extends Renderer = Renderer, TArgs extend

// @TODO: Support auto title

componentAnnotations.title = componentAnnotations.title ?? 'ComposedStory';
componentAnnotations.title = componentAnnotations.title ?? DEFAULT_TITLE;
const normalizedComponentAnnotations =
normalizeComponentAnnotations<TRenderer>(componentAnnotations);

Expand All @@ -72,7 +75,7 @@ export function composeStory<TRenderer extends Renderer = Renderer, TArgs extend
storyAnnotations.storyName ||
storyAnnotations.story?.name ||
storyAnnotations.name ||
'Unnamed Story';
DEFAULT_NAME;

const normalizedStory = normalizeStory<TRenderer>(
storyName,
Expand Down Expand Up @@ -126,11 +129,11 @@ export function composeStory<TRenderer extends Renderer = Renderer, TArgs extend

if (cleanups.length > 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(
', '
Expand Down

0 comments on commit 089f2c5

Please sign in to comment.