Skip to content

Commit

Permalink
implement trends actors frontend side
Browse files Browse the repository at this point in the history
  • Loading branch information
thmsobrmlr committed Feb 22, 2024
1 parent 18c1142 commit 804e5fd
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 30 deletions.
3 changes: 2 additions & 1 deletion frontend/src/queries/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1699,7 +1699,7 @@
"additionalProperties": false,
"properties": {
"funnelCustomSteps": {
"description": "Custom step numbers to get persons for. This overrides `funnelStep`.",
"description": "Custom step numbers to get persons for. This overrides `funnelStep`. Primarily for correlation use.",
"items": {
"type": "integer"
},
Expand All @@ -1717,6 +1717,7 @@
"type": "boolean"
},
"funnelTrendsEntrancePeriodStart": {
"description": "Used together with `funnelTrendsDropOff` for funnels time conversion date for the persons modal.",
"type": "string"
},
"includeRecordings": {
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/queries/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1083,12 +1083,13 @@ export interface FunnelsActorsQuery extends InsightActorsQueryBase {
/** Index of the step for which we want to get the timestamp for, per person.
* Positive for converted persons, negative for dropped of persons. */
funnelStep?: integer
/** Custom step numbers to get persons for. This overrides `funnelStep`. */
/** Custom step numbers to get persons for. This overrides `funnelStep`. Primarily for correlation use. */
funnelCustomSteps?: integer[]
/** The breakdown value for which to get persons for. This is an array for
* person and event properties, a string for groups and an integer for cohorts. */
funnelStepBreakdown?: BreakdownKeyType
funnelTrendsDropOff?: boolean
/** Used together with `funnelTrendsDropOff` for funnels time conversion date for the persons modal. */
funnelTrendsEntrancePeriodStart?: string
}

Expand Down
47 changes: 33 additions & 14 deletions frontend/src/scenes/funnels/FunnelLineGraph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { buildPeopleUrl } from 'scenes/trends/persons-modal/persons-modal-utils'
import { openPersonsModal } from 'scenes/trends/persons-modal/PersonsModal'

import { queryNodeToFilter } from '~/queries/nodes/InsightQuery/utils/queryNodeToFilter'
import { TrendsFilter } from '~/queries/schema'
import { FunnelsActorsQuery, NodeKind, TrendsFilter } from '~/queries/schema'
import { isInsightQueryNode } from '~/queries/utils'
import { ChartParams, GraphDataset, GraphType } from '~/types'

Expand All @@ -28,8 +28,15 @@ export function FunnelLineGraph({
showPersonsModal = true,
}: Omit<ChartParams, 'filters'>): JSX.Element | null {
const { insightProps } = useValues(insightLogic)
const { indexedSteps, aggregationTargetLabel, incompletenessOffsetFromEnd, interval, querySource, insightData } =
useValues(funnelDataLogic(insightProps))
const {
hogQLInsightsFunnelsFlagEnabled,
indexedSteps,
aggregationTargetLabel,
incompletenessOffsetFromEnd,
interval,
querySource,
insightData,
} = useValues(funnelDataLogic(insightProps))

if (!isInsightQueryNode(querySource)) {
return null
Expand Down Expand Up @@ -78,19 +85,31 @@ export function FunnelLineGraph({
const day = dataset?.days?.[index] ?? ''
const label = dataset?.label ?? dataset?.labels?.[index] ?? ''

const filters = queryNodeToFilter(querySource) // for persons modal
const personsUrl = buildPeopleUrl({
filters,
date_from: day ?? '',
response: insightData,
})
if (personsUrl) {
const title = `${capitalizeFirstLetter(
aggregationTargetLabel.plural
)} converted on ${dayjs(label).format('MMMM Do YYYY')}`

if (hogQLInsightsFunnelsFlagEnabled) {
const query: FunnelsActorsQuery = {
kind: NodeKind.InsightActorsQuery,
source: querySource,
funnelTrendsDropOff: false,
funnelTrendsEntrancePeriodStart: dayjs(day).format('YYYY-MM-DD HH:mm:ss'),
}
openPersonsModal({
url: personsUrl,
title: `${capitalizeFirstLetter(
aggregationTargetLabel.plural
)} converted on ${dayjs(label).format('MMMM Do YYYY')}`,
title,
query,
})
} else {
const filters = queryNodeToFilter(querySource) // for persons modal
const personsUrl = buildPeopleUrl({
filters,
date_from: day ?? '',
response: insightData,
})
if (personsUrl) {
openPersonsModal({ title, url: personsUrl })
}
}
}
}
Expand Down
11 changes: 10 additions & 1 deletion frontend/src/scenes/funnels/funnelDataLogic.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { actions, connect, kea, key, path, props, reducers, selectors } from 'kea'
import { BIN_COUNT_AUTO } from 'lib/constants'
import { BIN_COUNT_AUTO, FEATURE_FLAGS } from 'lib/constants'
import { dayjs } from 'lib/dayjs'
import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
import { average, percentage, sum } from 'lib/utils'
import { insightVizDataLogic } from 'scenes/insights/insightVizDataLogic'
import { keyForInsightLogicProps } from 'scenes/insights/sharedUtils'
Expand Down Expand Up @@ -61,6 +62,8 @@ export const funnelDataLogic = kea<funnelDataLogicType>([
],
groupsModel,
['aggregationLabel'],
featureFlagLogic,
['featureFlags'],
],
actions: [insightVizDataLogic(props), ['updateInsightFilter', 'updateQuerySource']],
})),
Expand All @@ -79,6 +82,12 @@ export const funnelDataLogic = kea<funnelDataLogicType>([
}),

selectors(() => ({
hogQLInsightsFunnelsFlagEnabled: [
(s) => [s.featureFlags],
(featureFlags): boolean => {
return !!featureFlags[FEATURE_FLAGS.HOGQL_INSIGHTS_FUNNELS]
},
],
querySource: [
(s) => [s.vizQuerySource],
(vizQuerySource) => (isFunnelsQuery(vizQuerySource) ? vizQuerySource : null),
Expand Down
12 changes: 1 addition & 11 deletions frontend/src/scenes/funnels/funnelPersonsModalLogic.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { actions, connect, kea, key, listeners, path, props, selectors } from 'kea'
import { FEATURE_FLAGS } from 'lib/constants'
import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
import { insightLogic } from 'scenes/insights/insightLogic'
import { keyForInsightLogicProps } from 'scenes/insights/sharedUtils'
import { funnelTitle } from 'scenes/trends/persons-modal/persons-modal-utils'
Expand Down Expand Up @@ -36,9 +34,7 @@ export const funnelPersonsModalLogic = kea<funnelPersonsModalLogicType>([
insightLogic(props),
['isInDashboardContext', 'isInExperimentContext'],
funnelDataLogic(props),
['steps', 'querySource', 'funnelsFilter'],
featureFlagLogic,
['featureFlags'],
['hogQLInsightsFunnelsFlagEnabled', 'steps', 'querySource', 'funnelsFilter'],
],
})),

Expand Down Expand Up @@ -82,12 +78,6 @@ export const funnelPersonsModalLogic = kea<funnelPersonsModalLogicType>([
return !isInDashboardContext && !funnelsFilter?.funnelAggregateByHogQL
},
],
hogQLInsightsFunnelsFlagEnabled: [
(s) => [s.featureFlags],
(featureFlags): boolean => {
return !!featureFlags[FEATURE_FLAGS.HOGQL_INSIGHTS_FUNNELS]
},
],
}),

listeners(({ values }) => ({
Expand Down
8 changes: 6 additions & 2 deletions posthog/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -2544,7 +2544,8 @@ class FunnelsActorsQuery(BaseModel):
extra="forbid",
)
funnelCustomSteps: Optional[List[int]] = Field(
default=None, description="Custom step numbers to get persons for. This overrides `funnelStep`."
default=None,
description="Custom step numbers to get persons for. This overrides `funnelStep`. Primarily for correlation use.",
)
funnelStep: Optional[int] = Field(
default=None,
Expand All @@ -2555,7 +2556,10 @@ class FunnelsActorsQuery(BaseModel):
description="The breakdown value for which to get persons for. This is an array for person and event properties, a string for groups and an integer for cohorts.",
)
funnelTrendsDropOff: Optional[bool] = None
funnelTrendsEntrancePeriodStart: Optional[str] = None
funnelTrendsEntrancePeriodStart: Optional[str] = Field(
default=None,
description="Used together with `funnelTrendsDropOff` for funnels time conversion date for the persons modal.",
)
includeRecordings: Optional[bool] = None
kind: Literal["InsightActorsQuery"] = "InsightActorsQuery"
response: Optional[ActorsQueryResponse] = None
Expand Down

0 comments on commit 804e5fd

Please sign in to comment.