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.0 KB
Raw Blame
import {
    ActivityLogItem,
    ActivityLogUserName,
    HumanizedChange,
    activityLogSummary,
    defaultDescriber,
} from 'lib/components/ActivityLog/humanizeActivity'

const getDisplayName = (logItem: ActivityLogItem): string => {
    const name = logItem?.detail?.name
    if (name) {
        return name
    }

    const context = logItem?.detail?.context as any
    if (context?.source_type && context?.content_type) {
        return `source ${context.source_type} (${context.content_type})`
    }

    const detail = logItem?.detail as any
    const config = detail?.import_config
    if (config?.source?.type) {
        return `source ${config.source.type}`
    }

    return 'unknown source'
}

export function batchImportActivityDescriber(logItem: ActivityLogItem, asNotification?: boolean): HumanizedChange {
    if (logItem.activity == 'created') {
        return {
            summary: activityLogSummary(logItem, 'Created the import', getDisplayName(logItem)),
            description: (
                <>
                    <ActivityLogUserName logItem={logItem} /> created <strong>{getDisplayName(logItem)}</strong>
                </>
            ),
        }
    }

    if (logItem.activity == 'deleted') {
        return {
            summary: activityLogSummary(logItem, 'Deleted the import', getDisplayName(logItem)),
            description: (
                <>
                    <ActivityLogUserName logItem={logItem} /> deleted <strong>{getDisplayName(logItem)}</strong>
                </>
            ),
        }
    }

    if (logItem.activity == 'updated') {
        return {
            summary: activityLogSummary(logItem, 'Updated the import', getDisplayName(logItem)),
            description: (
                <>
                    <ActivityLogUserName logItem={logItem} /> updated <strong>{getDisplayName(logItem)}</strong>
                </>
            ),
        }
    }

    return defaultDescriber(logItem, asNotification, getDisplayName(logItem))
}