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.

fix(insights): explain and fall back for disabled drill-down on formula trend charts (#76517)

posthog[bot]1566441d9ca1
diff --git a/frontend/src/scenes/trends/Trends.tsx b/frontend/src/scenes/trends/Trends.tsx
index 3b22eccb5042..e3f1e6ad4abe 100644
--- a/frontend/src/scenes/trends/Trends.tsx
+++ b/frontend/src/scenes/trends/Trends.tsx
@@ -154,7 +154,7 @@ export function TrendInsight({ view, context, embedded, inSharedMode, editMode }
if (isStickiness) {
return <StickinessLineChart context={context} />
}
- return <TrendsLineChart context={context} inSharedMode={inSharedMode} />
+ return <TrendsLineChart context={context} inSharedMode={inSharedMode} embedded={embedded} />
}
return (
diff --git a/products/product_analytics/frontend/insights/shared/InsightSeriesTooltip.tsx b/products/product_analytics/frontend/insights/shared/InsightSeriesTooltip.tsx
index 4e2957a3e432..b34ebf8eedc8 100644
--- a/products/product_analytics/frontend/insights/shared/InsightSeriesTooltip.tsx
+++ b/products/product_analytics/frontend/insights/shared/InsightSeriesTooltip.tsx
@@ -57,6 +57,8 @@ export interface InsightSeriesTooltipProps<Meta extends InsightSeriesMetaBase> {
sortedByValue?: boolean
/** Hide rows whose value is exactly 0 (e.g. absent lifecycle statuses). */
hideZeroRows?: boolean
+ /** Override the default "click to view X" footer — e.g. to explain why drill-down is unavailable. */
+ footerOverride?: React.ReactNode
}
// ── Pure helpers ───────────────────────────────────────────────────────────
@@ -172,6 +174,7 @@ export function InsightSeriesTooltip<Meta extends InsightSeriesMetaBase>({
renderSeriesOverride,
sortedByValue = true,
hideZeroRows,
+ footerOverride,
}: InsightSeriesTooltipProps<Meta>): React.ReactElement {
const { formatPropertyValueForDisplay } = useValues(propertyDefinitionsModel)
const { weekStartDay } = useValues(teamLogic)
@@ -290,11 +293,12 @@ export function InsightSeriesTooltip<Meta extends InsightSeriesMetaBase>({
valueFormatter={valueFormatter}
onRowClick={onRowClick ? onRowClickEntry : undefined}
footer={
- onRowClick
+ footerOverride ??
+ (onRowClick
? context.seriesData.length > 1
? `Click a series to view ${groupTypeLabel}`
: `Click to view ${groupTypeLabel}`
- : undefined
+ : undefined)
}
/>
)
diff --git a/products/product_analytics/frontend/insights/trends/TrendsLineChart/TrendsLineChart.test.tsx b/products/product_analytics/frontend/insights/trends/TrendsLineChart/TrendsLineChart.test.tsx
index bd75a6ed1351..57da4ede1b26 100644
--- a/products/product_analytics/frontend/insights/trends/TrendsLineChart/TrendsLineChart.test.tsx
+++ b/products/product_analytics/frontend/insights/trends/TrendsLineChart/TrendsLineChart.test.tsx
@@ -1,13 +1,17 @@
import '@testing-library/jest-dom'
import { cleanup, configure, screen, waitFor } from '@testing-library/react'
+import { router } from 'kea-router'
import { dimensions, dragSelection, rawDrag, setupJsdom, setupSyncRaf } from '@posthog/quill-charts/testing'
import { FEATURE_FLAGS } from 'lib/constants'
+import { removeProjectIdIfPresent } from 'lib/utils/kea-router'
+import { urls } from 'scenes/urls'
import { ExportType } from '~/exporter/types'
-import { NodeKind } from '~/queries/schema/schema-general'
+import { InsightVizNode, NodeKind } from '~/queries/schema/schema-general'
+import { QueryContext } from '~/queries/types'
import {
buildTrendsQuery,
chart,
@@ -20,7 +24,7 @@ import {
trendsSeries,
} from '~/test/insight-testing'
import { buildAnnotation } from '~/test/insight-testing/test-data'
-import { AnnotationScope, ChartDisplayType } from '~/types'
+import { AnnotationScope, ChartDisplayType, InsightShortId } from '~/types'
// The full InsightViz tree is heavy to mount under jsdom; on contended CI shards
// the default 1s waitFor / findBy timeout is too tight and flakes randomly.
@@ -632,6 +636,77 @@ describe('TrendsLineChart', () => {
})
})
+ describe('formula insights with drill-down disabled', () => {
+ const multiSeriesFormulaQuery = buildTrendsQuery({
+ series: [
+ { kind: NodeKind.EventsNode, event: '$pageview', name: '$pageview' },
+ { kind: NodeKind.EventsNode, event: 'Napped', name: 'Napped' },
+ ],
+ trendsFilter: { formula: 'A/B' },
+ })
+
+ /** Mirrors how InsightCard hands a dashboard tile's real short_id and query down through
+ * `context.insightProps.cachedInsight` (see InsightCard.tsx / InsightMeta.tsx). */
+ const dashboardTileContext = (shortId: InsightShortId): QueryContext<InsightVizNode> => ({
+ insightProps: {
+ dashboardItemId: shortId,
+ dashboardId: 42,
+ cachedInsight: {
+ short_id: shortId,
+ query: { kind: NodeKind.InsightVizNode, source: multiSeriesFormulaQuery } as InsightVizNode,
+ },
+ },
+ })
+
+ it('explains why drill-down is unavailable instead of opening the persons modal', async () => {
+ renderInsight({ query: multiSeriesFormulaQuery })
+
+ await chart.hoverTooltip(2)
+
+ expect(chart.getTooltip()?.textContent).toContain("Drill-down isn't available for formula insights")
+ await chart.clickTooltipRow('Pageview')
+ expect(personsModal.get()).not.toBeInTheDocument()
+ })
+
+ it('navigates to the insight on click when rendered as a dashboard/card tile', async () => {
+ const shortId = 'formula-insight-1' as InsightShortId
+ renderInsight({
+ query: multiSeriesFormulaQuery,
+ embedded: true,
+ context: dashboardTileContext(shortId),
+ })
+
+ await chart.hoverTooltip(2)
+ expect(chart.getTooltip()?.textContent).toContain(
+ "Drill-down isn't available for formula insights. Click to view the insight."
+ )
+
+ await chart.clickTooltipRow('Pageview')
+
+ await waitFor(() => {
+ const path = removeProjectIdIfPresent(router.values.location.pathname) + router.values.location.search
+ expect(path).toEqual(urls.insightView(shortId, 42))
+ })
+ expect(personsModal.get()).not.toBeInTheDocument()
+ })
+
+ it('does not navigate on click when rendered in shared mode', async () => {
+ const shortId = 'formula-insight-2' as InsightShortId
+ renderInsight({
+ query: multiSeriesFormulaQuery,
+ embedded: true,
+ inSharedMode: true,
+ context: dashboardTileContext(shortId),
+ })
+ const pathnameBeforeClick = router.values.location.pathname
+
+ await chart.hoverTooltip(2)
+ await chart.clickTooltipRow('Pageview')
+
+ expect(router.values.location.pathname).toEqual(pathnameBeforeClick)
+ })
+ })
+
describe('quill in-chart legend', () => {
const twoSeriesQuery = buildTrendsQuery({
series: [
diff --git a/products/product_analytics/frontend/insights/trends/TrendsLineChart/TrendsLineChart.tsx b/products/product_analytics/frontend/insights/trends/TrendsLineChart/TrendsLineChart.tsx
index c0292edcb222..c16e53f81c52 100644
--- a/products/product_analytics/frontend/insights/trends/TrendsLineChart/TrendsLineChart.tsx
+++ b/products/product_analytics/frontend/insights/trends/TrendsLineChart/TrendsLineChart.tsx
@@ -1,4 +1,5 @@
import { useValues } from 'kea'
+import { router } from 'kea-router'
import { useCallback, useMemo } from 'react'
import { DEFAULT_Y_AXIS_ID, TimeSeriesLineChart } from '@posthog/quill-charts'
@@ -7,6 +8,7 @@ import type { PointClickData, TooltipContext } from '@posthog/quill-charts'
import { useChartTheme, useChartConfig, useDateRangeZoom } from 'lib/charts/hooks'
import { ciRanges } from 'lib/statistics'
import { percentage } from 'lib/utils/numbers'
+import { isMultiSeriesFormula } from 'lib/utils/strings'
import { formatAggregationAxisValue } from 'scenes/insights/aggregationAxisFormat'
import { InsightEmptyState } from 'scenes/insights/EmptyStates'
import { insightLogic } from 'scenes/insights/insightLogic'
@@ -15,6 +17,7 @@ import { teamLogic } from 'scenes/teamLogic'
import { openPersonsModal } from 'scenes/trends/persons-modal/PersonsModal'
import { trendsDataLogic } from 'scenes/trends/trendsDataLogic'
import type { IndexedTrendResult } from 'scenes/trends/types'
+import { urls } from 'scenes/urls'
import { cohortsModel } from '~/models/cohortsModel'
import { groupsModel } from '~/models/groupsModel'
@@ -38,11 +41,16 @@ import { buildTrendsLineTimeSeriesConfig, buildTrendsSeries } from './trendsChar
interface TrendsLineChartProps {
context?: QueryContext<InsightVizNode>
inSharedMode?: boolean
+ embedded?: boolean
}
const handleChartError = makeChartErrorHandler('trends-line-chart')
-export function TrendsLineChart({ context, inSharedMode = false }: TrendsLineChartProps): JSX.Element | null {
+export function TrendsLineChart({
+ context,
+ inSharedMode = false,
+ embedded = false,
+}: TrendsLineChartProps): JSX.Element | null {
const theme = useChartTheme()
const { insightProps, insight } = useValues(insightLogic)
@@ -128,6 +136,26 @@ export function TrendsLineChart({ context, inSharedMode = false }: TrendsLineCha
)
const canHandleClick = !!context?.onDataPointClick || !!hasPersonsModal
+ // The persons modal is intentionally unavailable for multi-series formulas (there's no
+ // single series of actors behind a computed ratio), so surface that instead of leaving
+ // the chart looking interactive with no explanation. On dashboard/card tiles a click
+ // instead opens the underlying insight, since there's nowhere else for the click to go.
+ const isFormulaDrillDownDisabled = !canHandleClick && isMultiSeriesFormula(formula)
+ const canNavigateToInsight = embedded && !inSharedMode && isFormulaDrillDownDisabled && !!insight.short_id
+ const canHandlePointInteraction = canHandleClick || canNavigateToInsight
+
+ const navigateToInsight = useCallback(() => {
+ if (!insight.short_id) {
+ return
+ }
+ router.actions.push(urls.insightView(insight.short_id, insightProps.dashboardId))
+ }, [insight.short_id, insightProps.dashboardId])
+
+ const noDrillDownFooter = isFormulaDrillDownDisabled
+ ? canNavigateToInsight
+ ? "Drill-down isn't available for formula insights. Click to view the insight."
+ : "Drill-down isn't available for formula insights"
+ : undefined
const clickDeps = useMemo(
() => ({
@@ -155,19 +183,27 @@ export function TrendsLineChart({ context, inSharedMode = false }: TrendsLineCha
const onPointClick = useCallback(
(clickData: PointClickData) => {
- handleTrendsChartClick(clickData.series.key, clickData.dataIndex, clickDeps)
+ if (canHandleClick) {
+ handleTrendsChartClick(clickData.series.key, clickData.dataIndex, clickDeps)
+ } else if (canNavigateToInsight) {
+ navigateToInsight()
+ }
},
- [clickDeps]
+ [canHandleClick, canNavigateToInsight, clickDeps, navigateToInsight]
)
const onDateRangeZoom = useDateRangeZoom(currentPeriodResult?.days, context?.onDateRangeZoom)
const renderTooltip = useCallback(
(ctx: TooltipContext<TrendsSeriesMeta>) => {
- const onRowClick = canHandleClick
+ const onRowClick = canHandlePointInteraction
? (datum: SeriesDatum) => {
- const seriesKey = ctx.seriesData[datum.datasetIndex].series.key
- handleTrendsChartClick(seriesKey, datum.dataIndex, clickDeps)
+ if (canHandleClick) {
+ const seriesKey = ctx.seriesData[datum.datasetIndex].series.key
+ handleTrendsChartClick(seriesKey, datum.dataIndex, clickDeps)
+ } else {
+ navigateToInsight()
+ }
}
: undefined
const tooltipProps = {
@@ -184,6 +220,7 @@ export function TrendsLineChart({ context, inSharedMode = false }: TrendsLineCha
groupTypeLabel: resolvedGroupTypeLabel,
formatCompareLabel: context?.formatCompareLabel,
onRowClick,
+ footerOverride: noDrillDownFooter,
}
return <InsightSeriesTooltip {...tooltipProps} />
},
@@ -199,7 +236,10 @@ export function TrendsLineChart({ context, inSharedMode = false }: TrendsLineCha
baseCurrency,
resolvedGroupTypeLabel,
context?.formatCompareLabel,
+ canHandlePointInteraction,
canHandleClick,
+ navigateToInsight,
+ noDrillDownFooter,
clickDeps,
]
)
@@ -304,7 +344,7 @@ export function TrendsLineChart({ context, inSharedMode = false }: TrendsLineCha
theme={theme}
config={config}
tooltip={renderTooltip}
- onPointClick={canHandleClick ? onPointClick : undefined}
+ onPointClick={canHandlePointInteraction ? onPointClick : undefined}
onDateRangeZoom={onDateRangeZoom}
className="LineGraph"
dataAttr="trend-line-graph"