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.

4.6 KB
Raw Blame
import { MakeLogicType, actions, connect, kea, listeners, path, reducers, selectors } from 'kea'

import { openTab } from '../../browser/extensionBrowser'
import { capturePageToolUsed } from '../../browser/extensionTelemetry'
import { PageToolbarMoreState, PageToolbarState } from '../../messaging/pageToolbarBridge'
import type { PageMoreCommand } from '../page/extensionPageMoreLogic'
import { extensionPageToolbarConnectionLogic } from './extensionPageToolbarConnectionLogic'

// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface extensionMoreLogicValues {
    pageToolbarState: PageToolbarState | null // extensionPageToolbarConnectionLogic
    screenshotPreview: string | null // extensionPageToolbarConnectionLogic
    moreState: PageToolbarMoreState | null
    screenshotEventName: string
}

// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface extensionMoreLogicActions {
    sendCommand: (message: import('../../messaging/pageToolbarBridge').PageToolbarCommand) => {
        message: import('../../messaging/pageToolbarBridge').PageToolbarCommand
    } // extensionPageToolbarConnectionLogic
    closeScreenshot: () => {
        value: true
    }
    openSessionRecording: (url: string) => {
        url: string
    }
    selectScreenshotEvent: (
        id: string,
        name: string
    ) => {
        id: string
        name: string
    }
    sendMoreCommand: (command: PageMoreCommand) => {
        command: PageMoreCommand
    }
    setPiiMasking: (enabled: boolean) => {
        enabled: boolean
    }
    setScreenshotEventName: (name: string) => {
        name: string
    }
    takeScreenshot: () => {
        value: true
    }
    uploadScreenshot: () => {
        value: true
    }
}

// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface extensionMoreLogicMeta {
    __keaTypeGenInternalSelectorTypes: {
        moreState: (pageToolbarState: PageToolbarState | null) => PageToolbarMoreState | null
    }
}

export type extensionMoreLogicType = MakeLogicType<
    extensionMoreLogicValues,
    extensionMoreLogicActions,
    Record<string, any>,
    extensionMoreLogicMeta
>

/** The panel side of the toolbar's "More" menu tools. */
export const extensionMoreLogic = kea<extensionMoreLogicType>([
    path(['toolbar', 'extension', 'extensionMoreLogic']),
    connect(() => ({
        values: [extensionPageToolbarConnectionLogic, ['pageToolbarState', 'screenshotPreview']],
        actions: [extensionPageToolbarConnectionLogic, ['sendCommand']],
    })),
    actions({
        sendMoreCommand: (command: PageMoreCommand) => ({ command }),
        openSessionRecording: (url: string) => ({ url }),
        setPiiMasking: (enabled: boolean) => ({ enabled }),
        takeScreenshot: true,
        setScreenshotEventName: (name: string) => ({ name }),
        selectScreenshotEvent: (id: string, name: string) => ({ id, name }),
        uploadScreenshot: true,
        closeScreenshot: true,
    }),
    reducers({
        // The page searches event names a moment later, so the input keeps what the user typed meanwhile.
        screenshotEventName: [
            '',
            {
                setScreenshotEventName: (_, { name }) => name,
                selectScreenshotEvent: (_, { name }) => name,
                closeScreenshot: () => '',
                takeScreenshot: () => '',
            },
        ],
    }),
    selectors({
        moreState: [
            (s) => [s.pageToolbarState],
            (pageToolbarState: PageToolbarState | null): PageToolbarMoreState | null => pageToolbarState?.more ?? null,
        ],
    }),
    listeners(({ actions }) => ({
        sendMoreCommand: ({ command }) => actions.sendCommand({ tool: 'more', command }),
        openSessionRecording: ({ url }) => {
            void openTab(url)
            capturePageToolUsed('view-session-recording')
        },
        setPiiMasking: ({ enabled }) => {
            actions.sendMoreCommand({ type: 'set-pii-masking', enabled })
            if (enabled) {
                capturePageToolUsed('pii-masking')
            }
        },
        takeScreenshot: () => actions.sendMoreCommand({ type: 'take-screenshot' }),
        setScreenshotEventName: ({ name }) => actions.sendMoreCommand({ type: 'set-screenshot-event-name', name }),
        selectScreenshotEvent: ({ id }) => actions.sendMoreCommand({ type: 'select-screenshot-event', id }),
        uploadScreenshot: () => {
            actions.sendMoreCommand({ type: 'upload-screenshot' })
            capturePageToolUsed('screenshot-for-event')
        },
        closeScreenshot: () => actions.sendMoreCommand({ type: 'close-screenshot' }),
    })),
])