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

import type { ExperimentMetric } from '~/queries/schema/schema-general'
import type { ExperimentMetricUnion } from '~/queries/schema/schema-general'

import {
    METRIC_CONTEXTS,
    type MetricContext,
} from 'products/experiments/frontend/modals/ExperimentMetricModal/experimentMetricModalLogic'

// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface sharedMetricDetailsModalLogicValues {
    context: MetricContext
    isModalOpen: boolean
    sharedMetric: ExperimentMetric | null
}

// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface sharedMetricDetailsModalLogicActions {
    closeSharedMetricDetailModal: () => {
        value: true
    }
    openSharedMetricDetailModal: (
        metric: ExperimentMetric,
        context: MetricContext
    ) => {
        context: MetricContext
        metric: ExperimentMetricUnion
    }
}

export type sharedMetricDetailsModalLogicType = MakeLogicType<
    sharedMetricDetailsModalLogicValues,
    sharedMetricDetailsModalLogicActions
>

export const sharedMetricDetailsModalLogic = kea<sharedMetricDetailsModalLogicType>([
    path(['scenes', 'experiments', 'Metrics', 'sharedMetricDetailsModalLogic']),

    actions({
        openSharedMetricDetailModal: (metric: ExperimentMetric, context: MetricContext) => ({
            metric,
            context,
        }),
        closeSharedMetricDetailModal: true,
    }),

    reducers({
        isModalOpen: [
            false,
            {
                openSharedMetricDetailModal: () => true,
                closeSharedMetricDetailModal: () => false,
            },
        ],
        sharedMetric: [
            null as ExperimentMetric | null,
            {
                openSharedMetricDetailModal: (_, { metric }) => metric,
                closeSharedMetricDetailModal: () => null,
            },
        ],
        context: [
            METRIC_CONTEXTS.primary as MetricContext,
            {
                openSharedMetricDetailModal: (_, { context }) => context,
                closeSharedMetricDetailModal: () => METRIC_CONTEXTS.primary,
            },
        ],
    }),
])