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.

1.4 KB
Raw Blame
import {
    ActivityLogItem,
    ActivityLogUserName,
    HumanizedChange,
    activityLogSummary,
    defaultDescriber,
} from 'lib/components/ActivityLog/humanizeActivity'

const STATUS_VERBS: Record<string, string> = {
    accepted: 'accepted',
    dismissed: 'dismissed',
    proposed: 'reopened',
    expired: 'expired',
    auto_resolved: 'resolved',
}

function statusVerb(logItem: ActivityLogItem): string | undefined {
    const statusChange = logItem.detail.changes?.find((change) => change.field === 'status')
    return statusChange ? STATUS_VERBS[String(statusChange.after)] : undefined
}

function assigneeVerb(logItem: ActivityLogItem): string | undefined {
    const assigneeChange = logItem.detail.changes?.find((change) => change.field === 'assignee')
    if (!assigneeChange) {
        return undefined
    }
    return assigneeChange.after ? 'assigned' : 'unassigned'
}

export function warehouseSuggestionActivityDescriber(
    logItem: ActivityLogItem,
    asNotification?: boolean
): HumanizedChange {
    const verb = statusVerb(logItem) ?? assigneeVerb(logItem)
    if (!verb) {
        return defaultDescriber(logItem, asNotification)
    }
    const name = logItem.detail.name ?? 'suggestion'
    return {
        summary: activityLogSummary(logItem, verb, name),
        description: (
            <>
                <ActivityLogUserName logItem={logItem} /> {verb} the <b>{name}</b>
            </>
        ),
    }
}