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.8 KB
Raw Blame
// Lightweight logic that loads and caches a batch export's configuration.
// Child logics (runs, backfills, modal) connect here instead of the heavyweight form logic,
// so they can be mounted independently (e.g. from the hog function backfills tab).
import { MakeLogicType, afterMount, kea, key, path, props } from 'kea'
import { loaders } from 'kea-loaders'

import api from 'lib/api'

import { BatchExportConfiguration } from '~/types'

export interface BatchExportConfigLogicProps {
    id: string | null
}

// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface batchExportDataLogicValues {
    batchExportConfig: BatchExportConfiguration | null
    batchExportConfigLoading: boolean
}

// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface batchExportDataLogicActions {
    loadBatchExportConfig: () => any
    loadBatchExportConfigFailure: (
        error: string,
        errorObject?: any
    ) => {
        error: string
        errorObject?: any
    }
    loadBatchExportConfigSuccess: (
        batchExportConfig: BatchExportConfiguration | null,
        payload?: any
    ) => {
        batchExportConfig: BatchExportConfiguration | null
        payload?: any
    }
    setBatchExportConfig: (config: BatchExportConfiguration) => BatchExportConfiguration
    setBatchExportConfigFailure: (
        error: string,
        errorObject?: any
    ) => {
        error: string
        errorObject?: any
    }
    setBatchExportConfigSuccess: (
        batchExportConfig: BatchExportConfiguration,
        payload?: BatchExportConfiguration
    ) => {
        batchExportConfig: BatchExportConfiguration
        payload?: BatchExportConfiguration
    }
}

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

export type batchExportDataLogicType = MakeLogicType<
    batchExportDataLogicValues,
    batchExportDataLogicActions,
    BatchExportConfigLogicProps,
    batchExportDataLogicMeta
>

export const batchExportDataLogic = kea<batchExportDataLogicType>([
    props({} as BatchExportConfigLogicProps),
    key(({ id }) => id ?? 'new'),
    path((key) => ['scenes', 'data-pipelines', 'batch-exports', 'batchExportDataLogic', key]),
    loaders(({ props }) => ({
        batchExportConfig: [
            null as BatchExportConfiguration | null,
            {
                loadBatchExportConfig: async () => {
                    if (props.id) {
                        return await api.batchExports.get(props.id)
                    }
                    return null
                },
                setBatchExportConfig: (config: BatchExportConfiguration) => config,
            },
        ],
    })),
    afterMount(({ actions }) => {
        actions.loadBatchExportConfig()
    }),
])