: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): show loading for results of another chart category (#102751)
Sam Pennington25525e0c9dfd
diff --git a/frontend/src/scenes/insights/insightVizDataLogic.test.ts b/frontend/src/scenes/insights/insightVizDataLogic.test.tsindex acecb8da668b..fadc09386847 100644--- a/frontend/src/scenes/insights/insightVizDataLogic.test.ts+++ b/frontend/src/scenes/insights/insightVizDataLogic.test.ts@@ -950,6 +950,27 @@ describe('insightVizDataLogic', () => {} as Record<string, any>)}).toMatchValues({ hasRenderableResults: false })})++ it.each([+ ['blocks time series rows under a donut chart', ChartDisplayType.ActionsDonut, { data: [1, 2, 3] }, false],+ [+ 'renders total value rows under a donut chart',+ ChartDisplayType.ActionsDonut,+ { aggregated_value: 6 },+ true,+ ],+ ['renders time series rows under a scatter plot', ChartDisplayType.ScatterPlot, { data: [1, 2, 3] }, true],+ [+ 'renders time series rows under a two dimensional heatmap',+ ChartDisplayType.TwoDimensionalHeatmap,+ { data: [1, 2, 3] },+ true,+ ],+ ])('%s', (_, display, row, expected) => {+ builtInsightVizDataLogic.actions.updateQuerySource({ ...trendsQueryDefault, trendsFilter: { display } })+ builtInsightDataLogic.actions.loadDataSuccess({ results: [row] })+ expect(builtInsightVizDataLogic.values.hasRenderableResults).toBe(expected)+ })})describe('isSingleSeriesOutput', () => {diff --git a/frontend/src/scenes/insights/insightVizDataLogic.ts b/frontend/src/scenes/insights/insightVizDataLogic.tsindex f17e0ee1cbc6..e940af90e134 100644--- a/frontend/src/scenes/insights/insightVizDataLogic.ts+++ b/frontend/src/scenes/insights/insightVizDataLogic.ts@@ -23,6 +23,7 @@ import { databaseTableListLogic } from 'scenes/data-management/database/databaseimport { dataThemeLogic } from 'scenes/dataThemeLogic'import { insightDataLogic } from 'scenes/insights/insightDataLogic'import { keyForInsightLogicProps } from 'scenes/insights/sharedUtils'+import { trendsResultsMatchQuery } from 'scenes/insights/utils/queryUtils'import { sceneLogic } from 'scenes/sceneLogic'import { filterTestAccountsDefaultsLogic } from 'scenes/settings/environment/filterTestAccountDefaultsLogic'@@ -1227,7 +1228,20 @@ export interface insightVizDataLogicMeta {validationError: (insightDataError: Record<string, any> | null) => string | nullvalidationErrorCode: (insightDataError: Record<string, any> | null) => string | nulltimezone: (insightData: Record<string, any>) => any- hasRenderableResults: (insightData: Record<string, any>) => boolean+ hasRenderableResults: (+ insightData: Record<string, any>,+ querySource:+ | FunnelsQuery+ | LifecycleQuery+ | PathsQuery+ | PathsV2Query+ | RetentionQuery+ | StickinessQuery+ | TrendsQuery+ | WebOverviewQuery+ | WebStatsTableQuery+ | null+ ) => booleanallEventNames: (querySource:| FunnelsQuery@@ -2471,8 +2485,20 @@ export const insightVizDataLogic = kea<insightVizDataLogicType>([timezone: [(s) => [s.insightData], (insightData: Record<string, any>) => insightData?.timezone || 'UTC'],hasRenderableResults: [- (s) => [s.insightData],- (insightData: Record<string, any>): boolean => insightData?.result != null || insightData?.results != null,+ (s) => [s.insightData, s.querySource],+ (+ insightData: Record<string, any>,+ querySource: FunnelsQuery | LifecycleQuery | RetentionQuery | StickinessQuery | TrendsQuery | null+ ): boolean => {+ const results = insightData?.results ?? insightData?.result+ if (results == null) {+ return false+ }+ if (!querySource || !isTrendsQuery(querySource) || !Array.isArray(results)) {+ return true+ }+ return trendsResultsMatchQuery(results, querySource)+ },],// all events used in the insight (useful for fetching only relevant property definitions)diff --git a/frontend/src/scenes/insights/utils/queryUtils.ts b/frontend/src/scenes/insights/utils/queryUtils.tsindex faa66dcac093..4244318da3d2 100644--- a/frontend/src/scenes/insights/utils/queryUtils.ts+++ b/frontend/src/scenes/insights/utils/queryUtils.ts@@ -20,11 +20,11 @@ import {isEventsNode,isFunnelsQuery,isHogQLQuery,- isLifecycleQuery,isInsightQueryNode,isInsightQueryWithDisplay,isInsightQueryWithSeries,isInsightVizNode,+ isLifecycleQuery,isPathsQuery,isRetentionQuery,isStickinessQuery,@@ -386,3 +386,29 @@ export const cleanInsightQuery = (query: InsightQueryNode, opts?: CompareQueryOpreturn cleanedQuery}++// Sync with backend TrendsDisplay.is_total_value: only these displays return one aggregated value per row.+const AGGREGATED_RESULT_DISPLAYS = new Set<ChartDisplayType>([+ ChartDisplayType.BoldNumber,+ ChartDisplayType.ActionsPie,+ ChartDisplayType.ActionsDonut,+ ChartDisplayType.ActionsBarValue,+ ChartDisplayType.ActionsTable,+ ChartDisplayType.WorldMap,+ ChartDisplayType.CalendarHeatmap,+])++// A result computed for the other row shape renders as a blank or zeroed chart.+export const trendsResultsMatchQuery = (results: unknown[], query: TrendsQuery): boolean => {+ const first = results[0] as { data?: unknown[]; aggregated_value?: unknown } | undefined+ const isAggregated = AGGREGATED_RESULT_DISPLAYS.has(+ query.trendsFilter?.display ?? ChartDisplayType.ActionsLineGraph+ )+ if (first?.data?.length) {+ return !isAggregated+ }+ if (first?.aggregated_value != null) {+ return isAggregated+ }+ return true+}