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.1 KB
Raw Blame
import { FeatureFlagGroupType } from '~/types'

// The shared group aggregation when every group agrees, otherwise null (mixed or none).
export function uniformAggregationGroupTypeIndex(groups: FeatureFlagGroupType[]): number | null {
    const indices = groups.map((group) => group.aggregation_group_type_index ?? null)
    return indices.length > 0 && indices.every((index) => index === indices[0]) ? indices[0] : null
}

// Mirror a top-level group aggregation onto every group — the inverse of uniformAggregationGroupTypeIndex.
// A null index leaves each group's own index untouched (so mixed-targeting per-group values survive and
// loading a saved config doesn't dirty the form); groups already at the target index are returned as-is
// to keep the dirty-check stable.
export function distributeAggregationGroupTypeIndex(
    groups: FeatureFlagGroupType[],
    index: number | null
): FeatureFlagGroupType[] {
    if (index === null) {
        return groups
    }
    return groups.map((group) =>
        group.aggregation_group_type_index === index ? group : { ...group, aggregation_group_type_index: index }
    )
}