From 8103aaf3d50f2a1284a6720c21556d14bc65f0b1 Mon Sep 17 00:00:00 2001 From: Michael Shilman Date: Fri, 7 Jun 2024 00:55:57 +0800 Subject: [PATCH] Merge pull request #27708 from storybookjs/yann/add-tags-to-portable-stories Portable Stories: Add tags to composed story (cherry picked from commit 17b7512c60256c739b890b3d85aaac992806dee6) --- .../store/csf/portable-stories.test.ts | 20 +++++++++++-------- .../src/modules/store/csf/portable-stories.ts | 1 + code/lib/types/src/modules/composedStory.ts | 2 ++ 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/code/lib/preview-api/src/modules/store/csf/portable-stories.test.ts b/code/lib/preview-api/src/modules/store/csf/portable-stories.test.ts index 6babf08285ec..425e2162c425 100644 --- a/code/lib/preview-api/src/modules/store/csf/portable-stories.test.ts +++ b/code/lib/preview-api/src/modules/store/csf/portable-stories.test.ts @@ -23,6 +23,7 @@ describe('composeStory', () => { label: 'Hello World', primary: true, }, + tags: ['metaTag'], }; it('should compose project annotations in all module formats', () => { @@ -40,15 +41,16 @@ describe('composeStory', () => { it('should return story with composed annotations from story, meta and project', () => { const decoratorFromProjectAnnotations = vi.fn((StoryFn) => StoryFn()); const decoratorFromStoryAnnotations = vi.fn((StoryFn) => StoryFn()); - setProjectAnnotations([ - { - parameters: { injected: true }, - globalTypes: { - locale: { defaultValue: 'en' }, - }, - decorators: [decoratorFromProjectAnnotations], + const projectAnnotations = { + parameters: { injected: true }, + globalTypes: { + locale: { defaultValue: 'en' }, }, - ]); + decorators: [decoratorFromProjectAnnotations], + tags: ['projectTag'], + }; + + setProjectAnnotations(projectAnnotations); const Story: Story = { render: () => {}, @@ -57,6 +59,7 @@ describe('composeStory', () => { secondAddon: true, }, decorators: [decoratorFromStoryAnnotations], + tags: ['storyTag'], }; const composedStory = composeStory(Story, meta); @@ -64,6 +67,7 @@ describe('composeStory', () => { expect(composedStory.parameters).toEqual( expect.objectContaining({ ...Story.parameters, ...meta.parameters }) ); + expect(composedStory.tags).toEqual(['dev', 'test', 'projectTag', 'metaTag', 'storyTag']); composedStory(); 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 056daa5dcbcb..987240ecab66 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 @@ -172,6 +172,7 @@ export function composeStory, play: playFunction as ComposedStoryPlayFn | undefined, + tags: story.tags, } ); diff --git a/code/lib/types/src/modules/composedStory.ts b/code/lib/types/src/modules/composedStory.ts index f670b1ef12a0..f4b49f24793a 100644 --- a/code/lib/types/src/modules/composedStory.ts +++ b/code/lib/types/src/modules/composedStory.ts @@ -6,6 +6,7 @@ import type { Renderer, StoryId, StrictArgTypes, + Tag, } from '@storybook/csf'; import type { @@ -56,6 +57,7 @@ export type ComposedStoryFn< storyName: string; parameters: Parameters; argTypes: StrictArgTypes; + tags: Tag[]; }; /** * Based on a module of stories, it returns all stories within it, filtering non-stories