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.1 KB
Raw Blame
import { useActions, useValues } from 'kea'
import { useEffect } from 'react'

import { IconWarning } from '@posthog/icons'
import { Progress, Spinner } from '@posthog/quill'

import { DISPLAY_PHASES } from '../observations/observationProgress'
import { observationProgressLogic } from '../observations/observationProgressLogic'

export function QuillObservationProgressBar({
    observationId,
    sessionId,
}: {
    observationId: string
    sessionId: string
}): JSX.Element {
    const logic = observationProgressLogic({ observationId, sessionId })
    const { percent, displayPhase, stepNumber, frames, streamError } = useValues(logic)
    const { startStream } = useActions(logic)

    useEffect(() => {
        startStream()
    }, [observationId, startStream])

    if (streamError) {
        // The stream died but the observation may still be running; status polling keeps the page truthful.
        return (
            <div className="flex items-center gap-2 text-muted-foreground text-sm">
                <IconWarning className="text-warning text-base shrink-0" />
                <span>Live progress isn't available. This updates when the observation finishes.</span>
            </div>
        )
    }

    return (
        <div className="flex flex-col gap-1.5">
            <div className="flex items-center gap-2 text-muted-foreground text-sm">
                <Spinner />
                <span className="min-w-0 truncate">{displayPhase.label}…</span>
            </div>
            <Progress value={percent} />
            {/* Ticking numbers skip page translation, which would otherwise freeze them and crash React on removal (react#11538). */}
            <div className="flex items-center justify-between gap-2 text-muted-foreground text-xs" translate="no">
                <span>
                    Step {stepNumber} of {DISPLAY_PHASES.length}
                </span>
                {frames && (
                    <span>
                        {frames.frame.toLocaleString()} / {frames.estimatedTotalFrames.toLocaleString()} frames
                    </span>
                )}
            </div>
        </div>
    )
}