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.3 KB
Raw Blame
import { useValues } from 'kea'

import { IconWarning } from '@posthog/icons'
import { Tooltip } from '@posthog/lemon-ui'

import { pluralize } from 'lib/utils/strings'

import { dataQualityChecksLogic } from 'products/data_quality/frontend/dataQualityChecksLogic'

import type { NodeDetailTestsSubjectType } from './NodeDetailTests'

/** Erroring means a check could not run at all, so it reports no failure count to speak of. */
const TONES: Record<string, string> = {
    failing: 'text-danger',
    warn: 'text-warning',
    erroring: 'text-warning',
}

export function NodeDetailTestsTabLabel({
    subjectType,
    subjectId,
}: {
    subjectType: NodeDetailTestsSubjectType
    subjectId: string
}): JSX.Element {
    const { health } = useValues(dataQualityChecksLogic({ subjectType, subjectId }))
    const tone = health ? TONES[health.health] : undefined
    const explanation =
        health?.health === 'erroring'
            ? 'A check could not run'
            : `${pluralize(health?.checks_failing ?? 0, 'check')} failing`

    return (
        <span className="flex items-center gap-1">
            Data quality
            {tone && (
                <Tooltip title={explanation}>
                    <IconWarning className={tone} />
                </Tooltip>
            )}
        </span>
    )
}