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.

refactor(insights): read insights table series from the query (#116861)

Thomas Obermüllerf02bfdd66397
diff --git a/frontend/snapshots.yml b/frontend/snapshots.yml
index 30281e41f0a9..4efc4fb8ae1b 100644
--- a/frontend/snapshots.yml
+++ b/frontend/snapshots.yml
@@ -12331,9 +12331,9 @@ snapshots:
scenes-app-insights-error-empty-states--validation-error--light:
hash: v1.k794b7964.b6e11cfba354f46512f0909f31666f8d0318bc56ee0dcce111ef895bbce4be6a.RDM-1EMK2YZEI-mvQo9N4dYEuQdGDfSGrY2sazgq2YA
scenes-app-insights-flag-called-rebuild-banner--insight-on-flag-calls--dark:
- hash: v1.k794b7964.3d946f71319ec412299b8888e9a3fed48a7098bcf0e92cda25f6f34a43071a3f.PbH5UAwbwGY8tveYtVSlUz6TeywtNh7otO1PSPZi9vw
+ hash: v1.k794b7964.6e0dbf185860e9334d5f47bd37bc3c83fb7c80a6f67aec420dc4c3e84c7be1da.Qwx2T2FkdkOHXJUXSl4wGbz6wZHvzM-jkljApsLUVuk
scenes-app-insights-flag-called-rebuild-banner--insight-on-flag-calls--light:
- hash: v1.k794b7964.c1bca29126f3f201df46989d83af5e777ad42f21aba60febca75e2ded1a00d6e.WHUf4o3J7Uo7jwnFaGNXQgqa9jMdohuIOo1eSFbW9a4
+ hash: v1.k794b7964.e667a70f89bbba0a7d5bc3166f2bf3a42a17845518e994975944ee2a31aaee0a.fshegHwDj7O7_Gwl8j5eof7QXffqbc_yldQxsNlkUpQ
scenes-app-insights-flag-calls-retention-notice--default--dark:
hash: v1.k794b7964.d9aefe5f9ce9d7a864d6bf0338965adf5c01284b0fa767b3db193cbf9102838b.F_x981isYjYR1oKf0BPU3Agkr_bpR7TqheKovVn432o
scenes-app-insights-flag-calls-retention-notice--default--light:
@@ -12383,9 +12383,9 @@ snapshots:
scenes-app-insights-side-panel-actions--saved-hog-ql-data-table--light:
hash: v1.k794b7964.602be55b40a5fdcd79839a50eb3ced165702357fda6074051233988743b6a263.5AuLPU3Rcd90xrrOMpWjO2SowfaamP291mM0FEoAn_M
scenes-app-insights-side-panel-actions--saved-trends-insight--dark:
- hash: v1.k794b7964.bbb281c33fb319c3533f089f9012364e09adb7ec4ec105bbd031035cfec30d8f.t3-xk6ogh7h_ngxjAm_Kv9sKzEprz03rTKu_ZixujOc
+ hash: v1.k794b7964.4d761d5ca570e5cf69e5bd32ad7f530fe6dd50cf1049c81decafd573b8a099ac.19lqB3UqGtYlnc2lhiebaKkDXZgpDUPPf2gpWfLcbfY
scenes-app-insights-side-panel-actions--saved-trends-insight--light:
- hash: v1.k794b7964.7536160e02e9f6bfa7b9e38fab645e4c3dc9fa86f9c0c4a3eb27828cb2f3b97c.5QZ0PRFbVTH8twv-gQwnHOG-r_ZUbqN_do8UXhkeTpo
+ hash: v1.k794b7964.cf5d3aac98555317e5eba0c4f50d9b98a4d37ecefaaf2ebdd0d5c175288b0810.HjuoJYntIBw1ybaTD2-vd49tL7_1Wm0t9OMV5EG7ovE
scenes-app-insights-side-panel-actions--unsaved-insight--dark:
hash: v1.k794b7964.fd37c04636d22a4bd420750e3eb007eeb90eaeb615c73543513fc8bf093ed049.e38Xtlvpj0vSHJNNkprn94CRhpPWmkEtICoHM0C0IqE
scenes-app-insights-side-panel-actions--unsaved-insight--light:
diff --git a/frontend/src/lib/components/InsightLabel/index.test.tsx b/frontend/src/lib/components/InsightLabel/index.test.tsx
index c562ab0065e4..0c1062ee6563 100644
--- a/frontend/src/lib/components/InsightLabel/index.test.tsx
+++ b/frontend/src/lib/components/InsightLabel/index.test.tsx
@@ -7,24 +7,12 @@ import type { ResultSeries } from 'scenes/insights/utils/resultSeries'
import { EventsNode, NodeKind } from '~/queries/schema/schema-general'
import { initKeaTests } from '~/test/init'
-import { ActionFilter, HogQLMathType } from '~/types'
+import { HogQLMathType, PropertyMathType } from '~/types'
import { InsightLabel } from './index'
const HOGQL_EXPRESSION = 'avg(properties.usd_amount)'
-function hogqlAction(overrides: Partial<ActionFilter> = {}): ActionFilter {
- return {
- id: '$pageview',
- name: '$pageview',
- type: 'events',
- order: 0,
- math: 'hogql',
- math_hogql: HOGQL_EXPRESSION,
- ...overrides,
- } as ActionFilter
-}
-
function hogqlSeries(overrides: Partial<EventsNode> = {}): ResultSeries {
const node: EventsNode = {
kind: NodeKind.EventsNode,
@@ -58,30 +46,30 @@ describe('InsightLabel — hideHogQLTagWhenCustomName', () => {
)
}
- it.each<[string, Parameters<typeof InsightLabel>[0]]>([
- ['a custom name', { action: hogqlAction({ custom_name: 'Revenue' }) }],
- ['a query series renamed through its name', { series: hogqlSeries({ name: 'Revenue' }) }],
- ])('hides the SQL expression tag when the flag is on, the series has %s, and math is hogql', (_, props) => {
- renderLabel({ ...props, hideHogQLTagWhenCustomName: true })
+ it.each<[string, Partial<EventsNode>]>([
+ ['a custom name', { custom_name: 'Revenue' }],
+ ['a rename through its name', { name: 'Revenue' }],
+ ])('hides the SQL expression tag when the flag is on, the series has %s, and math is hogql', (_, overrides) => {
+ renderLabel({ series: hogqlSeries(overrides), hideHogQLTagWhenCustomName: true })
expect(screen.queryByText(HOGQL_EXPRESSION)).not.toBeInTheDocument()
})
it('keeps the SQL expression tag by default (opt-in), even with a custom name', () => {
- renderLabel({ action: hogqlAction({ custom_name: 'Revenue' }) })
+ renderLabel({ series: hogqlSeries({ custom_name: 'Revenue' }) })
expect(screen.getByText(HOGQL_EXPRESSION)).toBeInTheDocument()
})
it('keeps the SQL expression tag when the flag is on but the series has no custom name', () => {
- renderLabel({ action: hogqlAction(), hideHogQLTagWhenCustomName: true })
+ renderLabel({ series: hogqlSeries(), hideHogQLTagWhenCustomName: true })
expect(screen.getByText(HOGQL_EXPRESSION)).toBeInTheDocument()
})
it('does not affect non-hogql math tags — a named sum series still shows its tag', () => {
renderLabel({
- action: hogqlAction({ custom_name: 'Revenue', math: 'sum', math_property: 'usd_amount' }),
+ series: hogqlSeries({ custom_name: 'Revenue', math: PropertyMathType.Sum, math_property: 'usd_amount' }),
hideHogQLTagWhenCustomName: true,
})
diff --git a/frontend/src/lib/components/InsightLabel/index.tsx b/frontend/src/lib/components/InsightLabel/index.tsx
index 0f472901eaa9..15fc39e98163 100644
--- a/frontend/src/lib/components/InsightLabel/index.tsx
+++ b/frontend/src/lib/components/InsightLabel/index.tsx
@@ -5,7 +5,7 @@ import { useValues } from 'kea'
import { LemonTag } from '@posthog/lemon-ui'
-import { DisplayableEntity, EntityFilterInfo } from 'lib/components/EntityFilterInfo'
+import { EntityFilterInfo } from 'lib/components/EntityFilterInfo'
import { parseAliasToReadable } from 'lib/components/PathCleanFilters/PathCleanFilterItem'
import { PropertyKeyInfo } from 'lib/components/PropertyKeyInfo'
import { SeriesLetter } from 'lib/components/SeriesGlyph'
@@ -16,7 +16,7 @@ import { formatEventName } from 'scenes/insights/utils'
import { ResultSeries, getResultSeriesCustomName } from 'scenes/insights/utils/resultSeries'
import { groupsModel } from '~/models/groupsModel'
-import { ActionFilter, BreakdownKeyType } from '~/types'
+import { BreakdownKeyType } from '~/types'
import { mathsLogic } from 'products/product_analytics/frontend/insights/trends/mathsLogic'
@@ -28,12 +28,11 @@ export enum IconSize {
Large = 'large',
}
-// InsightsLabel pretty prints the action (or event) returned from /insights
+// InsightsLabel pretty prints the series a result row reports
interface InsightsLabelProps {
seriesColor?: string
- /** The result row's series, from `getResultSeries`. Takes precedence over `action`. */
+ /** The result row's series, from `getResultSeries`. */
series?: ResultSeries | null
- action?: ActionFilter | null
value?: string
className?: string
breakdownValue?: BreakdownKeyType
@@ -108,7 +107,6 @@ function MathTag({ math, mathProperty, mathHogQL, mathGroupTypeIndex }: MathTagP
export function InsightLabel({
seriesColor = '#000000',
series,
- action,
value,
className,
breakdownValue,
@@ -133,10 +131,10 @@ export function InsightLabel({
}: InsightsLabelProps): JSX.Element {
const showEventName = _showEventName || !breakdownValue || (hasMultipleSeries && !Array.isArray(breakdownValue))
- const entity: DisplayableEntity | null | undefined = series ? series.node : action
- const math = series ? series.math : action
- const seriesIndex = series ? (series.node ? series.order : undefined) : action?.order
- const customName = series ? series.node && getResultSeriesCustomName(series.node) : action?.custom_name
+ const entity = series?.node
+ const math = series?.math
+ const seriesIndex = series?.node ? series.order : undefined
+ const customName = entity ? getResultSeriesCustomName(entity) : null
const displayEntity = entity ? { ...entity, name: formatEventName(entity.name) } : undefined
const eventName = seriesStatus
diff --git a/frontend/src/scenes/insights/filters/ActionFilter/ActionFilterRow/ActionFilterRow.test.tsx b/frontend/src/scenes/insights/filters/ActionFilter/ActionFilterRow/ActionFilterRow.test.tsx
index 002ed9bacc31..40f4536e74a1 100644
--- a/frontend/src/scenes/insights/filters/ActionFilter/ActionFilterRow/ActionFilterRow.test.tsx
+++ b/frontend/src/scenes/insights/filters/ActionFilter/ActionFilterRow/ActionFilterRow.test.tsx
@@ -527,7 +527,7 @@ describe('ActionFilterRow', () => {
expect(duplicated[1]).toEqual(expect.objectContaining({ kind: NodeKind.EventsNode, event: '$pageview' }))
})
- it('dispatches selectFilter and calls onRenameClick on rename', async () => {
+ it('calls onRenameClick on rename', async () => {
const { logic } = setup()
const onRenameClick = jest.fn()
renderRow(logic, { ...INLINE_CONTEXT, hideRename: false, onRenameClick })
diff --git a/frontend/src/scenes/insights/filters/ActionFilter/entityFilterLogic.ts b/frontend/src/scenes/insights/filters/ActionFilter/entityFilterLogic.ts
index 1192dc402dca..aa74c58a078b 100644
--- a/frontend/src/scenes/insights/filters/ActionFilter/entityFilterLogic.ts
+++ b/frontend/src/scenes/insights/filters/ActionFilter/entityFilterLogic.ts
@@ -8,15 +8,7 @@ import { uuid } from 'lib/utils/dom'
import { GraphSeriesAddedSource, eventUsageLogic } from 'lib/utils/eventUsageLogic'
import { AnyEntityNode, EventsNode, GroupNode, NodeKind } from '~/queries/schema/schema-general'
-import {
- ActionFilter,
- AnyPropertyFilter,
- EntityFilter,
- EntityType,
- FilterLogicalOperator,
- PropertyFilterType,
- PropertyMathType,
-} from '~/types'
+import { AnyPropertyFilter, EntityType, FilterLogicalOperator, PropertyFilterType, PropertyMathType } from '~/types'
import {
SeriesNode,
@@ -173,9 +165,6 @@ export interface entityFilterLogicActions {
renameSeries: (customName: string) => {
customName: string
}
- selectFilter: (filter: ActionFilter | EntityFilter | null) => {
- filter: ActionFilter | EntityFilter | null
- }
selectSeries: (
index: number | null,
node?: SeriesNode | null,
@@ -185,6 +174,9 @@ export interface entityFilterLogicActions {
node: SeriesNode | null | undefined
uuid: string | undefined
}
+ selectSeriesAt: (index: number | null) => {
+ index: number | null
+ }
setEntityFilterVisibility: (
index: number,
value: boolean
@@ -258,8 +250,7 @@ export const entityFilterLogic = kea<entityFilterLogicType>([
})),
actions({
selectSeries: (index: number | null, node?: SeriesNode | null, uuid?: string) => ({ index, node, uuid }),
- // The results table hands over the legacy-shaped series object the trends runner emits.
- selectFilter: (filter: EntityFilter | ActionFilter | null) => ({ filter }),
+ selectSeriesAt: (index: number | null) => ({ index }),
updateSeriesEntity: (index: number, update: SeriesEntityUpdate) => ({ index, update }),
updateSeriesMath: (index: number, math: SeriesMathUpdate) => ({ index, math }),
updateSeriesProperties: (index: number, properties: AnyPropertyFilter[]) => ({ index, properties }),
@@ -349,13 +340,8 @@ export const entityFilterLogic = kea<entityFilterLogicType>([
}
return {
- selectFilter: ({ filter }) => {
- if (!filter) {
- actions.selectSeries(null)
- return
- }
- const index = filter.order ?? filter.index ?? -1
- const local = values.localSeries[index]
+ selectSeriesAt: ({ index }) => {
+ const local = index === null ? undefined : values.localSeries[index]
actions.selectSeries(local ? index : null, local?.node, local?.uuid)
},
renameSeries: ({ customName }) => {
diff --git a/frontend/src/scenes/insights/filters/ActionFilter/renameModalLogic.test.ts b/frontend/src/scenes/insights/filters/ActionFilter/renameModalLogic.test.ts
index 24067073ca1e..8fb6b38c7b40 100644
--- a/frontend/src/scenes/insights/filters/ActionFilter/renameModalLogic.test.ts
+++ b/frontend/src/scenes/insights/filters/ActionFilter/renameModalLogic.test.ts
@@ -6,7 +6,6 @@ import { insightDataLogic } from 'scenes/insights/insightDataLogic'
import { getDisplayNameFromEntityNode } from 'scenes/insights/utils'
import { initKeaTests } from '~/test/init'
-import { EntityFilter } from '~/types'
import filtersJson from './__mocks__/filters.json'
import { legacyFiltersToSeries } from './legacyFilters'
@@ -69,16 +68,10 @@ describe('renameModalLogic', () => {
})
})
- it('resolves the legacy series object the results table passes', async () => {
+ it('selects the series the results table picks by index', async () => {
await expectLogic(relevantEntityFilterLogic, () => {
- // The trends runner emits `order`, not an index.
- relevantEntityFilterLogic.actions.selectFilter({
- id: '9',
- name: 'Users signed up',
- type: 'actions',
- order: 2,
- } as EntityFilter)
- }).toDispatchActions(['selectFilter', 'selectSeries'])
+ relevantEntityFilterLogic.actions.selectSeriesAt(2)
+ }).toDispatchActions(['selectSeriesAt', 'selectSeries'])
await expectLogic(logic).toMatchValues({
name: 'Users signed up',
diff --git a/products/product_analytics/frontend/insights/shared/InsightsTable/InsightsTable.tsx b/products/product_analytics/frontend/insights/shared/InsightsTable/InsightsTable.tsx
index 881028946629..00b5af4fde2f 100644
--- a/products/product_analytics/frontend/insights/shared/InsightsTable/InsightsTable.tsx
+++ b/products/product_analytics/frontend/insights/shared/InsightsTable/InsightsTable.tsx
@@ -11,6 +11,8 @@ import { formatAggregationAxisValue } from 'scenes/insights/aggregationAxisForma
import { entityFilterLogic } from 'scenes/insights/filters/ActionFilter/entityFilterLogic'
import { insightLogic } from 'scenes/insights/insightLogic'
import { formatBreakdownLabel } from 'scenes/insights/utils'
+import { getResultSeries, getResultSeriesIndex } from 'scenes/insights/utils/resultSeries'
+import { getResultSeriesName } from 'scenes/insights/utils/resultSeriesName'
import { teamLogic } from 'scenes/teamLogic'
import { cohortsModel } from '~/models/cohortsModel'
@@ -99,6 +101,7 @@ export function InsightsTable({
getTrendsColor,
getTrendsHidden,
insightData,
+ querySource,
} = useValues(trendsDataLogic(insightProps))
const { toggleResultHidden, toggleAllResultsHidden } = useActions(trendsDataLogic(insightProps))
const { aggregation, allowAggregation, pinnedColumns, isColumnPinned, getPreviousResult, displayResults } =
@@ -114,11 +117,18 @@ export function InsightsTable({
typeKey: filterKey,
})
if (entityFilter) {
- entityFilter.actions.selectFilter(item.action)
+ entityFilter.actions.selectSeriesAt(getResultSeriesIndex(querySource, item) ?? null)
entityFilter.actions.showModal()
}
}
+ const mathPropertyOf = (item: IndexedTrendResult): string | null | undefined =>
+ getResultSeries(querySource, item).math?.math_property
+ const showCountedByTag = indexedResults.some((item) => {
+ const math = getResultSeries(querySource, item).math?.math
+ return !!math && math !== 'total'
+ })
+
const { allCohorts } = useValues(cohortsModel)
const { formatPropertyValueForDisplay } = useValues(propertyDefinitionsModel)
@@ -197,7 +207,8 @@ export function InsightsTable({
) : (
<SeriesColumnItem
item={item}
- indexedResults={indexedResults}
+ series={getResultSeries(querySource, item)}
+ showCountedByTag={showCountedByTag}
canEditSeriesNameInline={canEditSeriesNameInline}
seriesNameTooltip={seriesNameTooltip}
handleEditClick={handleSeriesEditClick}
@@ -231,8 +242,8 @@ export function InsightsTable({
return compareFn()(formatItemBreakdownLabel!(a), formatItemBreakdownLabel!(b))
}
- const labelA = a.action?.name || a.label || ''
- const labelB = b.action?.name || b.label || ''
+ const labelA = getResultSeriesName(getResultSeries(querySource, a)) || a.label || ''
+ const labelB = getResultSeriesName(getResultSeries(querySource, b)) || b.label || ''
return labelA.localeCompare(labelB)
},
})
@@ -352,6 +363,7 @@ export function InsightsTable({
render: (_: any, item: IndexedTrendResult) => (
<AggregationColumnItem
item={item}
+ mathProperty={mathPropertyOf(item)}
isNonTimeSeriesDisplay={isNonTimeSeriesDisplay}
aggregation={aggregation}
trendsFilter={trendsFilter}
@@ -376,6 +388,7 @@ export function InsightsTable({
return (
<AggregationColumnItem
item={previousItem}
+ mathProperty={mathPropertyOf(previousItem)}
isNonTimeSeriesDisplay={isNonTimeSeriesDisplay}
aggregation={aggregation}
trendsFilter={trendsFilter}
@@ -452,6 +465,7 @@ export function InsightsTable({
<ValueColumnItem
index={index}
item={item}
+ mathProperty={mathPropertyOf(item)}
isStickiness={isStickiness}
renderCount={renderCount}
formatPropertyValueForDisplay={formatPropertyValueForDisplay}
@@ -463,6 +477,7 @@ export function InsightsTable({
}))
}, [
indexedResults,
+ querySource,
renderCount,
formatPropertyValueForDisplay,
isStickiness,
diff --git a/products/product_analytics/frontend/insights/shared/InsightsTable/columns/AggregationColumn.tsx b/products/product_analytics/frontend/insights/shared/InsightsTable/columns/AggregationColumn.tsx
index e69d84878d4c..23e436e87995 100644
--- a/products/product_analytics/frontend/insights/shared/InsightsTable/columns/AggregationColumn.tsx
+++ b/products/product_analytics/frontend/insights/shared/InsightsTable/columns/AggregationColumn.tsx
@@ -68,6 +68,7 @@ export function AggregationColumnTitle({
type AggregationColumnItemProps = {
item: IndexedTrendResult
+ mathProperty: string | null | undefined
isNonTimeSeriesDisplay: boolean
aggregation: CalcColumnState
trendsFilter: TrendsFilter | null | undefined
@@ -94,6 +95,7 @@ export function getAggregatedValue(
export function AggregationColumnItem({
item,
+ mathProperty,
isNonTimeSeriesDisplay,
aggregation,
trendsFilter,
@@ -106,7 +108,7 @@ export function AggregationColumnItem({
const formattedValue: ReactNode =
value !== undefined
? formatAggregationValue(
- item.action?.math_property,
+ mathProperty,
value,
(value) => formatAggregationAxisValue(trendsFilter as Partial<TrendsFilterType>, value, baseCurrency),
formatPropertyValueForDisplay
diff --git a/products/product_analytics/frontend/insights/shared/InsightsTable/columns/SeriesColumn.tsx b/products/product_analytics/frontend/insights/shared/InsightsTable/columns/SeriesColumn.tsx
index f53e3b7ca3e4..4c19500c283e 100644
--- a/products/product_analytics/frontend/insights/shared/InsightsTable/columns/SeriesColumn.tsx
+++ b/products/product_analytics/frontend/insights/shared/InsightsTable/columns/SeriesColumn.tsx
@@ -4,6 +4,7 @@ import { Tooltip } from '@posthog/lemon-ui'
import { InsightLabel } from 'lib/components/InsightLabel'
import { capitalizeFirstLetter } from 'lib/utils/strings'
+import type { ResultSeries } from 'scenes/insights/utils/resultSeries'
import { TrendResult } from '~/types'
@@ -11,7 +12,8 @@ import { IndexedTrendResult } from 'products/product_analytics/frontend/insights
type SeriesColumnItemProps = {
item: IndexedTrendResult
- indexedResults: IndexedTrendResult[]
+ series: ResultSeries
+ showCountedByTag: boolean
canEditSeriesNameInline: boolean
seriesNameTooltip?: string
handleEditClick: (item: IndexedTrendResult) => void
@@ -22,7 +24,8 @@ type SeriesColumnItemProps = {
export function SeriesColumnItem({
item,
- indexedResults,
+ series,
+ showCountedByTag,
canEditSeriesNameInline,
seriesNameTooltip,
handleEditClick,
@@ -30,13 +33,11 @@ export function SeriesColumnItem({
hasBreakdown,
hideCompare,
}: SeriesColumnItemProps): JSX.Element {
- const showCountedByTag = !!indexedResults.find(({ action }) => action?.math && action.math !== 'total')
-
return (
<Tooltip title={seriesNameTooltip}>
<div className="series-name-wrapper-col deprecated-space-x-1">
<InsightLabel
- action={item.action}
+ series={series}
fallbackName={item.breakdown_value === '' ? 'None' : item.label}
hasMultipleSeries={hasMultipleSeries}
showEventName
diff --git a/products/product_analytics/frontend/insights/shared/InsightsTable/columns/ValueColumn.tsx b/products/product_analytics/frontend/insights/shared/InsightsTable/columns/ValueColumn.tsx
index 4eef62beebaa..df5afb5d7292 100644
--- a/products/product_analytics/frontend/insights/shared/InsightsTable/columns/ValueColumn.tsx
+++ b/products/product_analytics/frontend/insights/shared/InsightsTable/columns/ValueColumn.tsx
@@ -46,6 +46,7 @@ export function ValueColumnTitle({
type ValueColumnItemProps = {
index: number
item: IndexedTrendResult
+ mathProperty: string | null | undefined
isStickiness: boolean
renderCount: (value: number) => ReactNode
formatPropertyValueForDisplay: FormatPropertyValueForDisplayFunction
@@ -54,12 +55,13 @@ type ValueColumnItemProps = {
export const ValueColumnItem = memo(function ValueColumnItem({
index,
item,
+ mathProperty,
isStickiness,
renderCount,
formatPropertyValueForDisplay,
}: ValueColumnItemProps): JSX.Element {
const formattedValue = formatAggregationValue(
- item.action?.math_property,
+ mathProperty,
item.data[index],
renderCount,
formatPropertyValueForDisplay
diff --git a/products/product_analytics/frontend/insights/shared/InsightsTable/insightsTableDataLogic.test.ts b/products/product_analytics/frontend/insights/shared/InsightsTable/insightsTableDataLogic.test.ts
index 452aec201abd..c40c54523eaa 100644
--- a/products/product_analytics/frontend/insights/shared/InsightsTable/insightsTableDataLogic.test.ts
+++ b/products/product_analytics/frontend/insights/shared/InsightsTable/insightsTableDataLogic.test.ts
@@ -148,19 +148,14 @@ describe('insightsTableDataLogic', () => {
describe('compareResultKey', () => {
const makeResult = (overrides: Partial<IndexedTrendResult>): IndexedTrendResult =>
({
- action: { order: 0 },
+ order: 0,
label: '$pageview',
breakdown_value: '',
...overrides,
}) as IndexedTrendResult
it.each([
- [
- 'distinguishes by action order',
- makeResult({ action: { order: 0 } as any }),
- makeResult({ action: { order: 1 } as any }),
- false,
- ],
+ ['distinguishes by series order', makeResult({ order: 0 }), makeResult({ order: 1 }), false],
[
'distinguishes by breakdown value',
makeResult({ breakdown_value: 'Chrome' }),
@@ -175,8 +170,8 @@ describe('insightsTableDataLogic', () => {
],
[
'matches when all fields are the same',
- makeResult({ action: { order: 0 } as any, label: '$pageview', breakdown_value: 'Chrome' }),
- makeResult({ action: { order: 0 } as any, label: '$pageview', breakdown_value: 'Chrome' }),
+ makeResult({ order: 0, label: '$pageview', breakdown_value: 'Chrome' }),
+ makeResult({ order: 0, label: '$pageview', breakdown_value: 'Chrome' }),
true,
],
[
@@ -194,15 +189,13 @@ describe('insightsTableDataLogic', () => {
})
it('produces valid JSON array string', () => {
- const result = compareResultKey(
- makeResult({ action: { order: 2 } as any, label: 'test', breakdown_value: 'val' })
- )
+ const result = compareResultKey(makeResult({ order: 2, label: 'test', breakdown_value: 'val' }))
expect(JSON.parse(result)).toEqual([2, 'test', 'val'])
})
it('handles nullish fields gracefully', () => {
const result = compareResultKey(
- makeResult({ action: undefined, label: undefined, breakdown_value: undefined } as any)
+ makeResult({ order: undefined, label: undefined, breakdown_value: undefined } as any)
)
expect(JSON.parse(result)).toEqual([0, '', ''])
})
@@ -224,6 +217,7 @@ describe('insightsTableDataLogic', () => {
math_group_type_index: null,
properties: {},
} as any,
+ order: 0,
label: '$pageview',
count: 100,
data: [10, 20, 30],
@@ -312,12 +306,14 @@ describe('insightsTableDataLogic', () => {
compare_label: CompareLabelType.Current,
compare: true,
action: { order: 1, id: '$autocapture', name: '$autocapture' } as any,
+ order: 1,
label: '$autocapture',
}),
makeCompareResult({
compare_label: CompareLabelType.Previous,
compare: true,
action: { order: 1, id: '$autocapture', name: '$autocapture' } as any,
+ order: 1,
label: '$autocapture',
count: 60,
data: [6, 12, 18],
diff --git a/products/product_analytics/frontend/insights/shared/InsightsTable/insightsTableDataLogic.ts b/products/product_analytics/frontend/insights/shared/InsightsTable/insightsTableDataLogic.ts
index f29a998ee888..7755fa5ca16c 100644
--- a/products/product_analytics/frontend/insights/shared/InsightsTable/insightsTableDataLogic.ts
+++ b/products/product_analytics/frontend/insights/shared/InsightsTable/insightsTableDataLogic.ts
@@ -2,6 +2,7 @@ import { MakeLogicType, actions, connect, kea, key, path, props, reducers, selec
import { insightVizDataLogic } from 'scenes/insights/insightVizDataLogic'
import { keyForInsightLogicProps } from 'scenes/insights/sharedUtils'
+import { getResultOrder } from 'scenes/insights/utils/resultSeries'
import type {
AnyDataWarehouseNode,
@@ -22,7 +23,7 @@ export enum AggregationType {
}
export function compareResultKey(item: IndexedTrendResult): string {
- return JSON.stringify([item.action?.order ?? 0, item.label ?? '', item.breakdown_value ?? ''])
+ return JSON.stringify([getResultOrder(item), item.label ?? '', item.breakdown_value ?? ''])
}
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.