Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CHANGE to use getDataForManager over extract api on storyStore #11584

Merged
merged 7 commits into from
Jul 21, 2020
27 changes: 3 additions & 24 deletions lib/cli/src/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,7 @@ const read = async (url: string) => {
const data = JSON.parse(
await page.evaluate(async () => {
// eslint-disable-next-line no-undef
const d = window.__STORYBOOK_STORY_STORE__.extract();

const result = Object.entries(d).reduce(
(acc, [k, v]: [string, any]) => ({
...acc,
[k]: {
...v,
parameters: {
globals: v.parameters.globals,
globalTypes: v.parameters.globalTypes,
options: v.parameters.options,
args: v.parameters.args,
argTypes: v.parameters.argTypes,
framework: v.parameters.framework,
fileName: v.parameters.fileName,
docsOnly: v.parameters.docsOnly,
},
},
}),
{}
);
return JSON.stringify(result, null, 2);
return JSON.stringify(window.__STORYBOOK_STORY_STORE__.getStoriesJsonData(), null, 2);
})
);

Expand Down Expand Up @@ -95,9 +74,9 @@ export async function extract(input: string, targetPath: string) {
if (input && targetPath) {
const [location, exit] = await useLocation(input);

const stories = await read(location);
const data = await read(location);

await writeFile(targetPath, JSON.stringify({ stories }, null, 2));
await writeFile(targetPath, JSON.stringify(data, null, 2));

await exit();
} else {
Expand Down
30 changes: 30 additions & 0 deletions lib/client-api/src/story_store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import memoize from 'memoizerific';
import dedent from 'ts-dedent';
import stable from 'stable';
import mapValues from 'lodash/mapValues';
import pick from 'lodash/pick';
import store from 'store2';

import { Channel } from '@storybook/channels';
Expand Down Expand Up @@ -569,6 +570,35 @@ export default class StoryStore {
};
};

getStoriesJsonData = () => {
const value = this.getDataForManager();
const allowed = ['fileName', 'docsOnly', 'framework', '__id'];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

__isArgsStory?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to know that for the sidebar?


return {
v: 2,
globalParameters: pick(value.globalParameters, allowed),
kindParameters: Object.entries(value.kindParameters).reduce(
ndelangen marked this conversation as resolved.
Show resolved Hide resolved
(acc, [k, v]) => ({
...acc,
[k]: pick(v, allowed),
}),
{}
),
stories: Object.entries(value.stories).reduce(
(acc, [k, v]) => ({
...acc,
// @ts-ignore
[k]: {
...pick(v, ['id', 'name', 'kind', 'story']),
// @ts-ignore
parameters: pick(v.parameters, allowed),
},
}),
{}
),
};
};

pushToManager = () => {
if (this._channel) {
// send to the parent frame.
Expand Down