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

import api from 'lib/api'

import { DataWarehouseManagedViewsetKind } from '~/queries/schema/schema-general'
import { DataWarehouseManagedViewsetSavedQuery } from '~/types'

export const VIEWSET_TITLES: Record<DataWarehouseManagedViewsetKind, string> = {
    revenue_analytics: 'Revenue analytics',
}

export interface DisableDataWarehouseManagedViewsetModalLogicProps {
    type: string
}

// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface disableDataWarehouseManagedViewsetModalLogicValues {
    confirmationInput: string
    isDeleting: boolean
    isOpen: boolean
    kind: DataWarehouseManagedViewsetKind | null
    views: DataWarehouseManagedViewsetSavedQuery[]
    viewsLoading: boolean
}

// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface disableDataWarehouseManagedViewsetModalLogicActions {
    closeModal: () => {
        value: true
    }
    openModal: (kind: DataWarehouseManagedViewsetKind) => {
        kind: 'revenue_analytics'
    }
    openModalFailure: (
        error: string,
        errorObject?: any
    ) => {
        error: string
        errorObject?: any
    }
    openModalSuccess: (
        views: DataWarehouseManagedViewsetSavedQuery[],
        payload?: {
            kind: 'revenue_analytics'
        }
    ) => {
        views: DataWarehouseManagedViewsetSavedQuery[]
        payload?: {
            kind: 'revenue_analytics'
        }
    }
    setConfirmationInput: (confirmationInput: string) => {
        confirmationInput: string
    }
    setIsDeleting: (isDeleting: boolean) => {
        isDeleting: boolean
    }
}

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

export type disableDataWarehouseManagedViewsetModalLogicType = MakeLogicType<
    disableDataWarehouseManagedViewsetModalLogicValues,
    disableDataWarehouseManagedViewsetModalLogicActions,
    DisableDataWarehouseManagedViewsetModalLogicProps,
    disableDataWarehouseManagedViewsetModalLogicMeta
>

export const disableDataWarehouseManagedViewsetModalLogic = kea<disableDataWarehouseManagedViewsetModalLogicType>([
    props({ type: 'root' } as DisableDataWarehouseManagedViewsetModalLogicProps),
    key(({ type }) => `disableDataWarehouseManagedViewsetModalLogic-${type}`),
    path((key) => ['scenes', 'data-management', 'managed-viewsets', key]),

    actions({
        openModal: (kind: DataWarehouseManagedViewsetKind) => ({ kind }),
        closeModal: true,
        setIsDeleting: (isDeleting: boolean) => ({ isDeleting }),
        setConfirmationInput: (confirmationInput: string) => ({ confirmationInput }),
    }),
    reducers({
        isOpen: [
            false,
            {
                openModal: () => true,
                closeModal: () => false,
            },
        ],
        kind: [
            null as DataWarehouseManagedViewsetKind | null,
            {
                openModal: (_, { kind }) => kind,
                closeModal: () => null,
            },
        ],
        isDeleting: [
            false,
            {
                setIsDeleting: (_, { isDeleting }) => isDeleting,
                closeModal: () => false,
            },
        ],
        confirmationInput: [
            '',
            {
                openModal: () => '',
                closeModal: () => '',
                setIsDeleting: () => '',
                setConfirmationInput: (_, { confirmationInput }) => confirmationInput,
            },
        ],
    }),
    loaders(() => ({
        views: [
            [] as DataWarehouseManagedViewsetSavedQuery[],
            {
                openModal: async ({ kind }) => {
                    try {
                        const response = await api.dataWarehouseManagedViewsets.getViews(kind)
                        return response.views
                    } catch (error) {
                        console.error('Failed to fetch views:', error)
                        return []
                    }
                },
            },
        ],
    })),
])