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.6 KB
Raw Blame
import { MakeLogicType, afterMount, kea, key, path, props } from 'kea'
import { loaders } from 'kea-loaders'

import { performQuery } from '~/queries/query'
import { setLatestVersionsOnQuery } from '~/queries/schema/query-versions'
import { NodeKind, SessionsTimelineQuery, SessionsTimelineQueryResponse } from '~/queries/schema/schema-general'

import { CUSTOMER_ANALYTICS_DEFAULT_QUERY_TAGS } from 'products/customer_analytics/frontend/constants'

import type { TimelineEntry } from '../../../../queries/schema/schema-general'

export type NotebookNodePersonFeedLogicProps = {
    personId: string
}

// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface notebookNodePersonFeedLogicValues {
    sessions: SessionsTimelineQueryResponse['results'] | null
    sessionsLoading: boolean
}

// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface notebookNodePersonFeedLogicActions {
    loadSessionsTimeline: () => any
    loadSessionsTimelineFailure: (
        error: string,
        errorObject?: any
    ) => {
        error: string
        errorObject?: any
    }
    loadSessionsTimelineSuccess: (
        sessions: TimelineEntry[],
        payload?: any
    ) => {
        sessions: TimelineEntry[]
        payload?: any
    }
}

// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface notebookNodePersonFeedLogicMeta {
    key: string
}

export type notebookNodePersonFeedLogicType = MakeLogicType<
    notebookNodePersonFeedLogicValues,
    notebookNodePersonFeedLogicActions,
    NotebookNodePersonFeedLogicProps,
    notebookNodePersonFeedLogicMeta
>

export const notebookNodePersonFeedLogic = kea<notebookNodePersonFeedLogicType>([
    props({} as NotebookNodePersonFeedLogicProps),
    path((key) => ['scenes', 'notebooks', 'Notebook', 'Nodes', 'notebookNodePersonFeedLogic', key]),
    key(({ personId }) => personId),

    loaders(({ props }) => ({
        sessions: [
            null as SessionsTimelineQueryResponse['results'] | null,
            {
                loadSessionsTimeline: async () => {
                    const result = await performQuery<SessionsTimelineQuery>(
                        setLatestVersionsOnQuery({
                            kind: NodeKind.SessionsTimelineQuery,
                            tags: CUSTOMER_ANALYTICS_DEFAULT_QUERY_TAGS,
                            personId: props.personId,
                        })
                    )
                    return result.results
                },
            },
        ],
    })),

    afterMount(({ actions }) => {
        actions.loadSessionsTimeline()
    }),
])