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

fix(experiments): clean query nodes for experiment insights #21128

Merged
merged 1 commit into from
Mar 25, 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
13 changes: 11 additions & 2 deletions frontend/src/scenes/experiments/experimentLogic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { urls } from 'scenes/urls'
import { groupsModel } from '~/models/groupsModel'
import { filtersToQueryNode } from '~/queries/nodes/InsightQuery/utils/filtersToQueryNode'
import { queryNodeToFilter } from '~/queries/nodes/InsightQuery/utils/queryNodeToFilter'
import { InsightVizNode } from '~/queries/schema'
import { FunnelsQuery, InsightVizNode, TrendsQuery } from '~/queries/schema'
import {
ActionFilter as ActionFilterType,
Breadcrumb,
Expand Down Expand Up @@ -382,7 +382,16 @@ export const experimentLogic = kea<experimentLogicType>([
})
}

actions.updateQuerySource(filtersToQueryNode(newInsightFilters))
// This allows switching between insight types. It's necessary as `updateQuerySource` merges
// the new query with any existing query and that causes validation problems when there are
// unsupported properties in the now merged query.
const newQuery = filtersToQueryNode(newInsightFilters)
if (filters?.insight === InsightType.FUNNELS) {
;(newQuery as TrendsQuery).trendsFilter = undefined
} else {
;(newQuery as FunnelsQuery).funnelsFilter = undefined
}
actions.updateQuerySource(newQuery)
},
// sync form value `filters` with query
setQuery: ({ query }) => {
Expand Down
13 changes: 11 additions & 2 deletions frontend/src/scenes/experiments/secondaryMetricsLogic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { teamLogic } from 'scenes/teamLogic'

import { filtersToQueryNode } from '~/queries/nodes/InsightQuery/utils/filtersToQueryNode'
import { queryNodeToFilter } from '~/queries/nodes/InsightQuery/utils/queryNodeToFilter'
import { InsightVizNode } from '~/queries/schema'
import { FunnelsQuery, InsightVizNode, TrendsQuery } from '~/queries/schema'
import { Experiment, FilterType, FunnelVizType, InsightType, SecondaryExperimentMetric } from '~/types'

import { SECONDARY_METRIC_INSIGHT_ID } from './constants'
Expand Down Expand Up @@ -162,7 +162,16 @@ export const secondaryMetricsLogic = kea<secondaryMetricsLogicType>([
})
}

actions.updateQuerySource(filtersToQueryNode(newInsightFilters))
// This allows switching between insight types. It's necessary as `updateQuerySource` merges
// the new query with any existing query and that causes validation problems when there are
// unsupported properties in the now merged query.
const newQuery = filtersToQueryNode(newInsightFilters)
if (filters?.insight === InsightType.FUNNELS) {
;(newQuery as TrendsQuery).trendsFilter = undefined
} else {
;(newQuery as FunnelsQuery).funnelsFilter = undefined
}
actions.updateQuerySource(newQuery)
},
// sync form value `filters` with query
setQuery: ({ query }) => {
Expand Down
Loading