Skip to content

Commit

Permalink
Merge pull request #16912 from TrevorBurnham/trevorburnham/fix-story-…
Browse files Browse the repository at this point in the history
…group-viewmode

fix(storybook): Use parameters from first story in group
  • Loading branch information
ndelangen authored Jun 30, 2022
2 parents f6e17dc + a4e5171 commit f0a4b55
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
3 changes: 3 additions & 0 deletions lib/api/src/lib/stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,9 +282,12 @@ export const transformStoriesRawToStoriesHash = (
rootAndGroups.forEach((group, index) => {
const child = paths[index + 1];
const { id } = group;
// @ts-ignore
const { parameters: originalParameters = group.parameters } = acc[id] || {};
acc[id] = merge(acc[id] || {}, {
...group,
...(child && { children: [child] }),
parameters: originalParameters,
});
});

Expand Down
11 changes: 7 additions & 4 deletions lib/api/src/tests/stories.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ describe('stories API', () => {
});
});
const parameters = {};
const firstInGroupParameters = { viewMode: 'docs' };
const secondInGroupParameters = { viewMode: 'story' };
const storiesHash = {
'a--1': {
kind: 'a',
Expand Down Expand Up @@ -112,15 +114,15 @@ describe('stories API', () => {
'b-d--1': {
kind: 'b/d',
name: '1',
parameters,
parameters: firstInGroupParameters,
path: 'b-d--1',
id: 'b-d--1',
args: {},
},
'b-d--2': {
kind: 'b/d',
name: '2',
parameters,
parameters: secondInGroupParameters,
path: 'b-d--2',
id: 'b-d--2',
args: { a: 'b' },
Expand Down Expand Up @@ -229,6 +231,7 @@ describe('stories API', () => {
id: 'b-d',
parent: 'b',
children: ['b-d--1', 'b-d--2'],
parameters: firstInGroupParameters,
isRoot: false,
isComponent: true,
});
Expand All @@ -239,7 +242,7 @@ describe('stories API', () => {
parent: 'b-d',
kind: 'b/d',
name: '1',
parameters,
parameters: firstInGroupParameters,
args: {},
prepared: true,
});
Expand All @@ -250,7 +253,7 @@ describe('stories API', () => {
parent: 'b-d',
kind: 'b/d',
name: '2',
parameters,
parameters: secondInGroupParameters,
args: { a: 'b' },
prepared: true,
});
Expand Down

0 comments on commit f0a4b55

Please sign in to comment.