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.6 KB
Raw Blame
import type { ExperimentExposureQueryResponse } from '~/queries/schema/schema-general'

import { type HealthReading, healthCheckReadings, healthExposureSplit } from './healthCheckValues'
import { HealthExposureSplitTable } from './HealthExposureSplitTable'
import type { HealthPanelCheck } from './healthPanelChecks'
import { HealthPanelSection } from './HealthPanelSection'
import { HealthReadingList } from './HealthReadingList'

// These checks compare the variants, so they show the split that the exposure answer counted.
const CHECKS_WITH_SPLIT: ReadonlySet<HealthPanelCheck['key']> = new Set(['srm', 'bias_risk_multiple_excluded'])

export function HealthCheckReadSection({
    check,
    units,
    exposures,
}: {
    check: HealthPanelCheck
    units: string
    exposures: ExperimentExposureQueryResponse | null
}): JSX.Element | null {
    // An exposure answer cached before the server added the values keeps the layout without them.
    if (!check.values || Object.keys(check.values).length === 0) {
        return null
    }
    const split = CHECKS_WITH_SPLIT.has(check.key) ? healthExposureSplit(exposures) : null
    const countedFrom = split ? exposures?.date_range.date_from : null
    const readings: HealthReading[] = [
        ...healthCheckReadings(check.values, units),
        ...(countedFrom ? [{ label: 'Exposures counted from', time: countedFrom, asDate: true }] : []),
    ]

    return (
        <HealthPanelSection title="What it read">
            {split && <HealthExposureSplitTable rows={split} units={units} />}
            {readings.length > 0 && <HealthReadingList readings={readings} />}
        </HealthPanelSection>
    )
}