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.

perf(signals): mount one tooltip per scout run strip on hover (#127230)

Shy Alterefe9018b2c5e
diff --git a/products/signals/frontend/inbox/components/config/scouts/ScoutRunBoxes.test.tsx b/products/signals/frontend/inbox/components/config/scouts/ScoutRunBoxes.test.tsx
index 2ecfda3530a2..0fa88ca48979 100644
--- a/products/signals/frontend/inbox/components/config/scouts/ScoutRunBoxes.test.tsx
+++ b/products/signals/frontend/inbox/components/config/scouts/ScoutRunBoxes.test.tsx
@@ -1,6 +1,6 @@
import '@testing-library/jest-dom'
-import { cleanup, render } from '@testing-library/react'
+import { act, cleanup, fireEvent, render } from '@testing-library/react'
import { SignalScoutRunSummary } from '../../../types'
import { ScoutRunBoxes } from './ScoutRunBoxes'
@@ -103,6 +103,45 @@ describe('ScoutRunBoxes', () => {
expect(strip.querySelectorAll('*')).toHaveLength(runs.length * 2)
})
+ it('shows the hovered run in one tooltip, and closes it on Escape or when the pointer leaves the box', () => {
+ jest.useFakeTimers()
+ try {
+ const { container } = render(
+ <ScoutRunBoxes
+ runs={[
+ makeRun({ run_id: 'run-plain', status: 'failed' }),
+ makeRun({ run_id: 'run-linked', task_url: '/project/2/tasks/run-linked' }),
+ ]}
+ />
+ )
+ expect(document.querySelector('.Tooltip')).toBeNull()
+
+ fireEvent.mouseOver(container.querySelector('[data-run-id="run-linked"]') as Element)
+ act(() => {
+ jest.advanceTimersByTime(400)
+ })
+
+ const tooltips = document.querySelectorAll('.Tooltip')
+ expect(tooltips).toHaveLength(1)
+ expect(tooltips[0]).toHaveTextContent('open task run')
+
+ fireEvent.keyDown(document, { key: 'Escape' })
+ act(() => {
+ jest.advanceTimersByTime(400)
+ })
+ expect(document.querySelector('.Tooltip')).toBeNull()
+
+ fireEvent.mouseOver(container.querySelector('[data-run-id="run-plain"]') as Element)
+ fireEvent.mouseOver(container.firstElementChild as Element)
+ act(() => {
+ jest.advanceTimersByTime(400)
+ })
+ expect(document.querySelector('.Tooltip')).toBeNull()
+ } finally {
+ jest.useRealTimers()
+ }
+ })
+
it('marks nothing while the fleet has too few priced runs to rank', () => {
const { container } = render(
<ScoutRunBoxes runs={[makeRun()]} costs={new Map([['run-1', 3.19]])} costThreshold={null} />
diff --git a/products/signals/frontend/inbox/components/config/scouts/ScoutRunBoxes.tsx b/products/signals/frontend/inbox/components/config/scouts/ScoutRunBoxes.tsx
index 1b21c22a1f03..91173b47f25b 100644
--- a/products/signals/frontend/inbox/components/config/scouts/ScoutRunBoxes.tsx
+++ b/products/signals/frontend/inbox/components/config/scouts/ScoutRunBoxes.tsx
@@ -1,4 +1,4 @@
-import { memo, useMemo } from 'react'
+import { memo, MouseEvent, FocusEvent, useEffect, useMemo, useRef, useState } from 'react'
import { Link, Tooltip } from '@posthog/lemon-ui'
@@ -31,13 +31,19 @@ const OUTCOME_BOX_CLASS: Record<ScoutRunOutcome, string> = {
}
const MAX_BOXES = 24
+const TOOLTIP_DELAY_MS = 400
const BOX_CLASS = 'block h-3 w-2 shrink-0 rounded-[2px] transition-transform duration-100 hover:scale-y-125'
// A box column always keeps the marker's height, priced or not, so the strip does not jump a few
// pixels when the costs land a moment after the runs.
const COLUMN_CLASS = 'flex h-4 w-2 shrink-0 flex-col items-center justify-end gap-px'
const MARKER_CLASS = 'block h-[3px] w-2 rounded-[1px] bg-brand-yellow'
-function runTooltip(run: SignalScoutRunSummary, now: Date, costUsd: number | undefined, expensive: boolean): string {
+function runDescription(
+ run: SignalScoutRunSummary,
+ now: Date,
+ costUsd: number | undefined,
+ expensive: boolean
+): string {
const parts = [scoutRunOutcomeLabel(run, now)]
const duration = formatRunDuration(runDurationSeconds(run, now))
if (duration) {
@@ -56,9 +62,35 @@ function runTooltip(run: SignalScoutRunSummary, now: Date, costUsd: number | und
if (expensive) {
parts.push('top 10% of runs by cost')
}
+ if (run.task_url) {
+ parts.push('open task run')
+ }
return parts.join(' · ')
}
+interface ActiveBox {
+ runId: string
+ left: number
+ top: number
+ width: number
+ height: number
+}
+
+function columnOf(target: EventTarget, strip: HTMLElement): HTMLElement | null {
+ const column = target instanceof Element ? target.closest<HTMLElement>('[data-run-id]') : null
+ return column && strip.contains(column) ? column : null
+}
+
+function activeBoxOf(column: HTMLElement): ActiveBox {
+ return {
+ runId: column.dataset.runId ?? '',
+ left: column.offsetLeft,
+ top: column.offsetTop,
+ width: column.offsetWidth,
+ height: column.offsetHeight,
+ }
+}
+
/**
* One small box per run in the visible window, oldest on the left. Each box
* links out to cloud's Tasks UI via the run's relative `task_url`; runs without
@@ -91,10 +123,47 @@ export const ScoutRunBoxes = memo(function ScoutRunBoxes({
run,
outcome: deriveRunOutcome(run, now),
expensive,
- tooltip: runTooltip(run, now, costUsd, expensive),
+ description: runDescription(run, now, costUsd, expensive),
}
})
}, [runs, costs, costThreshold])
+ const [activeBox, setActiveBox] = useState<ActiveBox | null>(null)
+ const hoverTimer = useRef<ReturnType<typeof setTimeout> | null>(null)
+ const pendingRunId = useRef<string | null>(null)
+ const isOpen = activeBox !== null
+
+ const clearHoverTimer = (): void => {
+ if (hoverTimer.current !== null) {
+ clearTimeout(hoverTimer.current)
+ hoverTimer.current = null
+ }
+ pendingRunId.current = null
+ }
+
+ const close = (): void => {
+ clearHoverTimer()
+ setActiveBox(null)
+ }
+
+ useEffect(() => clearHoverTimer, [])
+
+ useEffect(() => {
+ if (!isOpen) {
+ return
+ }
+ const dismiss = (): void => setActiveBox(null)
+ const onKeyDown = (event: KeyboardEvent): void => {
+ if (event.key === 'Escape') {
+ dismiss()
+ }
+ }
+ window.addEventListener('scroll', dismiss, { capture: true, passive: true })
+ document.addEventListener('keydown', onKeyDown)
+ return () => {
+ window.removeEventListener('scroll', dismiss, { capture: true })
+ document.removeEventListener('keydown', onKeyDown)
+ }
+ }, [isOpen])
if (runs.length === 0) {
return null
@@ -104,19 +173,56 @@ export const ScoutRunBoxes = memo(function ScoutRunBoxes({
// Newest first so flex-row-reverse renders them right-to-left; the oldest
// runs (and the +N marker) sit at the left edge and clip away first.
const newestFirst = visible.slice().reverse()
+ const activeEntry = activeBox ? visible.find(({ run }) => run.run_id === activeBox.runId) : undefined
+
+ const onMouseOver = (event: MouseEvent<HTMLDivElement>): void => {
+ const column = columnOf(event.target, event.currentTarget)
+ if (!column) {
+ close()
+ return
+ }
+ const runId = column.dataset.runId
+ if (runId === activeBox?.runId || runId === pendingRunId.current) {
+ return
+ }
+ clearHoverTimer()
+ if (activeBox) {
+ setActiveBox(activeBoxOf(column))
+ return
+ }
+ pendingRunId.current = runId ?? null
+ hoverTimer.current = setTimeout(() => {
+ pendingRunId.current = null
+ hoverTimer.current = null
+ setActiveBox(activeBoxOf(column))
+ }, TOOLTIP_DELAY_MS)
+ }
+
+ const onFocus = (event: FocusEvent<HTMLDivElement>): void => {
+ const column = columnOf(event.target, event.currentTarget)
+ if (column) {
+ clearHoverTimer()
+ setActiveBox(activeBoxOf(column))
+ }
+ }
return (
- <div className="flex flex-row-reverse items-center gap-1 min-w-0 overflow-hidden">
- {newestFirst.map(({ run, outcome, expensive, tooltip }) => {
+ <div
+ className="relative flex flex-row-reverse items-center gap-1 min-w-0 overflow-hidden"
+ onMouseOver={onMouseOver}
+ onMouseLeave={close}
+ onFocus={onFocus}
+ onBlur={close}
+ onClick={close}
+ >
+ {newestFirst.map(({ run, outcome, expensive, description }) => {
const boxClass = `${BOX_CLASS} ${OUTCOME_BOX_CLASS[outcome]}`
- const boxTooltip = run.task_url ? `${tooltip} · open task run` : tooltip
// The label is an attribute, not an `sr-only` child: the roster renders a strip per
// scout, so one more node per box adds thousands of nodes to a large fleet.
- const label = `Run ${boxTooltip}`
const column = (
<>
{expensive ? <span className={MARKER_CLASS} /> : null}
- <span className={boxClass} role="img" aria-label={label} />
+ <span className={boxClass} role="img" aria-label={`Run ${description}`} />
</>
)
// The whole column links, not only the box, because the tooltip spans the column
@@ -124,19 +230,31 @@ export const ScoutRunBoxes = memo(function ScoutRunBoxes({
// navigate there: the roster card holds no handler above the box, and the roster
// table's row handler pushes the scout page for every click that is not inside an
// `a` or `button`.
- return (
- <Tooltip key={run.run_id} title={boxTooltip}>
- {run.task_url ? (
- <Link to={run.task_url} className={COLUMN_CLASS}>
- {column}
- </Link>
- ) : (
- <span className={COLUMN_CLASS}>{column}</span>
- )}
- </Tooltip>
+ return run.task_url ? (
+ <Link key={run.run_id} to={run.task_url} className={COLUMN_CLASS} data-run-id={run.run_id}>
+ {column}
+ </Link>
+ ) : (
+ <span key={run.run_id} className={COLUMN_CLASS} data-run-id={run.run_id}>
+ {column}
+ </span>
)
})}
{hidden > 0 ? <span className="shrink-0 text-[10px] text-muted">+{hidden}</span> : null}
+ {activeBox && activeEntry ? (
+ <Tooltip visible title={activeEntry.description}>
+ <span
+ aria-hidden
+ className="pointer-events-none absolute"
+ style={{
+ left: activeBox.left,
+ top: activeBox.top,
+ width: activeBox.width,
+ height: activeBox.height,
+ }}
+ />
+ </Tooltip>
+ ) : null}
</div>
)
})