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.

1.4 KB
Raw Blame
import { useActions, useValues } from 'kea'

import { RestrictionScope, useRestrictedArea } from 'lib/components/RestrictedArea'
import { TeamMembershipLevel } from 'lib/constants'

import { ExperimentStatsMethod } from '~/types'

import { StatsMethodSelector } from 'products/experiments/frontend/components/StatsMethodSelector'

import { experimentsConfigLogic } from './experimentsConfigLogic'

export function DefaultExperimentStatsMethod(): JSX.Element {
    const { experimentsConfig, experimentsConfigLoading } = useValues(experimentsConfigLogic)
    const { updateExperimentsConfig } = useActions(experimentsConfigLogic)

    const restrictionReason = useRestrictedArea({
        scope: RestrictionScope.Project,
        minimumAccessLevel: TeamMembershipLevel.Admin,
    })

    const handleChange = (value: ExperimentStatsMethod): void => {
        updateExperimentsConfig({ default_experiment_stats_method: value })
    }

    return (
        <StatsMethodSelector
            value={
                (experimentsConfig?.default_experiment_stats_method as ExperimentStatsMethod) ??
                ExperimentStatsMethod.Bayesian
            }
            onChange={handleChange}
            disabled={!!restrictionReason || experimentsConfigLoading}
            disabledReason={restrictionReason || (experimentsConfigLoading ? 'Loading...' : undefined)}
        />
    )
}