Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(insights): Put "Other" and "None" last in Trends results #21233

Merged
merged 9 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions frontend/src/scenes/insights/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,13 @@ export function formatAggregationValue(
return Array.isArray(formattedValue) ? formattedValue[0] : formattedValue
}

// NB! Sync this with breakdown.py
// NB! Sync this with breakdown_values.py
export const BREAKDOWN_OTHER_STRING_LABEL = '$$_posthog_breakdown_other_$$'
export const BREAKDOWN_OTHER_NUMERIC_LABEL = 9007199254740991 // pow(2, 53) - 1
export const BREAKDOWN_OTHER_DISPLAY = 'Other (i.e. all remaining values)'
export const BREAKDOWN_NULL_STRING_LABEL = '$$_posthog_breakdown_null_$$'
export const BREAKDOWN_NULL_NUMERIC_LABEL = 9007199254740990 // pow(2, 53) - 2
export const BREAKDOWN_NULL_DISPLAY = 'None (i.e. no value)'

export function isOtherBreakdown(breakdown_value: string | number | null | undefined | ReactNode): boolean {
return (
Expand Down Expand Up @@ -277,17 +279,17 @@ export function formatBreakdownLabel(
return cohorts?.filter((c) => c.id == breakdown_value)[0]?.name ?? (breakdown_value || '').toString()
} else if (typeof breakdown_value == 'number') {
return isOtherBreakdown(breakdown_value)
? 'Other (Groups all remaining values)'
? BREAKDOWN_OTHER_DISPLAY
: isNullBreakdown(breakdown_value)
? 'None'
? BREAKDOWN_NULL_DISPLAY
: formatPropertyValueForDisplay
? formatPropertyValueForDisplay(breakdown, breakdown_value)?.toString() ?? 'None'
: String(breakdown_value)
} else if (typeof breakdown_value == 'string') {
return isOtherBreakdown(breakdown_value) || breakdown_value === 'nan'
? 'Other (Groups all remaining values)'
? BREAKDOWN_OTHER_DISPLAY
: isNullBreakdown(breakdown_value) || breakdown_value === ''
? 'None'
? BREAKDOWN_NULL_DISPLAY
: breakdown_value
} else if (Array.isArray(breakdown_value)) {
return breakdown_value
Expand Down
16 changes: 14 additions & 2 deletions frontend/src/scenes/trends/trendsDataLogic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@ import api from 'lib/api'
import { dayjs } from 'lib/dayjs'
import { insightVizDataLogic } from 'scenes/insights/insightVizDataLogic'
import { keyForInsightLogicProps } from 'scenes/insights/sharedUtils'
import { isOtherBreakdown } from 'scenes/insights/utils'
import {
BREAKDOWN_NULL_NUMERIC_LABEL,
BREAKDOWN_NULL_STRING_LABEL,
BREAKDOWN_OTHER_NUMERIC_LABEL,
BREAKDOWN_OTHER_STRING_LABEL,
isOtherBreakdown,
} from 'scenes/insights/utils'

import { EntityNode } from '~/queries/schema'
import {
Expand Down Expand Up @@ -118,7 +124,13 @@ export const trendsDataLogic = kea<trendsDataLogicType>([
display &&
(display === ChartDisplayType.ActionsBarValue || display === ChartDisplayType.ActionsPie)
) {
indexedResults.sort((a, b) => b.aggregated_value - a.aggregated_value)
indexedResults.sort((a, b) =>
a.label === BREAKDOWN_OTHER_STRING_LABEL
? BREAKDOWN_OTHER_NUMERIC_LABEL
: a.label === BREAKDOWN_NULL_STRING_LABEL
? BREAKDOWN_NULL_NUMERIC_LABEL
: b.aggregated_value - a.aggregated_value
)
} else if (lifecycleFilter) {
if (lifecycleFilter.toggledLifecycles) {
indexedResults = indexedResults.filter((result) =>
Expand Down
14 changes: 12 additions & 2 deletions frontend/src/scenes/trends/viz/ActionsHorizontalBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
import { useEffect, useState } from 'react'
import { insightLogic } from 'scenes/insights/insightLogic'
import { insightVizDataLogic } from 'scenes/insights/insightVizDataLogic'
import { formatBreakdownLabel, isNullBreakdown, isOtherBreakdown } from 'scenes/insights/utils'
import {
BREAKDOWN_NULL_DISPLAY,
BREAKDOWN_OTHER_DISPLAY,
formatBreakdownLabel,
isNullBreakdown,
isOtherBreakdown,
} from 'scenes/insights/utils'

import { cohortsModel } from '~/models/cohortsModel'
import { propertyDefinitionsModel } from '~/models/propertyDefinitionsModel'
Expand Down Expand Up @@ -42,7 +48,11 @@ export function ActionsHorizontalBar({ showPersonsModal = true }: ChartParams):
setData([
{
labels: _data.map((item) =>
isOtherBreakdown(item.label) ? 'Other' : isNullBreakdown(item.label) ? 'None' : item.label
isOtherBreakdown(item.label)
? BREAKDOWN_OTHER_DISPLAY
: isNullBreakdown(item.label)
? BREAKDOWN_NULL_DISPLAY
: item.label
),
data: _data.map((item) => item.aggregated_value),
actions: _data.map((item) => item.action),
Expand Down
2 changes: 2 additions & 0 deletions posthog/hogql_queries/insights/trends/breakdown_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@

BREAKDOWN_OTHER_STRING_LABEL = "$$_posthog_breakdown_other_$$"
BREAKDOWN_OTHER_NUMERIC_LABEL = 9007199254740991 # pow(2, 53) - 1, for JS compatibility
BREAKDOWN_OTHER_DISPLAY = "Other (i.e. all remaining values)"
BREAKDOWN_NULL_STRING_LABEL = "$$_posthog_breakdown_null_$$"
BREAKDOWN_NULL_NUMERIC_LABEL = 9007199254740990 # pow(2, 53) - 2, for JS compatibility
BREAKDOWN_NULL_DISPLAY = "None (i.e. no value)"


class BreakdownValues:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,8 @@
breakdown_value
ORDER BY day_start ASC, breakdown_value ASC)
GROUP BY breakdown_value
ORDER BY sum(count) DESC, breakdown_value ASC
ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)),
sum(count) DESC, breakdown_value ASC
LIMIT 10000 SETTINGS readonly=2,
max_execution_time=60,
allow_experimental_object_type=1
Expand Down Expand Up @@ -348,7 +349,8 @@
breakdown_value
ORDER BY day_start ASC, breakdown_value ASC)
GROUP BY breakdown_value
ORDER BY sum(count) DESC, breakdown_value ASC
ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)),
sum(count) DESC, breakdown_value ASC
LIMIT 10000 SETTINGS readonly=2,
max_execution_time=60,
allow_experimental_object_type=1
Expand Down Expand Up @@ -401,7 +403,8 @@
breakdown_value
ORDER BY day_start ASC, breakdown_value ASC)
GROUP BY breakdown_value
ORDER BY sum(count) DESC, breakdown_value ASC
ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)),
sum(count) DESC, breakdown_value ASC
LIMIT 10000 SETTINGS readonly=2,
max_execution_time=60,
allow_experimental_object_type=1
Expand Down Expand Up @@ -454,7 +457,8 @@
breakdown_value
ORDER BY day_start ASC, breakdown_value ASC)
GROUP BY breakdown_value
ORDER BY sum(count) DESC, breakdown_value ASC
ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)),
sum(count) DESC, breakdown_value ASC
LIMIT 10000 SETTINGS readonly=2,
max_execution_time=60,
allow_experimental_object_type=1
Expand Down Expand Up @@ -705,7 +709,8 @@
breakdown_value
ORDER BY day_start ASC, breakdown_value ASC)
GROUP BY breakdown_value
ORDER BY sum(count) DESC, breakdown_value ASC
ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)),
sum(count) DESC, breakdown_value ASC
LIMIT 10000 SETTINGS readonly=2,
max_execution_time=60,
allow_experimental_object_type=1
Expand Down Expand Up @@ -774,7 +779,8 @@
breakdown_value
ORDER BY day_start ASC, breakdown_value ASC)
GROUP BY breakdown_value
ORDER BY sum(count) DESC, breakdown_value ASC
ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)),
sum(count) DESC, breakdown_value ASC
LIMIT 10000 SETTINGS readonly=2,
max_execution_time=60,
allow_experimental_object_type=1
Expand Down Expand Up @@ -863,7 +869,8 @@
breakdown_value
ORDER BY day_start ASC, breakdown_value ASC)
GROUP BY breakdown_value
ORDER BY sum(count) DESC, breakdown_value ASC
ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)),
sum(count) DESC, breakdown_value ASC
LIMIT 10000 SETTINGS readonly=2,
max_execution_time=60,
allow_experimental_object_type=1
Expand Down Expand Up @@ -923,7 +930,8 @@
breakdown_value
ORDER BY day_start ASC, breakdown_value ASC)
GROUP BY breakdown_value
ORDER BY sum(count) DESC, breakdown_value ASC
ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)),
sum(count) DESC, breakdown_value ASC
LIMIT 10000 SETTINGS readonly=2,
max_execution_time=60,
allow_experimental_object_type=1
Expand Down Expand Up @@ -983,7 +991,8 @@
breakdown_value
ORDER BY day_start ASC, breakdown_value ASC)
GROUP BY breakdown_value
ORDER BY sum(count) DESC, breakdown_value ASC
ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)),
sum(count) DESC, breakdown_value ASC
LIMIT 10000 SETTINGS readonly=2,
max_execution_time=60,
allow_experimental_object_type=1
Expand Down Expand Up @@ -1355,7 +1364,8 @@
breakdown_value
ORDER BY day_start ASC, breakdown_value ASC)
GROUP BY breakdown_value
ORDER BY sum(count) DESC, breakdown_value ASC
ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)),
sum(count) DESC, breakdown_value ASC
LIMIT 10000 SETTINGS readonly=2,
max_execution_time=60,
allow_experimental_object_type=1
Expand Down Expand Up @@ -1436,7 +1446,8 @@
breakdown_value
ORDER BY day_start ASC, breakdown_value ASC)
GROUP BY breakdown_value
ORDER BY sum(count) DESC, breakdown_value ASC
ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)),
sum(count) DESC, breakdown_value ASC
LIMIT 10000 SETTINGS readonly=2,
max_execution_time=60,
allow_experimental_object_type=1
Expand Down Expand Up @@ -1559,7 +1570,8 @@
breakdown_value
ORDER BY day_start ASC, breakdown_value ASC)
GROUP BY breakdown_value
ORDER BY sum(count) DESC, breakdown_value ASC
ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)),
sum(count) DESC, breakdown_value ASC
LIMIT 10000 SETTINGS readonly=2,
max_execution_time=60,
allow_experimental_object_type=1
Expand Down Expand Up @@ -1654,7 +1666,8 @@
breakdown_value
ORDER BY day_start ASC, breakdown_value ASC)
GROUP BY breakdown_value
ORDER BY sum(count) DESC, breakdown_value ASC
ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)),
sum(count) DESC, breakdown_value ASC
LIMIT 10000 SETTINGS readonly=2,
max_execution_time=60,
allow_experimental_object_type=1
Expand Down Expand Up @@ -2283,7 +2296,8 @@
breakdown_value
ORDER BY day_start ASC, breakdown_value ASC)
GROUP BY breakdown_value
ORDER BY sum(count) DESC, breakdown_value ASC
ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)),
sum(count) DESC, breakdown_value ASC
LIMIT 10000 SETTINGS readonly=2,
max_execution_time=60,
allow_experimental_object_type=1
Expand Down Expand Up @@ -2474,7 +2488,8 @@
breakdown_value
ORDER BY day_start ASC, breakdown_value ASC)
GROUP BY breakdown_value
ORDER BY sum(count) DESC, breakdown_value ASC
ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)),
sum(count) DESC, breakdown_value ASC
LIMIT 10000 SETTINGS readonly=2,
max_execution_time=60,
allow_experimental_object_type=1
Expand Down Expand Up @@ -2665,7 +2680,8 @@
breakdown_value
ORDER BY day_start ASC, breakdown_value ASC)
GROUP BY breakdown_value
ORDER BY sum(count) DESC, breakdown_value ASC
ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)),
sum(count) DESC, breakdown_value ASC
LIMIT 10000 SETTINGS readonly=2,
max_execution_time=60,
allow_experimental_object_type=1
Expand Down Expand Up @@ -3091,7 +3107,8 @@
breakdown_value
ORDER BY day_start ASC, breakdown_value ASC)
GROUP BY breakdown_value
ORDER BY sum(count) DESC, breakdown_value ASC
ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)),
sum(count) DESC, breakdown_value ASC
LIMIT 10000 SETTINGS readonly=2,
max_execution_time=60,
allow_experimental_object_type=1
Expand Down Expand Up @@ -3184,7 +3201,8 @@
breakdown_value
ORDER BY day_start ASC, breakdown_value ASC)
GROUP BY breakdown_value
ORDER BY sum(count) DESC, breakdown_value ASC
ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)),
sum(count) DESC, breakdown_value ASC
LIMIT 10000 SETTINGS readonly=2,
max_execution_time=60,
allow_experimental_object_type=1
Expand Down Expand Up @@ -3343,7 +3361,8 @@
breakdown_value
ORDER BY day_start ASC, breakdown_value ASC)
GROUP BY breakdown_value
ORDER BY sum(count) DESC, breakdown_value ASC
ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)),
sum(count) DESC, breakdown_value ASC
LIMIT 10000 SETTINGS readonly=2,
max_execution_time=60,
allow_experimental_object_type=1
Expand Down Expand Up @@ -3474,7 +3493,8 @@
breakdown_value
ORDER BY day_start ASC, breakdown_value ASC)
GROUP BY breakdown_value
ORDER BY sum(count) DESC, breakdown_value ASC
ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)),
sum(count) DESC, breakdown_value ASC
LIMIT 10000 SETTINGS readonly=2,
max_execution_time=60,
allow_experimental_object_type=1
Expand Down Expand Up @@ -3592,7 +3612,8 @@
ORDER BY day_start ASC, breakdown_value ASC)
ORDER BY day_start ASC)
GROUP BY breakdown_value
ORDER BY sum(count) DESC, breakdown_value ASC
ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)),
sum(count) DESC, breakdown_value ASC
LIMIT 10000 SETTINGS readonly=2,
max_execution_time=60,
allow_experimental_object_type=1
Expand Down Expand Up @@ -3657,7 +3678,8 @@
ORDER BY day_start ASC, breakdown_value ASC)
ORDER BY day_start ASC)
GROUP BY breakdown_value
ORDER BY sum(count) DESC, breakdown_value ASC
ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)),
sum(count) DESC, breakdown_value ASC
LIMIT 10000 SETTINGS readonly=2,
max_execution_time=60,
allow_experimental_object_type=1
Expand Down Expand Up @@ -3727,7 +3749,8 @@
ORDER BY day_start ASC, breakdown_value ASC)
ORDER BY day_start ASC)
GROUP BY breakdown_value
ORDER BY sum(count) DESC, breakdown_value ASC
ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)),
sum(count) DESC, breakdown_value ASC
LIMIT 10000 SETTINGS readonly=2,
max_execution_time=60,
allow_experimental_object_type=1
Expand Down Expand Up @@ -3796,7 +3819,8 @@
ORDER BY day_start ASC, breakdown_value ASC)
ORDER BY day_start ASC)
GROUP BY breakdown_value
ORDER BY sum(count) DESC, breakdown_value ASC
ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)),
sum(count) DESC, breakdown_value ASC
LIMIT 10000 SETTINGS readonly=2,
max_execution_time=60,
allow_experimental_object_type=1
Expand Down Expand Up @@ -4551,7 +4575,8 @@
breakdown_value
ORDER BY day_start ASC, breakdown_value ASC)
GROUP BY breakdown_value
ORDER BY sum(count) DESC, breakdown_value ASC
ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)),
sum(count) DESC, breakdown_value ASC
LIMIT 10000 SETTINGS readonly=2,
max_execution_time=60,
allow_experimental_object_type=1
Expand Down Expand Up @@ -4626,7 +4651,8 @@
breakdown_value
ORDER BY day_start ASC, breakdown_value ASC)
GROUP BY breakdown_value
ORDER BY sum(count) DESC, breakdown_value ASC
ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)),
sum(count) DESC, breakdown_value ASC
LIMIT 10000 SETTINGS readonly=2,
max_execution_time=60,
allow_experimental_object_type=1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@
breakdown_value
ORDER BY day_start ASC, breakdown_value ASC)
GROUP BY breakdown_value
ORDER BY sum(count) DESC, breakdown_value ASC
ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)),
sum(count) DESC, breakdown_value ASC
LIMIT 100 SETTINGS readonly=2,
max_execution_time=60,
allow_experimental_object_type=1
Expand Down Expand Up @@ -99,7 +100,8 @@
breakdown_value
ORDER BY day_start ASC, breakdown_value ASC)
GROUP BY breakdown_value
ORDER BY sum(count) DESC, breakdown_value ASC
ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)),
sum(count) DESC, breakdown_value ASC
LIMIT 100 SETTINGS readonly=2,
max_execution_time=60,
allow_experimental_object_type=1
Expand Down
Loading
Loading