Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

2.7 KB
Raw Blame
import type { Meta, StoryObj } from '@storybook/react'
import { useActions } from 'kea'

import { useOnMountEffect } from 'lib/hooks/useOnMountEffect'

import { mswDecorator } from '~/mocks/browser'

import { healthSummaryLogic } from './healthSummaryLogic'
import { HelpMenu } from './HelpMenu'
import { helpMenuLogic } from './helpMenuLogic'

// The health-issues summary is the only request the menu makes that the default Storybook
// mocks (billing, preflight, users/@me, status page) don't already cover. Mocking it drives
// the trigger/Health badge state deterministically.
const NO_ISSUES = { total: 0, by_severity: {}, by_kind: {} }
const HEALTHY_SUMMARY = { unsnoozed: NO_ISSUES, snoozed: NO_ISSUES }
const UNHEALTHY_SUMMARY = {
    unsnoozed: {
        total: 3,
        by_severity: { critical: 1, warning: 2 },
        by_kind: { ingestion_warning: 2, query_error: 1 },
    },
    snoozed: NO_ISSUES,
}
const ALL_SNOOZED_SUMMARY = {
    unsnoozed: NO_ISSUES,
    snoozed: {
        total: 3,
        by_severity: { critical: 1, warning: 2 },
        by_kind: { ingestion_warning: 2, query_error: 1 },
    },
}

const meta: Meta<typeof HelpMenu> = {
    title: 'Components/Help Menu',
    component: HelpMenu,
    render: () => {
        const { setHelpMenuOpen } = useActions(helpMenuLogic)
        const { loadHealthSummary } = useActions(healthSummaryLogic)
        useOnMountEffect(() => {
            setHelpMenuOpen(true)
            // The app waits for the browser to go idle before it loads the summary. Load it now so
            // the snapshot does not depend on when that happens.
            loadHealthSummary()
        })

        return (
            <div className="flex h-[1400px] w-[600px]">
                <HelpMenu />
            </div>
        )
    },
    parameters: {
        // Not `fullscreen` — the runner rejects snapshotTargetSelector for fullscreen stories.
        layout: 'centered',
        // Tall viewport so the open menu renders its full height without the popup's internal
        // ScrollableShadows clipping items (it's capped at the available height).
        testOptions: { viewport: { width: 600, height: 1400 } },
    },
}
export default meta

type Story = StoryObj<typeof HelpMenu>

export const Open: Story = {
    decorators: [mswDecorator({ get: { '/api/environments/:team_id/health_issues/summary/': HEALTHY_SUMMARY } })],
}

export const OpenWithHealthIssues: Story = {
    decorators: [mswDecorator({ get: { '/api/environments/:team_id/health_issues/summary/': UNHEALTHY_SUMMARY } })],
}

export const OpenWithSnoozedHealthIssues: Story = {
    decorators: [mswDecorator({ get: { '/api/environments/:team_id/health_issues/summary/': ALL_SNOOZED_SUMMARY } })],
}