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.

3.0 KB
Raw Blame
import { useValues } from 'kea'

import { LemonBanner, LemonCollapse } from '@posthog/lemon-ui'

import { LinkedHogFunctions } from 'scenes/hog-functions/list/LinkedHogFunctions'

import { ActionType } from '~/types'

import { actionEditLogic } from '../logics/actionEditLogic'
import { actionLogic } from '../logics/actionLogic'

export function ActionHogFunctions(): JSX.Element | null {
    const { action } = useValues(actionLogic)
    return !action ? null : <Functions action={action} />
}

const Functions = ({ action }: { action: ActionType }): JSX.Element => {
    const { hasCohortFilters, actionChanged, showCohortDisablesFunctionsWarning } = useValues(
        actionEditLogic({ id: action?.id, action })
    )
    return (
        <LemonCollapse
            defaultActiveKey="connected-destinations"
            panels={[
                {
                    key: 'connected-destinations',
                    header: {
                        children: (
                            <div className="py-1">
                                <div className="font-semibold">Connected destinations</div>
                                <div className="text-secondary text-sm font-normal">
                                    Actions can be used as filters for destinations such as Slack or Webhook delivery
                                </div>
                            </div>
                        ),
                    },
                    content: (
                        <div className="@container deprecated-space-y-2">
                            {showCohortDisablesFunctionsWarning ? (
                                <LemonBanner type="error">
                                    Adding a cohort filter will disable all connected destinations!
                                </LemonBanner>
                            ) : null}

                            <LinkedHogFunctions
                                type="destination"
                                forceFilterGroups={[
                                    {
                                        actions: [
                                            {
                                                id: `${action.id}`,
                                                name: action.name,
                                                type: 'actions',
                                            },
                                        ],
                                    },
                                ]}
                                newDisabledReason={
                                    hasCohortFilters
                                        ? "Action with cohort filters can't be used in realtime destinations"
                                        : actionChanged
                                          ? 'Please first save the action to create a destination'
                                          : undefined
                                }
                            />
                        </div>
                    ),
                },
            ]}
        />
    )
}