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): hide the trends click hint when a click cannot open people (#115659)

Paul D'Ambrae9e37438bb45
diff --git a/products/product_analytics/frontend/insights/trends/TrendsBarChart/TrendsBarChart.tsx b/products/product_analytics/frontend/insights/trends/TrendsBarChart/TrendsBarChart.tsx
index d5329e7ae897..437864d8b73f 100644
--- a/products/product_analytics/frontend/insights/trends/TrendsBarChart/TrendsBarChart.tsx
+++ b/products/product_analytics/frontend/insights/trends/TrendsBarChart/TrendsBarChart.tsx
@@ -40,7 +40,11 @@ import { INSIGHT_TOOLTIP_CONFIG } from '../../shared/tooltipConfig'
import { makeChartErrorHandler } from '../shared/chartErrorHandler'
import { getTrendsSeriesDisplayLabel } from '../shared/getTrendsSeriesDisplayLabel'
import { goalLinesToReferenceLines } from '../shared/goalLinesAdapter'
-import { handleTrendsChartClick, type TrendsChartClickDeps } from '../shared/handleTrendsChartClick'
+import {
+ canHandleTrendsChartClick,
+ handleTrendsChartClick,
+ type TrendsChartClickDeps,
+} from '../shared/handleTrendsChartClick'
import { TrendsAlertOverlays } from '../shared/TrendsAlertOverlays'
import { trendsFilterToYFormatterConfig } from '../shared/trendsAxisFormat'
import { buildTrendsSeriesMeta, type TrendsSeriesMeta } from '../shared/trendsSeriesMeta'
@@ -329,7 +333,7 @@ export function TrendsBarChart({
embedded,
])
- const canHandleClick = !!context?.onDataPointClick || !!hasPersonsModal
+ const canHandleClick = canHandleTrendsChartClick({ context, hasPersonsModal, querySource })
const clickDeps = useMemo<TrendsChartClickDeps>(
() => ({
diff --git a/products/product_analytics/frontend/insights/trends/TrendsLifecycleChart/TrendsLifecycleChart.tsx b/products/product_analytics/frontend/insights/trends/TrendsLifecycleChart/TrendsLifecycleChart.tsx
index e4628f70f2f5..ab98d09c5568 100644
--- a/products/product_analytics/frontend/insights/trends/TrendsLifecycleChart/TrendsLifecycleChart.tsx
+++ b/products/product_analytics/frontend/insights/trends/TrendsLifecycleChart/TrendsLifecycleChart.tsx
@@ -27,6 +27,7 @@ import { InsightSeriesTooltip } from '../../shared/InsightSeriesTooltip'
import { buildBaseLegendConfig } from '../shared/buildBaseLegendConfig'
import { makeChartErrorHandler } from '../shared/chartErrorHandler'
import {
+ canHandleTrendsChartClick,
handleTrendsChartClick,
LIFECYCLE_PERSONS_MODAL_OPTIONS,
type TrendsChartClickDeps,
@@ -155,7 +156,7 @@ export function TrendsLifecycleChart({ context, inSharedMode = false }: TrendsLi
)
const config = useChartConfig(() => baseConfig, [baseConfig])
- const canHandleClick = !!context?.onDataPointClick || !!hasPersonsModal
+ const canHandleClick = canHandleTrendsChartClick({ context, hasPersonsModal, querySource })
const clickDeps = useMemo<TrendsChartClickDeps>(
() => ({
diff --git a/products/product_analytics/frontend/insights/trends/TrendsLineChart/TrendsLineChart.tsx b/products/product_analytics/frontend/insights/trends/TrendsLineChart/TrendsLineChart.tsx
index f1c8a4176c64..c0a717a88746 100644
--- a/products/product_analytics/frontend/insights/trends/TrendsLineChart/TrendsLineChart.tsx
+++ b/products/product_analytics/frontend/insights/trends/TrendsLineChart/TrendsLineChart.tsx
@@ -36,7 +36,7 @@ import { getSeriesIdentification } from '../../shared/seriesIdentification'
import { INSIGHT_TOOLTIP_CONFIG } from '../../shared/tooltipConfig'
import { makeChartErrorHandler } from '../shared/chartErrorHandler'
import { getTrendsSeriesDisplayLabel } from '../shared/getTrendsSeriesDisplayLabel'
-import { handleTrendsChartClick } from '../shared/handleTrendsChartClick'
+import { canHandleTrendsChartClick, handleTrendsChartClick } from '../shared/handleTrendsChartClick'
import { TrendsAlertOverlays } from '../shared/TrendsAlertOverlays'
import { buildTrendsSeriesMeta, resolveGroupTypeLabel, type TrendsSeriesMeta } from '../shared/trendsSeriesMeta'
import { useInsightsLegendConfig } from '../shared/useInsightsLegendConfig'
@@ -173,7 +173,7 @@ export function TrendsLineChart({
[trendsFilter, isPercentStackView, baseCurrency]
)
- const canHandleClick = !!context?.onDataPointClick || !!hasPersonsModal
+ const canHandleClick = canHandleTrendsChartClick({ context, hasPersonsModal, querySource })
// The persons modal is intentionally unavailable for multi-series formulas (there's no
// single series of actors behind a computed ratio). On dashboard/card tiles a click
// instead opens the underlying insight, since there's nowhere else for the click to go.
diff --git a/products/product_analytics/frontend/insights/trends/shared/handleTrendsChartClick.test.tsx b/products/product_analytics/frontend/insights/trends/shared/handleTrendsChartClick.test.tsx
index 21c6db3d15c2..aa5574cf8080 100644
--- a/products/product_analytics/frontend/insights/trends/shared/handleTrendsChartClick.test.tsx
+++ b/products/product_analytics/frontend/insights/trends/shared/handleTrendsChartClick.test.tsx
@@ -3,7 +3,7 @@ import { CompareLabelType, EntityTypes } from '~/types'
import type { IndexedTrendResult } from 'products/product_analytics/frontend/insights/trends/types'
-import { handleTrendsChartClick, type TrendsChartClickDeps } from './handleTrendsChartClick'
+import { canHandleTrendsChartClick, handleTrendsChartClick, type TrendsChartClickDeps } from './handleTrendsChartClick'
function makeTrendResult(overrides: Partial<IndexedTrendResult> = {}): IndexedTrendResult {
return {
@@ -238,4 +238,23 @@ describe('handleTrendsChartClick', () => {
expect(openPersonsModal).not.toHaveBeenCalled()
})
+
+ // The charts gate their tooltip click hint on this, so anything it allows the handler above
+ // must act on. A hint that promises a drill-down the handler declines is a dead end.
+ describe('canHandleTrendsChartClick', () => {
+ const querySource = makeDeps().querySource
+
+ it.each([
+ ['the persons modal has a query source', { hasPersonsModal: true, querySource }, true],
+ ['the persons modal has no query source', { hasPersonsModal: true, querySource: null }, false],
+ ['there is no persons modal', { hasPersonsModal: false, querySource }, false],
+ [
+ 'a context callback handles the click instead',
+ { context: { onDataPointClick: jest.fn() }, hasPersonsModal: false, querySource: null },
+ true,
+ ],
+ ])('when %s', (_desc, input, expected) => {
+ expect(canHandleTrendsChartClick(input)).toBe(expected)
+ })
+ })
})
diff --git a/products/product_analytics/frontend/insights/trends/shared/handleTrendsChartClick.tsx b/products/product_analytics/frontend/insights/trends/shared/handleTrendsChartClick.tsx
index 61fc61276b3f..ee444297be00 100644
--- a/products/product_analytics/frontend/insights/trends/shared/handleTrendsChartClick.tsx
+++ b/products/product_analytics/frontend/insights/trends/shared/handleTrendsChartClick.tsx
@@ -41,6 +41,16 @@ export const LIFECYCLE_PERSONS_MODAL_OPTIONS: TrendsPersonsModalOptions = {
orderBy: undefined,
}
+/** The tooltip's click hint and {@link handleTrendsChartClick} must agree on this, or the hint
+ * offers a drill-down the handler then declines: `querySource` is what builds the actors query. */
+export function canHandleTrendsChartClick({
+ context,
+ hasPersonsModal,
+ querySource,
+}: Pick<TrendsChartClickDeps, 'context' | 'querySource'> & { hasPersonsModal?: boolean | null }): boolean {
+ return !!context?.onDataPointClick || (!!hasPersonsModal && !!querySource)
+}
+
// Adapters key each hog-charts Series by `${r.id}`, so we can resolve back
// to the source IndexedTrendResult without stashing it on meta.
export function resolveDataset(seriesKey: string, indexedResults: IndexedTrendResult[]): IndexedTrendResult | null {