Skip to content

Commit

Permalink
Merge branch 'master' into tom/bi-feats
Browse files Browse the repository at this point in the history
  • Loading branch information
Gilbert09 committed Aug 5, 2024
2 parents eb5b236 + 472536a commit b858e62
Show file tree
Hide file tree
Showing 62 changed files with 3,069 additions and 3,017 deletions.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion frontend/src/lib/lemon-ui/LemonSwitch/LemonSwitch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export interface LemonSwitchProps {
/** Like plain `disabled`, except we enforce a reason to be shown in the tooltip. */
disabledReason?: string | null | false
'data-attr'?: string
tooltip?: string | null
tooltip?: string | JSX.Element | null
handleContent?: React.ReactElement | null
'aria-label'?: string
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,44 @@ describe('actionsAndEventsToSeries', () => {

expect(result[0].kind).toEqual(NodeKind.EventsNode)
})

it('converts funnels math types', () => {
const actions: ActionFilter[] = [
{ type: 'actions', id: '1', order: 0, name: 'item1', math: 'total' },
{ type: 'actions', id: '1', order: 1, name: 'item2', math: 'first_time_for_user' },
]
const events: ActionFilter[] = [
{ id: '$pageview', type: 'events', order: 2, name: 'item3', math: 'total' },
{ id: '$autocapture', type: 'events', order: 3, name: 'item4', math: 'first_time_for_user' },
]

const result = actionsAndEventsToSeries({ events, actions }, false, MathAvailability.FunnelsOnly)

expect(result).toEqual([
{
kind: NodeKind.ActionsNode,
id: '1',
name: 'item1',
},
{
kind: NodeKind.ActionsNode,
id: '1',
name: 'item2',
math: BaseMathType.FirstTimeForUser,
},
{
kind: NodeKind.EventsNode,
event: '$pageview',
name: 'item3',
},
{
kind: NodeKind.EventsNode,
event: '$autocapture',
name: 'item4',
math: BaseMathType.FirstTimeForUser,
},
])
})
})

describe('hiddenLegendKeysToIndexes', () => {
Expand Down Expand Up @@ -598,6 +636,27 @@ describe('filtersToQueryNode', () => {
}
expect(result).toEqual(query)
})

it('converts math type', () => {
const filters: Partial<FunnelsFilterType> = {
events: [{ id: '$pageview', type: 'events', order: 0, math: BaseMathType.FirstTimeForUser }],
insight: InsightType.FUNNELS,
}

const result = filtersToQueryNode(filters)

const query: FunnelsQuery = {
kind: NodeKind.FunnelsQuery,
series: [
{
kind: NodeKind.EventsNode,
event: '$pageview',
math: BaseMathType.FirstTimeForUser,
},
],
}
expect(result).toEqual(query)
})
})

describe('retention filter', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
InsightQueryNode,
InsightsQueryBase,
LifecycleFilter,
MathType,
NodeKind,
PathsFilter,
RetentionFilter,
Expand Down Expand Up @@ -83,6 +84,8 @@ const actorsOnlyMathTypes = [
HogQLMathType.HogQL,
]

const funnelsMathTypes = [BaseMathType.FirstTimeForUser]

type FilterTypeActionsAndEvents = {
events?: ActionFilter[]
actions?: ActionFilter[]
Expand Down Expand Up @@ -122,6 +125,13 @@ export const legacyEntityToNode = (
...shared,
math: BaseMathType.UniqueUsers,
}
} else if (mathAvailability === MathAvailability.FunnelsOnly) {
if (funnelsMathTypes.includes(entity.math as any)) {
shared = {
...shared,
math: entity.math as MathType,
}
}
} else {
shared = {
...shared,
Expand Down Expand Up @@ -283,6 +293,8 @@ export const filtersToQueryNode = (filters: Partial<FilterType>): InsightQueryNo
includeMath = MathAvailability.All
} else if (isStickinessQuery(query)) {
includeMath = MathAvailability.ActorsOnly
} else if (isFunnelsQuery(query)) {
includeMath = MathAvailability.FunnelsOnly
}

const { events, actions, data_warehouse } = filters
Expand Down
19 changes: 13 additions & 6 deletions frontend/src/scenes/insights/EditorFilters/FunnelsQuerySteps.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { useActions, useValues } from 'kea'
import { TaxonomicFilterGroupType } from 'lib/components/TaxonomicFilter/types'
import { FEATURE_FLAGS } from 'lib/constants'
import { LemonLabel } from 'lib/lemon-ui/LemonLabel/LemonLabel'
import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
import { MathAvailability } from 'scenes/insights/filters/ActionFilter/ActionFilterRow/ActionFilterRow'
import { insightVizDataLogic } from 'scenes/insights/insightVizDataLogic'
import { keyForInsightLogicProps } from 'scenes/insights/sharedUtils'
Expand All @@ -23,19 +25,24 @@ export function FunnelsQuerySteps({ insightProps }: EditorFilterProps): JSX.Elem
const { series, querySource } = useValues(insightVizDataLogic(insightProps))
const { updateQuerySource } = useActions(insightVizDataLogic(insightProps))

if (!isInsightQueryNode(querySource)) {
return null
}
const { featureFlags } = useValues(featureFlagLogic)
const mathAvailability = featureFlags[FEATURE_FLAGS.FIRST_TIME_FOR_USER_MATH]
? MathAvailability.FunnelsOnly
: MathAvailability.None

const actionFilters = queryNodeToFilter(querySource)
const actionFilters = isInsightQueryNode(querySource) ? queryNodeToFilter(querySource) : null
const setActionFilters = (payload: Partial<FilterType>): void => {
updateQuerySource({
series: actionsAndEventsToSeries(payload as any, true, MathAvailability.None),
series: actionsAndEventsToSeries(payload as any, true, mathAvailability),
} as FunnelsQuery)
}

const { groupsTaxonomicTypes, showGroupsOptions } = useValues(groupsModel)

if (!actionFilters) {
return null
}

const filterSteps = series || []
const showSeriesIndicator = (series || []).length > 0

Expand All @@ -55,7 +62,7 @@ export function FunnelsQuerySteps({ insightProps }: EditorFilterProps): JSX.Elem
filters={actionFilters}
setFilters={setActionFilters}
typeKey={keyForInsightLogicProps('new')(insightProps)}
mathAvailability={MathAvailability.None}
mathAvailability={mathAvailability}
hideDeleteBtn={filterSteps.length === 1}
buttonCopy="Add step"
showSeriesIndicator={showSeriesIndicator}
Expand Down
Loading

0 comments on commit b858e62

Please sign in to comment.