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.

2.5 KB
Raw Blame
import { MakeLogicType, actions, kea, listeners, path, reducers } from 'kea'
import posthog from 'posthog-js'

// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface notebookSettingsLogicValues {
    isJupyterMode: boolean
    isMarkdownExpanded: boolean
    showKernelInfo: boolean
    showVariablesOverride: boolean | null
}

// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface notebookSettingsLogicActions {
    setIsJupyterMode: (isJupyterMode: boolean) => {
        isJupyterMode: boolean
    }
    setIsMarkdownExpanded: (expanded: boolean) => {
        expanded: boolean
    }
    setShowKernelInfo: (showKernelInfo: boolean) => {
        showKernelInfo: boolean
    }
    setShowVariables: (showVariables: boolean | null) => {
        showVariables: boolean | null
    }
}

export type notebookSettingsLogicType = MakeLogicType<notebookSettingsLogicValues, notebookSettingsLogicActions>

// This logic contains settings that should persist across all notebooks
export const notebookSettingsLogic = kea<notebookSettingsLogicType>([
    path(['scenes', 'notebooks', 'notebooks', 'notebookSettingsLogic']),
    actions({
        setIsMarkdownExpanded: (expanded: boolean) => ({ expanded }),
        setIsJupyterMode: (isJupyterMode: boolean) => ({ isJupyterMode }),
        setShowKernelInfo: (showKernelInfo: boolean) => ({ showKernelInfo }),
        // null restores the default: open when the notebook declares variables, closed when not.
        setShowVariables: (showVariables: boolean | null) => ({ showVariables }),
    }),
    reducers(() => ({
        isMarkdownExpanded: [
            true,
            { persist: true },
            {
                setIsMarkdownExpanded: (_, { expanded }) => expanded,
            },
        ],
        isJupyterMode: [
            true,
            { persist: true },
            {
                setIsJupyterMode: (_, { isJupyterMode }) => isJupyterMode,
            },
        ],
        showKernelInfo: [
            false,
            {
                setShowKernelInfo: (_, { showKernelInfo }) => showKernelInfo,
            },
        ],
        showVariablesOverride: [
            null as boolean | null,
            {
                setShowVariables: (_, { showVariables }) => showVariables,
            },
        ],
    })),
    listeners(() => ({
        setIsJupyterMode: ({ isJupyterMode }) => {
            posthog.capture('notebook jupyter mode toggled', { enabled: isJupyterMode })
        },
    })),
])