Skip to content

Commit

Permalink
Merge pull request #30415 from storybookjs/norbert/extract-globals
Browse files Browse the repository at this point in the history
Preview: Add `globals` to `extract()`
(cherry picked from commit c4ff1b4)
  • Loading branch information
ndelangen authored and storybook-bot committed Jan 31, 2025
1 parent b8a3ae0 commit 25edd7e
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
12 changes: 12 additions & 0 deletions code/core/src/preview-api/modules/preview-web/PreviewWeb.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3793,6 +3793,9 @@ describe('PreviewWeb', () => {
},
"component": undefined,
"componentId": "component-one",
"globals": {
"a": "b",
},
"id": "component-one--a",
"initialArgs": {
"foo": "a",
Expand Down Expand Up @@ -3844,6 +3847,9 @@ describe('PreviewWeb', () => {
},
"component": undefined,
"componentId": "component-one",
"globals": {
"a": "b",
},
"id": "component-one--b",
"initialArgs": {
"foo": "b",
Expand Down Expand Up @@ -3876,6 +3882,9 @@ describe('PreviewWeb', () => {
"args": {},
"component": undefined,
"componentId": "component-one",
"globals": {
"a": "b",
},
"id": "component-one--e",
"initialArgs": {},
"kind": "Component One",
Expand Down Expand Up @@ -3914,6 +3923,9 @@ describe('PreviewWeb', () => {
},
"component": undefined,
"componentId": "component-two",
"globals": {
"a": "b",
},
"id": "component-two--c",
"initialArgs": {
"foo": "c",
Expand Down
21 changes: 21 additions & 0 deletions code/core/src/preview-api/modules/store/StoryStore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,9 @@ describe('StoryStore', () => {
},
"component": undefined,
"componentId": "component-one",
"globals": {
"a": "b",
},
"id": "component-one--a",
"initialArgs": {
"foo": "a",
Expand Down Expand Up @@ -471,6 +474,9 @@ describe('StoryStore', () => {
},
"component": undefined,
"componentId": "component-one",
"globals": {
"a": "b",
},
"id": "component-one--a",
"initialArgs": {
"foo": "a",
Expand Down Expand Up @@ -514,6 +520,9 @@ describe('StoryStore', () => {
},
"component": undefined,
"componentId": "component-one",
"globals": {
"a": "b",
},
"id": "component-one--b",
"initialArgs": {
"foo": "b",
Expand Down Expand Up @@ -557,6 +566,9 @@ describe('StoryStore', () => {
},
"component": undefined,
"componentId": "component-two",
"globals": {
"a": "b",
},
"id": "component-two--c",
"initialArgs": {
"foo": "c",
Expand Down Expand Up @@ -847,6 +859,9 @@ describe('StoryStore', () => {
},
"component": undefined,
"componentId": "component-one",
"globals": {
"a": "b",
},
"id": "component-one--a",
"initialArgs": {
"foo": "a",
Expand Down Expand Up @@ -890,6 +905,9 @@ describe('StoryStore', () => {
},
"component": undefined,
"componentId": "component-one",
"globals": {
"a": "b",
},
"id": "component-one--b",
"initialArgs": {
"foo": "b",
Expand Down Expand Up @@ -933,6 +951,9 @@ describe('StoryStore', () => {
},
"component": undefined,
"componentId": "component-two",
"globals": {
"a": "b",
},
"id": "component-two--c",
"initialArgs": {
"foo": "c",
Expand Down
10 changes: 9 additions & 1 deletion code/core/src/preview-api/modules/store/StoryStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,15 @@ export class StoryStore<TRenderer extends Renderer> {
}
return Object.assign(storyAcc, { [key]: value });
},
{ args: story.initialArgs }
{
//
args: story.initialArgs,
globals: {
...this.userGlobals.initialGlobals,
...this.userGlobals.globals,
...story.storyGlobals,
},
}
);
return acc;
},
Expand Down

0 comments on commit 25edd7e

Please sign in to comment.