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.

5.5 KB
Raw Blame
import { MakeLogicType, connect, kea, path, props } from 'kea'
import { forms } from 'kea-forms'
import type { DeepPartial, DeepPartialMap, FieldName, ValidationErrorType } from 'kea-forms'

import api from 'lib/api'
import { integrationsLogic } from 'lib/integrations/integrationsLogic'
import { lemonToast } from 'lib/lemon-ui/LemonToast'

import { IntegrationType } from '~/types'

export interface DatabricksSetupModalLogicProps {
    isOpen: boolean
    integration?: IntegrationType | null
    onComplete: (integrationId?: number) => void
}

// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface databricksSetupModalLogicValues {
    databricksIntegration: {
        clientId: string
        clientSecret: string
        serverHostname: string
    }
    databricksIntegrationAllErrors: Record<string, any>
    databricksIntegrationChanged: boolean
    databricksIntegrationErrors: DeepPartialMap<
        {
            clientId: string
            clientSecret: string
            serverHostname: string
        },
        ValidationErrorType
    >
    databricksIntegrationHasErrors: boolean
    databricksIntegrationManualErrors: Record<string, any>
    databricksIntegrationTouched: boolean
    databricksIntegrationTouches: Record<string, boolean>
    databricksIntegrationValidationErrors: DeepPartialMap<
        {
            clientId: string
            clientSecret: string
            serverHostname: string
        },
        ValidationErrorType
    >
    isDatabricksIntegrationSubmitting: boolean
    isDatabricksIntegrationValid: boolean
    showDatabricksIntegrationErrors: boolean
}

// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface databricksSetupModalLogicActions {
    loadIntegrations: (_?: any) => any // integrationsLogic
    resetDatabricksIntegration: (values?: { clientId: string; clientSecret: string; serverHostname: string }) => {
        values?: {
            clientId: string
            clientSecret: string
            serverHostname: string
        }
    }
    setDatabricksIntegrationManualErrors: (errors: Record<string, any>) => {
        errors: Record<string, any>
    }
    setDatabricksIntegrationValue: (
        key: FieldName,
        value: any
    ) => {
        name: FieldName
        value: any
    }
    setDatabricksIntegrationValues: (
        values: DeepPartial<{
            clientId: string
            clientSecret: string
            serverHostname: string
        }>
    ) => {
        values: DeepPartial<{
            clientId: string
            clientSecret: string
            serverHostname: string
        }>
    }
    submitDatabricksIntegration: () => {
        value: boolean
    }
    submitDatabricksIntegrationFailure: (
        error: Error,
        errors: Record<string, any>
    ) => {
        error: Error
        errors: Record<string, any>
    }
    submitDatabricksIntegrationRequest: (databricksIntegration: {
        clientId: string
        clientSecret: string
        serverHostname: string
    }) => {
        databricksIntegration: {
            clientId: string
            clientSecret: string
            serverHostname: string
        }
    }
    submitDatabricksIntegrationSuccess: (databricksIntegration: {
        clientId: string
        clientSecret: string
        serverHostname: string
    }) => {
        databricksIntegration: {
            clientId: string
            clientSecret: string
            serverHostname: string
        }
    }
    touchDatabricksIntegrationField: (key: string) => {
        key: string
    }
}

export type databricksSetupModalLogicType = MakeLogicType<
    databricksSetupModalLogicValues,
    databricksSetupModalLogicActions,
    DatabricksSetupModalLogicProps
>

export const databricksSetupModalLogic = kea<databricksSetupModalLogicType>([
    path(['integrations', 'databricks', 'databricksSetupModalLogic']),
    props({} as DatabricksSetupModalLogicProps),
    connect(() => ({
        actions: [integrationsLogic, ['loadIntegrations']],
    })),
    forms(({ props, actions, values }) => ({
        databricksIntegration: {
            defaults: {
                serverHostname: '',
                clientId: '',
                clientSecret: '',
            },
            errors: ({ serverHostname, clientId, clientSecret }) => ({
                serverHostname: serverHostname.trim() ? undefined : 'Server Hostname is required',
                clientId: clientId.trim() ? undefined : 'Client ID is required',
                clientSecret: clientSecret.trim() ? undefined : 'Client Secret is required',
            }),
            submit: async () => {
                try {
                    const integration = await api.integrations.create({
                        kind: 'databricks',
                        config: {
                            server_hostname: values.databricksIntegration.serverHostname,
                            client_id: values.databricksIntegration.clientId,
                            client_secret: values.databricksIntegration.clientSecret,
                        },
                    })
                    actions.loadIntegrations()
                    lemonToast.success('Databricks integration created successfully!')
                    props.onComplete(integration.id)
                } catch (error: any) {
                    lemonToast.error(error.detail || 'Failed to create Databricks integration')
                    throw error
                }
            },
        },
    })),
])