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.8 KB
Raw Blame
import { MakeLogicType, actions, connect, kea, path, reducers, selectors } from 'kea'

import { healthSummaryLogic } from './healthSummaryLogic'

export type HelpBadgeStatus = 'danger' | 'warning' | 'success'

// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface helpMenuLogicValues {
    criticalCount: number // healthSummaryLogic
    unsnoozedCount: number // healthSummaryLogic
    warningCount: number // healthSummaryLogic
    hasHealthIssue: boolean
    isHelpMenuOpen: boolean
    triggerBadgeContent: string
    triggerBadgeStatus: HelpBadgeStatus
}

// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface helpMenuLogicActions {
    setHelpMenuOpen: (isOpen: boolean) => {
        isOpen: boolean
    }
    toggleHelpMenu: () => {
        value: true
    }
}

// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface helpMenuLogicMeta {
    __keaTypeGenInternalSelectorTypes: {
        hasHealthIssue: (unsnoozedCount: number) => boolean
        triggerBadgeContent: (hasHealthIssue: boolean) => string
        triggerBadgeStatus: (hasHealthIssue: boolean, criticalCount: number, warningCount: number) => HelpBadgeStatus
    }
}

export type helpMenuLogicType = MakeLogicType<
    helpMenuLogicValues,
    helpMenuLogicActions,
    Record<string, any>,
    helpMenuLogicMeta
>

export const helpMenuLogic = kea<helpMenuLogicType>([
    path(['lib', 'components', 'HelpMenu', 'helpMenuLogic']),
    connect(() => ({
        values: [healthSummaryLogic, ['unsnoozedCount', 'criticalCount', 'warningCount']],
    })),
    actions({
        setHelpMenuOpen: (isOpen: boolean) => ({ isOpen }),
        toggleHelpMenu: true,
    }),
    reducers({
        isHelpMenuOpen: [
            false,
            {
                setHelpMenuOpen: (_, { isOpen }) => isOpen,
                toggleHelpMenu: (state) => !state,
            },
        ],
    }),
    selectors({
        hasHealthIssue: [(s) => [s.unsnoozedCount], (unsnoozedCount: number): boolean => unsnoozedCount > 0],
        triggerBadgeContent: [
            (s) => [s.hasHealthIssue],
            (hasHealthIssue: boolean): string => (hasHealthIssue ? '!' : ''),
        ],
        triggerBadgeStatus: [
            (s) => [s.hasHealthIssue, s.criticalCount, s.warningCount],
            (hasHealthIssue: boolean, criticalCount: number, warningCount: number): HelpBadgeStatus => {
                if (!hasHealthIssue) {
                    return 'success'
                }
                if (criticalCount > 0) {
                    return 'danger'
                }
                if (warningCount > 0) {
                    return 'warning'
                }
                return 'success'
            },
        ],
    }),
])