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

chore(experiments): hogql migration cleanup - PrimaryGoalTrends #27002

Merged
merged 1 commit into from
Dec 19, 2024
Merged
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
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
Loading