From 9637c28e9db7adc92bba6901e19e108375a8b675 Mon Sep 17 00:00:00 2001 From: Michael Shilman Date: Fri, 16 Jun 2023 00:52:36 +0800 Subject: [PATCH 1/2] Telemetry: Count onboarding stories --- .../src/utils/summarizeIndex.test.ts | 70 +++++++++++++++++++ .../core-server/src/utils/summarizeIndex.ts | 14 +++- 2 files changed, 81 insertions(+), 3 deletions(-) diff --git a/code/lib/core-server/src/utils/summarizeIndex.test.ts b/code/lib/core-server/src/utils/summarizeIndex.test.ts index 71fb515a005f..8662b0e45716 100644 --- a/code/lib/core-server/src/utils/summarizeIndex.test.ts +++ b/code/lib/core-server/src/utils/summarizeIndex.test.ts @@ -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, @@ -193,6 +253,8 @@ describe('summarizeIndex', () => { "exampleDocsCount": 0, "exampleStoryCount": 0, "mdxCount": 0, + "onboardingDocsCount": 0, + "onboardingStoryCount": 0, "pageStoryCount": 0, "playStoryCount": 0, "storiesMdxCount": 0, @@ -248,6 +310,8 @@ describe('summarizeIndex', () => { "exampleDocsCount": 0, "exampleStoryCount": 2, "mdxCount": 0, + "onboardingDocsCount": 0, + "onboardingStoryCount": 0, "pageStoryCount": 1, "playStoryCount": 1, "storiesMdxCount": 0, @@ -303,6 +367,8 @@ describe('summarizeIndex', () => { "exampleDocsCount": 0, "exampleStoryCount": 0, "mdxCount": 0, + "onboardingDocsCount": 0, + "onboardingStoryCount": 0, "pageStoryCount": 0, "playStoryCount": 0, "storiesMdxCount": 1, @@ -359,6 +425,8 @@ describe('summarizeIndex', () => { "exampleDocsCount": 1, "exampleStoryCount": 2, "mdxCount": 0, + "onboardingDocsCount": 0, + "onboardingStoryCount": 0, "pageStoryCount": 0, "playStoryCount": 0, "storiesMdxCount": 0, @@ -408,6 +476,8 @@ describe('summarizeIndex', () => { "exampleDocsCount": 1, "exampleStoryCount": 0, "mdxCount": 2, + "onboardingDocsCount": 0, + "onboardingStoryCount": 0, "pageStoryCount": 0, "playStoryCount": 0, "storiesMdxCount": 0, diff --git a/code/lib/core-server/src/utils/summarizeIndex.ts b/code/lib/core-server/src/utils/summarizeIndex.ts index 601455bcfcba..2921ca6c18b1 100644 --- a/code/lib/core-server/src/utils/summarizeIndex.ts +++ b/code/lib/core-server/src/utils/summarizeIndex.ts @@ -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); + /** * Filter out example stories that are generated by the CLI */ -const isExampleEntry = (entry: IndexEntry) => { - return [ +const isExampleEntry = (entry: IndexEntry) => + [ 'example-introduction--docs', 'example-button--docs', 'example-button--primary', @@ -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(); let exampleStoryCount = 0; + let onboardingStoryCount = 0; + let onboardingDocsCount = 0; let exampleDocsCount = 0; let pageStoryCount = 0; let playStoryCount = 0; @@ -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); @@ -69,6 +75,8 @@ export function summarizeIndex(storyIndex: StoryIndex) { mdxCount, exampleStoryCount, exampleDocsCount, + onboardingStoryCount, + onboardingDocsCount, version: storyIndex.v, }; } From 8a424a0a462f85be6c1f1de749fe9393ed8fa250 Mon Sep 17 00:00:00 2001 From: Michael Shilman Date: Fri, 16 Jun 2023 01:13:03 +0800 Subject: [PATCH 2/2] Improve based on PR feedback --- .../core-server/src/utils/summarizeIndex.ts | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/code/lib/core-server/src/utils/summarizeIndex.ts b/code/lib/core-server/src/utils/summarizeIndex.ts index 2921ca6c18b1..091038cdaccf 100644 --- a/code/lib/core-server/src/utils/summarizeIndex.ts +++ b/code/lib/core-server/src/utils/summarizeIndex.ts @@ -6,14 +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); - /** - * Filter out example stories that are generated by the CLI + * Is this story generated by the CLI */ -const isExampleEntry = (entry: IndexEntry) => +const isCLIExampleEntry = (entry: IndexEntry) => [ 'example-introduction--docs', + 'configure-your-project--docs', 'example-button--docs', 'example-button--primary', 'example-button--secondary', @@ -26,6 +25,15 @@ const isExampleEntry = (entry: IndexEntry) => '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(); @@ -39,10 +47,10 @@ export function summarizeIndex(storyIndex: StoryIndex) { 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 (isOnboardingEntry(entry)) { + } else if (isAnyExampleEntry(entry)) { if (entry.type === 'story') onboardingStoryCount += 1; if (entry.type === 'docs') onboardingDocsCount += 1; } else if (entry.type === 'story') {