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.

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

import { FEATURE_FLAGS, FeatureFlagKey } from 'lib/constants'
import { LemonTab } from 'lib/lemon-ui/LemonTabs'
import { FeatureFlagsSet, featureFlagLogic } from 'lib/logic/featureFlagLogic'
import { urls } from 'scenes/urls'

import { iconForType } from '~/layout/panel-layout/ProjectTree/defaultTree'
import { FileSystemIconType } from '~/queries/schema/schema-general'

export type DefinitionsSceneTabKey =
    | 'core-events'
    | 'events'
    | 'properties'
    | 'schema'
    | 'revenue'
    | 'warehouse-properties'

interface DefinitionsSceneTab {
    key: DefinitionsSceneTabKey
    label: string
    url: string
    iconType: FileSystemIconType
    flag?: FeatureFlagKey
    tooltipDocLink?: string
}

export const DEFINITIONS_TABS: DefinitionsSceneTab[] = [
    {
        key: 'core-events',
        label: 'Core events',
        url: urls.coreEvents(),
        iconType: 'core_event',
        flag: FEATURE_FLAGS.NEW_TEAM_CORE_EVENTS,
    },
    {
        key: 'events',
        label: 'Event definitions',
        url: urls.eventDefinitions(),
        iconType: 'event_definition',
        tooltipDocLink: 'https://posthog.com/docs/data/events',
    },
    {
        key: 'properties',
        label: 'Property definitions',
        url: urls.propertyDefinitions(),
        iconType: 'property_definition',
        tooltipDocLink: 'https://posthog.com/docs/new-to-posthog/understand-posthog#properties',
    },
    {
        key: 'schema',
        label: 'Property groups',
        url: urls.schemaManagement(),
        iconType: 'property_group',
        flag: FEATURE_FLAGS.SCHEMA_MANAGEMENT,
    },
    {
        key: 'revenue',
        label: 'Revenue definitions',
        url: urls.revenueSettings(),
        iconType: 'revenue_analytics_metadata',
    },
    {
        key: 'warehouse-properties',
        label: 'Warehouse properties',
        url: urls.warehouseProperties(),
        iconType: 'warehouse_property',
        flag: FEATURE_FLAGS.WAREHOUSE_PERSON_PROPERTIES,
    },
]

// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface definitionsSceneTabsLogicValues {
    featureFlags: FeatureFlagsSet // featureFlagLogic
    tabs: LemonTab<DefinitionsSceneTabKey>[]
}

// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface definitionsSceneTabsLogicMeta {
    __keaTypeGenInternalSelectorTypes: {
        tabs: (featureFlags: FeatureFlagsSet) => LemonTab<DefinitionsSceneTabKey>[]
    }
}

export type definitionsSceneTabsLogicType = MakeLogicType<
    definitionsSceneTabsLogicValues,
    {},
    Record<string, any>,
    definitionsSceneTabsLogicMeta
>

export const definitionsSceneTabsLogic = kea<definitionsSceneTabsLogicType>([
    path(['scenes', 'data-management', 'definitionsSceneTabsLogic']),
    connect(() => ({
        values: [featureFlagLogic, ['featureFlags']],
    })),
    selectors({
        tabs: [
            (s) => [s.featureFlags],
            (featureFlags: FeatureFlagsSet): LemonTab<DefinitionsSceneTabKey>[] =>
                DEFINITIONS_TABS.filter((tab) => !tab.flag || !!featureFlags[tab.flag]).map((tab) => ({
                    key: tab.key,
                    label: (
                        <span className="flex items-center gap-1">
                            {iconForType(tab.iconType)}
                            {tab.label}
                        </span>
                    ),
                    tooltipDocLink: tab.tooltipDocLink,
                    link: tab.url,
                })),
        ],
    }),
])