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: Filter out example stories/docs from summary #20553

Merged
merged 3 commits into from
Jan 10, 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
30 changes: 28 additions & 2 deletions code/lib/core-server/src/utils/summarizeIndex.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,44 @@
import type { StoryIndex } from '@storybook/types';
import type { IndexEntry, StoryIndex } from '@storybook/types';

import { STORIES_MDX_TAG, isMdxEntry, AUTODOCS_TAG, PLAY_FN_TAG } from './StoryIndexGenerator';

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
*/
const isExampleEntry = (entry: IndexEntry) => {
return [
'example-introduction--docs',
'example-button--docs',
'example-button--primary',
'example-button--secondary',
'example-button--large',
'example-button--small',
'example-header--docs',
'example-header--logged-in',
'example-header--logged-out',
'example-page--logged-in',
'example-page--logged-out',
].includes(entry.id);
};

export function summarizeIndex(storyIndex: StoryIndex) {
let storyCount = 0;
let exampleStoryCount = 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 (entry.type === 'story') {
if (isExampleEntry(entry)) {
if (entry.type === 'story') exampleStoryCount += 1;
if (entry.type === 'docs') exampleDocsCount += 1;
} else if (entry.type === 'story') {
storyCount += 1;
if (isPageStory(entry.title)) {
pageStoryCount += 1;
Expand All @@ -39,6 +63,8 @@ export function summarizeIndex(storyIndex: StoryIndex) {
autodocsCount,
storiesMdxCount,
mdxCount,
exampleStoryCount,
exampleDocsCount,
version: storyIndex.v,
};
}
4 changes: 4 additions & 0 deletions scripts/event-log-checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ async function run() {
assert.equal(bootEvent.eventType, 'boot');
assert.equal(bootEvent.payload?.eventType, eventType);

const { exampleStoryCount, exampleDocsCount } = mainEvent.payload?.storyIndex || {};
assert.equal(exampleStoryCount, 8);
assert.equal(exampleDocsCount, 3);

assert.equal(mainEvent.eventType, eventType);
assert.notEqual(mainEvent.eventId, bootEvent.eventId);
assert.equal(mainEvent.sessionId, bootEvent.sessionId);
Expand Down