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.1 KB
Raw Blame
import { MakeLogicType, actions, afterMount, connect, kea, listeners, path, selectors } from 'kea'
import { subscriptions } from 'kea-subscriptions'

import { FEATURE_FLAGS } from 'lib/constants'
import { FeatureFlagsSet, featureFlagLogic } from 'lib/logic/featureFlagLogic'

import { projectTreeDataLogic } from '~/layout/panel-layout/ProjectTree/projectTreeDataLogic'

import type { FileSystemEntry } from '../../../queries/schema/schema-general'
import type { ProjectTreeRef } from '../../../types'

// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface sceneFileLogicValues {
    featureFlags: FeatureFlagsSet // featureFlagLogic
    projectTreeRef: ProjectTreeRef | null // projectTreeDataLogic
    projectTreeRefEntry: FileSystemEntry | null // projectTreeDataLogic
    fileItemsEntry: FileSystemEntry | null
    hasFileItems: boolean
}

// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface sceneFileLogicActions {
    syncTypeAndRef: (
        type: string,
        ref: string
    ) => {
        ref: string
        type: string
    } // projectTreeDataLogic
    loadCurrentItem: () => {
        value: true
    }
}

// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface sceneFileLogicMeta {
    __keaTypeGenInternalSelectorTypes: {
        fileItemsEntry: (
            projectTreeRefEntry: FileSystemEntry | null,
            featureFlags: FeatureFlagsSet
        ) => FileSystemEntry | null
        hasFileItems: (fileItemsEntry: FileSystemEntry | null) => boolean
    }
}

export type sceneFileLogicType = MakeLogicType<
    sceneFileLogicValues,
    sceneFileLogicActions,
    Record<string, any>,
    sceneFileLogicMeta
>

export const sceneFileLogic = kea<sceneFileLogicType>([
    path(['lib', 'components', 'Scenes', 'sceneFileLogic']),
    connect({
        values: [featureFlagLogic, ['featureFlags'], projectTreeDataLogic, ['projectTreeRef', 'projectTreeRefEntry']],
        actions: [projectTreeDataLogic, ['syncTypeAndRef']],
    }),
    actions({
        loadCurrentItem: true,
    }),
    selectors({
        /** The scene's project tree entry that the menu bar's file items act on. The Today layout has no project tree. */
        fileItemsEntry: [
            (s) => [s.projectTreeRefEntry, s.featureFlags],
            (projectTreeRefEntry: FileSystemEntry | null, featureFlags: FeatureFlagsSet): FileSystemEntry | null =>
                featureFlags[FEATURE_FLAGS.TODAY_RAIL_NAV] ? null : projectTreeRefEntry,
        ],
        hasFileItems: [
            (s) => [s.fileItemsEntry],
            (fileItemsEntry: FileSystemEntry | null): boolean => !!fileItemsEntry,
        ],
    }),
    listeners(({ actions, values }) => ({
        loadCurrentItem: () => {
            const ref = values.projectTreeRef
            if (ref?.ref && !values.projectTreeRefEntry) {
                actions.syncTypeAndRef(ref.type, ref.ref)
            }
        },
    })),
    subscriptions(({ actions }) => ({
        projectTreeRef: () => actions.loadCurrentItem(),
    })),
    afterMount(({ actions }) => actions.loadCurrentItem()),
])