mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-09 00:19:13 +08:00
ADD parent field to story_store data
This commit is contained in:
parent
a9e439932f
commit
a567b5d9f9
@ -157,11 +157,13 @@ export default class StoryStore extends EventEmitter {
|
||||
// Map a bunch of extra fields onto the groups, collecting the path as we go (thus the reduce)
|
||||
.reduce((soFar, group, index, original) => {
|
||||
const { name } = group;
|
||||
const path = sanitize(index === 0 ? name : `${soFar[index - 1].path}-${name}`);
|
||||
const parent = index > 0 && soFar[index - 1].path;
|
||||
const path = sanitize(parent ? `${parent}-${name}` : name);
|
||||
return soFar.concat([
|
||||
{
|
||||
...group,
|
||||
path,
|
||||
parent,
|
||||
depth: index,
|
||||
isComponent: index === original.length - 1,
|
||||
isRoot: index === 0,
|
||||
@ -199,6 +201,7 @@ Story ids need to be unique -- ensure you aren't using the same names modolo url
|
||||
parameters,
|
||||
id: storyId,
|
||||
path: storyId,
|
||||
parent: rootAndGroups[rootAndGroups.length - 1].path,
|
||||
depth: rootAndGroups.length,
|
||||
isComponent: false,
|
||||
isRoot: false,
|
||||
|
@ -30,6 +30,7 @@ describe('preview.story_store', () => {
|
||||
expect(extracted['a--1']).toMatchObject({
|
||||
id: 'a--1',
|
||||
path: 'a--1',
|
||||
parent: 'a',
|
||||
kind: 'a',
|
||||
name: '1',
|
||||
parameters: {},
|
||||
@ -57,24 +58,28 @@ describe('preview.story_store', () => {
|
||||
isRoot: false,
|
||||
isComponent: false,
|
||||
children: ['a-b-c'],
|
||||
parent: 'a',
|
||||
});
|
||||
expect(extracted['a-b-c']).toMatchObject({
|
||||
name: 'c',
|
||||
isRoot: false,
|
||||
isComponent: false,
|
||||
children: ['a-b-c-d'],
|
||||
parent: 'a-b',
|
||||
});
|
||||
expect(extracted['a-b-c-d']).toMatchObject({
|
||||
name: 'd',
|
||||
isRoot: false,
|
||||
isComponent: true,
|
||||
children: ['a-b-c-d--1'],
|
||||
parent: 'a-b-c',
|
||||
});
|
||||
expect(extracted['a-b-c-d--1']).toMatchObject({
|
||||
kind: 'a|b/c/d',
|
||||
name: '1',
|
||||
isRoot: false,
|
||||
isComponent: false,
|
||||
parent: 'a-b-c-d',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user