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.

4.0 KB
Raw Blame
import { MakeLogicType, connect, kea, path, selectors } from 'kea'

import { superpowersLogic } from 'lib/components/Superpowers/superpowersLogic'
import type { NormalizedStatus } from 'lib/lemon-ui/LemonToast/incidentStatus'
import { capitalizeFirstLetter } from 'lib/utils/strings'

import type { FakeStatusOverride } from '../Superpowers/superpowersLogic'
import { incidentStatusLogic } from './incidentStatusLogic'

export type PostHogStatusType = 'operational' | 'degraded_performance' | 'partial_outage' | 'major_outage'
export type PostHogStatusBadgeStatus = 'success' | 'warning' | 'danger'

// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface posthogStatusLogicValues {
    status: NormalizedStatus // incidentStatusLogic
    statusDescription: string | null // incidentStatusLogic
    statusPageUrl: string // incidentStatusLogic
    fakeStatusOverride: FakeStatusOverride // superpowersLogic
    superpowersEnabled: boolean | undefined // superpowersLogic
    isFakeStatus: boolean
    postHogStatus: PostHogStatusType
    postHogStatusBadgeContent: string
    postHogStatusBadgeStatus: PostHogStatusBadgeStatus
    postHogStatusTooltip: string | null
}

// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface posthogStatusLogicMeta {
    __keaTypeGenInternalSelectorTypes: {
        postHogStatus: (status: NormalizedStatus) => PostHogStatusType
        isFakeStatus: (superpowersEnabled: boolean | undefined, fakeStatusOverride: FakeStatusOverride) => boolean
        postHogStatusTooltip: (
            statusDescription: string | null,
            isFakeStatus: boolean,
            postHogStatus: PostHogStatusType
        ) => string | null
        postHogStatusBadgeContent: (postHogStatus: PostHogStatusType) => string
        postHogStatusBadgeStatus: (postHogStatus: PostHogStatusType) => PostHogStatusBadgeStatus
    }
}

export type posthogStatusLogicType = MakeLogicType<
    posthogStatusLogicValues,
    {},
    Record<string, any>,
    posthogStatusLogicMeta
>

export const posthogStatusLogic = kea<posthogStatusLogicType>([
    path(['lib', 'components', 'HelpMenu', 'posthogStatusLogic']),
    connect({
        values: [
            incidentStatusLogic,
            ['status', 'statusDescription', 'statusPageUrl'],
            superpowersLogic,
            ['fakeStatusOverride', 'superpowersEnabled'],
        ],
    }),
    selectors({
        postHogStatus: [(s) => [s.status], (status: NormalizedStatus): PostHogStatusType => status],
        isFakeStatus: [
            (s) => [s.superpowersEnabled, s.fakeStatusOverride],
            (
                superpowersEnabled: boolean | undefined,
                fakeStatusOverride: import('lib/components/Superpowers/superpowersLogic').FakeStatusOverride
            ): boolean => !!superpowersEnabled && fakeStatusOverride !== 'none',
        ],
        postHogStatusTooltip: [
            (s) => [s.statusDescription, s.isFakeStatus, s.postHogStatus],
            (
                statusDescription: string | null,
                isFakeStatus: boolean,
                postHogStatus: PostHogStatusType
            ): string | null => {
                if (isFakeStatus) {
                    return `[DRILL] ${capitalizeFirstLetter(postHogStatus.replace(/_/g, ' '))}`
                }
                return statusDescription
            },
        ],
        postHogStatusBadgeContent: [
            (s) => [s.postHogStatus],
            (postHogStatus: PostHogStatusType): string => (postHogStatus !== 'operational' ? '!' : '✓'),
        ],
        postHogStatusBadgeStatus: [
            (s) => [s.postHogStatus],
            (postHogStatus: PostHogStatusType): PostHogStatusBadgeStatus => {
                if (postHogStatus.includes('outage')) {
                    return 'danger'
                }
                if (postHogStatus.includes('degraded') || postHogStatus.includes('monitoring')) {
                    return 'warning'
                }
                return 'success'
            },
        ],
    }),
])