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 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
2 changes: 2 additions & 0 deletions code/frameworks/ember/template/cli/Button.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ export default {
argTypes: {
label: { control: 'text' },
},
// This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/7.0/react/writing-docs/docs-page
tags: ['autodocs'],
};

// More on writing stories with args: https://storybook.js.org/docs/7.0/ember/writing-stories/args
Expand Down
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,
};
}
2 changes: 2 additions & 0 deletions code/renderers/react/template/cli/ts-legacy/Button.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { Button } from './Button';
const meta: Meta<typeof Button> = {
title: 'Example/Button',
component: Button,
// This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/7.0/react/writing-docs/docs-page
tags: ['autodocs'],
// More on argTypes: https://storybook.js.org/docs/react/api/argtypes
argTypes: {
backgroundColor: { control: 'color' },
Expand Down
2 changes: 2 additions & 0 deletions code/renderers/react/template/cli/ts-legacy/Header.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { Header } from './Header';
const meta: Meta<typeof Header> = {
title: 'Example/Header',
component: Header,
// This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/7.0/react/writing-docs/docs-page
tags: ['autodocs'],
parameters: {
// More on Story layout: https://storybook.js.org/docs/react/configure/story-layout
layout: 'fullscreen',
Expand Down
6 changes: 6 additions & 0 deletions scripts/event-log-checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ async function run() {
assert.equal(bootEvent.eventType, 'boot');
assert.equal(bootEvent.payload?.eventType, eventType);

const { exampleStoryCount, exampleDocsCount } = mainEvent.payload?.storyIndex || {};
if (['build', 'dev'].includes(eventType)) {
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