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

Telemetry: Count onboarding stories #23092

Merged
merged 2 commits into from
Jun 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions code/lib/core-server/src/utils/summarizeIndex.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,66 @@ describe('summarizeIndex', () => {
"exampleDocsCount": 3,
"exampleStoryCount": 8,
"mdxCount": 0,
"onboardingDocsCount": 0,
"onboardingStoryCount": 0,
"pageStoryCount": 0,
"playStoryCount": 0,
"storiesMdxCount": 0,
"storyCount": 0,
"version": 4,
}
`);
});
it('onboarding stories', () => {
expect(
summarizeIndex({
v: 4,
entries: {
'example-introduction--docs': {
id: 'example-introduction--docs',
title: 'Example/Introduction',
name: 'Docs',
importPath: './src/stories/Introduction.mdx',
storiesImports: [],
type: 'docs',
tags: ['docs'],
},
'example-button--docs': {
id: 'example-button--docs',
title: 'Example/Button',
name: 'Docs',
importPath: './src/stories/Button.stories.ts',
type: 'docs',
tags: ['autodocs', 'docs'],
storiesImports: [],
},
'example-button--primary': {
id: 'example-button--primary',
title: 'Example/Button',
name: 'Primary',
importPath: './src/stories/Button.stories.ts',
tags: ['autodocs', 'story'],
type: 'story',
},
'example-button--warning': {
id: 'example-button--warning',
title: 'Example/Button',
name: 'Warning',
importPath: './src/stories/Button.stories.ts',
tags: ['autodocs', 'story'],
type: 'story',
},
},
})
).toMatchInlineSnapshot(`
Object {
"autodocsCount": 0,
"componentCount": 0,
"exampleDocsCount": 2,
"exampleStoryCount": 1,
"mdxCount": 0,
"onboardingDocsCount": 0,
"onboardingStoryCount": 1,
"pageStoryCount": 0,
"playStoryCount": 0,
"storiesMdxCount": 0,
Expand Down Expand Up @@ -193,6 +253,8 @@ describe('summarizeIndex', () => {
"exampleDocsCount": 0,
"exampleStoryCount": 0,
"mdxCount": 0,
"onboardingDocsCount": 0,
"onboardingStoryCount": 0,
"pageStoryCount": 0,
"playStoryCount": 0,
"storiesMdxCount": 0,
Expand Down Expand Up @@ -248,6 +310,8 @@ describe('summarizeIndex', () => {
"exampleDocsCount": 0,
"exampleStoryCount": 2,
"mdxCount": 0,
"onboardingDocsCount": 0,
"onboardingStoryCount": 0,
"pageStoryCount": 1,
"playStoryCount": 1,
"storiesMdxCount": 0,
Expand Down Expand Up @@ -303,6 +367,8 @@ describe('summarizeIndex', () => {
"exampleDocsCount": 0,
"exampleStoryCount": 0,
"mdxCount": 0,
"onboardingDocsCount": 0,
"onboardingStoryCount": 0,
"pageStoryCount": 0,
"playStoryCount": 0,
"storiesMdxCount": 1,
Expand Down Expand Up @@ -359,6 +425,8 @@ describe('summarizeIndex', () => {
"exampleDocsCount": 1,
"exampleStoryCount": 2,
"mdxCount": 0,
"onboardingDocsCount": 0,
"onboardingStoryCount": 0,
"pageStoryCount": 0,
"playStoryCount": 0,
"storiesMdxCount": 0,
Expand Down Expand Up @@ -408,6 +476,8 @@ describe('summarizeIndex', () => {
"exampleDocsCount": 1,
"exampleStoryCount": 0,
"mdxCount": 2,
"onboardingDocsCount": 0,
"onboardingStoryCount": 0,
"pageStoryCount": 0,
"playStoryCount": 0,
"storiesMdxCount": 0,
Expand Down
26 changes: 21 additions & 5 deletions code/lib/core-server/src/utils/summarizeIndex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ const PAGE_REGEX = /(page|screen)/i;
export const isPageStory = (storyId: string) => PAGE_REGEX.test(storyId);

/**
* Filter out example stories that are generated by the CLI
* Is this story generated by the CLI
*/
const isExampleEntry = (entry: IndexEntry) => {
return [
const isCLIExampleEntry = (entry: IndexEntry) =>
[
'example-introduction--docs',
yannbf marked this conversation as resolved.
Show resolved Hide resolved
'configure-your-project--docs',
'example-button--docs',
'example-button--primary',
'example-button--secondary',
Expand All @@ -23,22 +24,35 @@ const isExampleEntry = (entry: IndexEntry) => {
'example-page--logged-in',
'example-page--logged-out',
].includes(entry.id);
};

/**
* Is this story part of the CLI generated examples,
* including user-created stories in those files
*/
const isAnyExampleEntry = (entry: IndexEntry) =>
entry.id.startsWith('example-button--') ||
entry.id.startsWith('example-header--') ||
entry.id.startsWith('example-page--');

export function summarizeIndex(storyIndex: StoryIndex) {
let storyCount = 0;
const componentTitles = new Set<string>();
let exampleStoryCount = 0;
let onboardingStoryCount = 0;
let onboardingDocsCount = 0;
let exampleDocsCount = 0;
let pageStoryCount = 0;
let playStoryCount = 0;
let autodocsCount = 0;
let storiesMdxCount = 0;
let mdxCount = 0;
Object.values(storyIndex.entries).forEach((entry) => {
if (isExampleEntry(entry)) {
if (isCLIExampleEntry(entry)) {
if (entry.type === 'story') exampleStoryCount += 1;
if (entry.type === 'docs') exampleDocsCount += 1;
} else if (isAnyExampleEntry(entry)) {
if (entry.type === 'story') onboardingStoryCount += 1;
if (entry.type === 'docs') onboardingDocsCount += 1;
} else if (entry.type === 'story') {
storyCount += 1;
componentTitles.add(entry.title);
Expand Down Expand Up @@ -69,6 +83,8 @@ export function summarizeIndex(storyIndex: StoryIndex) {
mdxCount,
exampleStoryCount,
exampleDocsCount,
onboardingStoryCount,
onboardingDocsCount,
version: storyIndex.v,
};
}