Skip to content

Commit

Permalink
chore(experiments): hogql migration cleanup - PrimaryGoalTrends (#27002)
Browse files Browse the repository at this point in the history
  • Loading branch information
andehen authored Dec 19, 2024
1 parent e264551 commit 8cd2f7c
Showing 1 changed file with 29 additions and 93 deletions.
122 changes: 29 additions & 93 deletions frontend/src/scenes/experiments/Metrics/PrimaryGoalTrends.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { LemonInput, LemonLabel } from '@posthog/lemon-ui'
import { useActions, useValues } from 'kea'
import { TestAccountFilterSwitch } from 'lib/components/TestAccountFiltersSwitch'
import { EXPERIMENT_DEFAULT_DURATION, FEATURE_FLAGS } from 'lib/constants'
import { EXPERIMENT_DEFAULT_DURATION } from 'lib/constants'
import { LemonBanner } from 'lib/lemon-ui/LemonBanner'
import { ActionFilter } from 'scenes/insights/filters/ActionFilter/ActionFilter'
import { MathAvailability } from 'scenes/insights/filters/ActionFilter/ActionFilterRow/ActionFilterRow'
import { teamLogic } from 'scenes/teamLogic'

import { actionsAndEventsToSeries, filtersToQueryNode } from '~/queries/nodes/InsightQuery/utils/filtersToQueryNode'
import { actionsAndEventsToSeries } from '~/queries/nodes/InsightQuery/utils/filtersToQueryNode'
import { queryNodeToFilter } from '~/queries/nodes/InsightQuery/utils/queryNodeToFilter'
import { Query } from '~/queries/Query/Query'
import { ExperimentTrendsQuery, NodeKind } from '~/queries/schema'
Expand All @@ -17,8 +17,8 @@ import { experimentLogic } from '../experimentLogic'
import { commonActionFilterProps } from './Selectors'

export function PrimaryGoalTrends(): JSX.Element {
const { experiment, isExperimentRunning, featureFlags, editingPrimaryMetricIndex } = useValues(experimentLogic)
const { setExperiment, setTrendsMetric } = useActions(experimentLogic)
const { experiment, isExperimentRunning, editingPrimaryMetricIndex } = useValues(experimentLogic)
const { setTrendsMetric } = useActions(experimentLogic)
const { currentTeam } = useValues(teamLogic)
const hasFilters = (currentTeam?.test_account_filters || []).length > 0

Expand All @@ -33,70 +33,30 @@ export function PrimaryGoalTrends(): JSX.Element {
<>
<div className="mb-4">
<LemonLabel>Name (optional)</LemonLabel>
{featureFlags[FEATURE_FLAGS.EXPERIMENTS_HOGQL] && (
<LemonInput
value={currentMetric.name}
onChange={(newName) => {
setTrendsMetric({
metricIdx,
name: newName,
})
}}
/>
)}
<LemonInput
value={currentMetric.name}
onChange={(newName) => {
setTrendsMetric({
metricIdx,
name: newName,
})
}}
/>
</div>
<ActionFilter
bordered
filters={(() => {
// :FLAG: CLEAN UP AFTER MIGRATION
if (featureFlags[FEATURE_FLAGS.EXPERIMENTS_HOGQL]) {
return queryNodeToFilter(currentMetric.count_query)
}
return experiment.filters
})()}
filters={queryNodeToFilter(currentMetric.count_query)}
setFilters={({ actions, events, data_warehouse }: Partial<FilterType>): void => {
// :FLAG: CLEAN UP AFTER MIGRATION
if (featureFlags[FEATURE_FLAGS.EXPERIMENTS_HOGQL]) {
const series = actionsAndEventsToSeries(
{ actions, events, data_warehouse } as any,
true,
MathAvailability.All
)
const series = actionsAndEventsToSeries(
{ actions, events, data_warehouse } as any,
true,
MathAvailability.All
)

setTrendsMetric({
metricIdx,
series,
})
} else {
if (actions?.length) {
setExperiment({
filters: {
...experiment.filters,
actions,
events: undefined,
data_warehouse: undefined,
},
})
} else if (events?.length) {
setExperiment({
filters: {
...experiment.filters,
events,
actions: undefined,
data_warehouse: undefined,
},
})
} else if (data_warehouse?.length) {
setExperiment({
filters: {
...experiment.filters,
data_warehouse,
actions: undefined,
events: undefined,
},
})
}
}
setTrendsMetric({
metricIdx,
series,
})
}}
typeKey="experiment-metric"
buttonCopy="Add graph series"
Expand All @@ -107,29 +67,12 @@ export function PrimaryGoalTrends(): JSX.Element {
/>
<div className="mt-4 space-y-4">
<TestAccountFilterSwitch
checked={(() => {
// :FLAG: CLEAN UP AFTER MIGRATION
if (featureFlags[FEATURE_FLAGS.EXPERIMENTS_HOGQL]) {
const val = currentMetric.count_query?.filterTestAccounts
return hasFilters ? !!val : false
}
return hasFilters ? !!experiment.filters.filter_test_accounts : false
})()}
checked={hasFilters ? !!currentMetric.count_query?.filterTestAccounts : false}
onChange={(checked: boolean) => {
// :FLAG: CLEAN UP AFTER MIGRATION
if (featureFlags[FEATURE_FLAGS.EXPERIMENTS_HOGQL]) {
setTrendsMetric({
metricIdx,
filterTestAccounts: checked,
})
} else {
setExperiment({
filters: {
...experiment.filters,
filter_test_accounts: checked,
},
})
}
setTrendsMetric({
metricIdx,
filterTestAccounts: checked,
})
}}
fullWidth
/>
Expand All @@ -141,17 +84,10 @@ export function PrimaryGoalTrends(): JSX.Element {
</LemonBanner>
)}
<div className="mt-4">
{/* :FLAG: CLEAN UP AFTER MIGRATION */}
<Query
query={{
kind: NodeKind.InsightVizNode,
source: (() => {
// :FLAG: CLEAN UP AFTER MIGRATION
if (featureFlags[FEATURE_FLAGS.EXPERIMENTS_HOGQL]) {
return currentMetric.count_query
}
return filtersToQueryNode(experiment.filters)
})(),
source: currentMetric.count_query,
showTable: false,
showLastComputation: true,
showLastComputationRefresh: false,
Expand Down

0 comments on commit 8cd2f7c

Please sign in to comment.