Skip to content

Commit

Permalink
improve readability
Browse files Browse the repository at this point in the history
  • Loading branch information
JReinhold committed May 2, 2024
1 parent 24148ad commit f7d809a
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 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,8 +29,8 @@ import { normalizeProjectAnnotations } from './normalizeProjectAnnotations';

let globalProjectAnnotations: ProjectAnnotations<any> = {};

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

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

// @TODO: Support auto title

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

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

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

if (cleanups.length > 0 && !previousCleanupsDone) {
let humanReadableIdentifier = storyName;
if (story.title !== DEFAULT_TITLE) {
if (story.title !== DEFAULT_STORY_TITLE) {
// prefix with title unless it's the generic ComposedStory title
humanReadableIdentifier = `${story.title} - ${humanReadableIdentifier}`;
}
if (storyName === DEFAULT_NAME && Object.keys(context.args).length > 0) {
if (storyName === DEFAULT_STORY_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(
', '
)})`;
}
console.warn(
dedent`Some stories were not cleaned up before rendering '${humanReadableIdentifier}'.
You should load the story with \`await Story.load()\` before rendering it.
See https://storybook.js.org/docs/api/portable-stories-${
process.env.JEST_WORKER_ID !== undefined ? 'jest' : 'vitest'
Expand Down

0 comments on commit f7d809a

Please sign in to comment.