Skip to content

Commit

Permalink
chore(experiments): hogql migration cleanup - PrimaryGoalTrends
Browse files Browse the repository at this point in the history
  • Loading branch information
andehen committed Dec 18, 2024
1 parent 6dca54c commit 033bd4b
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 } = useValues(experimentLogic)
const { setExperiment, setTrendsMetric } = useActions(experimentLogic)
const { experiment, isExperimentRunning } = useValues(experimentLogic)
const { setTrendsMetric } = useActions(experimentLogic)
const { currentTeam } = useValues(teamLogic)
const hasFilters = (currentTeam?.test_account_filters || []).length > 0

Expand All @@ -29,70 +29,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 @@ -103,29 +63,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 @@ -137,17 +80,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 033bd4b

Please sign in to comment.