: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(insights): reload results when switching to or from a metric (#102846)
Sam Pennington42a3570529c9
diff --git a/frontend/src/scenes/insights/utils/queryUtils.test.ts b/frontend/src/scenes/insights/utils/queryUtils.test.tsindex b8f7ed03da46..318678305d4c 100644--- a/frontend/src/scenes/insights/utils/queryUtils.test.ts+++ b/frontend/src/scenes/insights/utils/queryUtils.test.ts@@ -1,6 +1,6 @@import { getDefaultQuery } from '~/queries/nodes/InsightViz/utils'import { Node, NodeKind, TrendsFilter, TrendsQuery } from '~/queries/schema/schema-general'-import { InsightType } from '~/types'+import { ChartDisplayType, InsightType } from '~/types'import {compareDataNodeQuery,@@ -237,6 +237,17 @@ describe('compareQuery', () => {expect(compareQuery(plain, styled, { ignoreVisualizationOnlyChanges: true })).toBe(true)expect(compareQuery(plain, styled)).toBe(false)})++ it.each([+ ['reuses the result between a line chart and a bar chart', ChartDisplayType.ActionsBar, true],+ ['reloads between a line chart and a metric', ChartDisplayType.Metric, false],+ ])('%s', (_, display, expected) => {+ const line = makeTrendsQuery({ display: ChartDisplayType.ActionsLineGraph })++ expect(compareQuery(line, makeTrendsQuery({ display }), { ignoreVisualizationOnlyChanges: true })).toBe(+ expected+ )+ })})describe('isDraftQueryWorthSaving', () => {diff --git a/frontend/src/scenes/insights/utils/queryUtils.ts b/frontend/src/scenes/insights/utils/queryUtils.tsindex 4244318da3d2..acc210f47020 100644--- a/frontend/src/scenes/insights/utils/queryUtils.ts+++ b/frontend/src/scenes/insights/utils/queryUtils.ts@@ -262,7 +262,8 @@ const groupedChartDisplayTypes: Record<ChartDisplayType, ChartDisplayType> = {[ChartDisplayType.ActionsStackedBar]: ChartDisplayType.ActionsLineGraph,[ChartDisplayType.TwoDimensionalHeatmap]: ChartDisplayType.ActionsLineGraph,[ChartDisplayType.ScatterPlot]: ChartDisplayType.ActionsLineGraph,- [ChartDisplayType.Metric]: ChartDisplayType.ActionsLineGraph,+ // The backend adds a previous-period series for the Metric change pill, so its result does not fit the other displays.+ [ChartDisplayType.Metric]: ChartDisplayType.Metric,// cumulative time series[ChartDisplayType.ActionsLineGraphCumulative]: ChartDisplayType.ActionsLineGraphCumulative,