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.6 KB
Raw Blame
import { Tooltip } from '@posthog/lemon-ui'

import type { WarehouseSuggestionEvidenceApi } from '../generated/api.schemas'
import { daysReadLabel, surfaceSegments } from '../suggestionCopy'
import { ReadsBySurfaceBar } from './ReadsBySurfaceBar'

export interface WhyThisSuggestionProps {
    evidence: WarehouseSuggestionEvidenceApi
    windowDays: number
    label: string
}

export function WhyThisSuggestion({ evidence, windowDays, label }: WhyThisSuggestionProps): JSX.Element {
    const segments = surfaceSegments(evidence)
    const daysRead = (evidence.human_days ?? 0) > 0 ? daysReadLabel(evidence, windowDays) : null

    if (segments.length === 0 && !daysRead) {
        return <span translate="no">{label}</span>
    }

    return (
        <Tooltip
            title={
                <div className="flex w-64 max-w-full flex-col gap-2 py-0.5">
                    {segments.length > 0 && <ReadsBySurfaceBar segments={segments} />}
                    {daysRead && <span>{daysRead}</span>}
                </div>
            }
        >
            <span
                tabIndex={0}
                className="cursor-help underline decoration-dotted underline-offset-2"
                data-attr="warehouse-suggestions-why-this"
            >
                <span translate="no">{label}</span>
                <span className="sr-only">
                    {[segments.map((segment) => `${segment.label} ${segment.count}`).join(', '), daysRead]
                        .filter(Boolean)
                        .map((part) => `. ${part}`)
                        .join('')}
                </span>
            </span>
        </Tooltip>
    )
}