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 1 commit
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
14 changes: 11 additions & 3 deletions code/lib/core-server/src/utils/summarizeIndex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ const PAGE_REGEX = /(page|screen)/i;

export const isPageStory = (storyId: string) => PAGE_REGEX.test(storyId);

const isOnboardingEntry = (entry: IndexEntry) => ['example-button--warning'].includes(entry.id);
shilman marked this conversation as resolved.
Show resolved Hide resolved

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

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;
Expand All @@ -39,6 +42,9 @@ export function summarizeIndex(storyIndex: StoryIndex) {
if (isExampleEntry(entry)) {
if (entry.type === 'story') exampleStoryCount += 1;
if (entry.type === 'docs') exampleDocsCount += 1;
} else if (isOnboardingEntry(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 +75,8 @@ export function summarizeIndex(storyIndex: StoryIndex) {
mdxCount,
exampleStoryCount,
exampleDocsCount,
onboardingStoryCount,
onboardingDocsCount,
version: storyIndex.v,
};
}