From 31d432628d12b6342555158ce1b605fb1ef98ee4 Mon Sep 17 00:00:00 2001 From: Anders Asheim Hennum Date: Wed, 18 Dec 2024 08:30:39 +0100 Subject: [PATCH] chore(experiments): hogql migration cleanup - PrimaryGoalFunnels --- .../Metrics/PrimaryGoalFunnels.tsx | 267 ++++-------------- 1 file changed, 60 insertions(+), 207 deletions(-) diff --git a/frontend/src/scenes/experiments/Metrics/PrimaryGoalFunnels.tsx b/frontend/src/scenes/experiments/Metrics/PrimaryGoalFunnels.tsx index 50468541a0d9b..366063753c813 100644 --- a/frontend/src/scenes/experiments/Metrics/PrimaryGoalFunnels.tsx +++ b/frontend/src/scenes/experiments/Metrics/PrimaryGoalFunnels.tsx @@ -3,18 +3,18 @@ import { LemonInput } from '@posthog/lemon-ui' import { useActions, useValues } from 'kea' import { TaxonomicFilterGroupType } from 'lib/components/TaxonomicFilter/types' 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 { getHogQLValue } from 'scenes/insights/filters/AggregationSelect' 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 { ExperimentFunnelsQuery, NodeKind } from '~/queries/schema' -import { BreakdownAttributionType, FilterType, FunnelsFilterType } from '~/types' +import { BreakdownAttributionType, FilterType } from '~/types' import { experimentLogic } from '../experimentLogic' import { @@ -25,8 +25,8 @@ import { } from './Selectors' export function PrimaryGoalFunnels(): JSX.Element { const { currentTeam } = useValues(teamLogic) - const { experiment, isExperimentRunning, featureFlags } = useValues(experimentLogic) - const { setExperiment, setFunnelsMetric } = useActions(experimentLogic) + const { experiment, isExperimentRunning } = useValues(experimentLogic) + const { setFunnelsMetric } = useActions(experimentLogic) const hasFilters = (currentTeam?.test_account_filters || []).length > 0 const metricIdx = 0 @@ -42,70 +42,30 @@ export function PrimaryGoalFunnels(): JSX.Element { <>
Name (optional) - {featureFlags[FEATURE_FLAGS.EXPERIMENTS_HOGQL] && ( - { - setFunnelsMetric({ - metricIdx, - name: newName, - }) - }} - /> - )} + { + setFunnelsMetric({ + metricIdx, + name: newName, + }) + }} + />
{ - // :FLAG: CLEAN UP AFTER MIGRATION - if (featureFlags[FEATURE_FLAGS.EXPERIMENTS_HOGQL]) { - return queryNodeToFilter(currentMetric.funnels_query) - } - return experiment.filters - })()} + filters={queryNodeToFilter(currentMetric.funnels_query)} setFilters={({ actions, events, data_warehouse }: Partial): void => { - // :FLAG: CLEAN UP AFTER MIGRATION - if (featureFlags[FEATURE_FLAGS.EXPERIMENTS_HOGQL]) { - const series = actionsAndEventsToSeries( - { actions, events, data_warehouse } as any, - true, - MathAvailability.None - ) + const series = actionsAndEventsToSeries( + { actions, events, data_warehouse } as any, + true, + MathAvailability.None + ) - setFunnelsMetric({ - 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, - }, - }) - } - } + setFunnelsMetric({ + metricIdx, + series, + }) }} typeKey="experiment-metric" mathAvailability={MathAvailability.None} @@ -118,100 +78,39 @@ export function PrimaryGoalFunnels(): JSX.Element { />
{ - // :FLAG: CLEAN UP AFTER MIGRATION - if (featureFlags[FEATURE_FLAGS.EXPERIMENTS_HOGQL]) { - return getHogQLValue( - currentMetric.funnels_query.aggregation_group_type_index ?? undefined, - currentMetric.funnels_query.funnelsFilter?.funnelAggregateByHogQL ?? undefined - ) - } - return getHogQLValue( - experiment.filters.aggregation_group_type_index, - (experiment.filters as FunnelsFilterType).funnel_aggregate_by_hogql - ) - })()} + value={getHogQLValue( + currentMetric.funnels_query.aggregation_group_type_index ?? undefined, + currentMetric.funnels_query.funnelsFilter?.funnelAggregateByHogQL ?? undefined + )} onChange={(value) => { - // :FLAG: CLEAN UP AFTER MIGRATION - if (featureFlags[FEATURE_FLAGS.EXPERIMENTS_HOGQL]) { - setFunnelsMetric({ - metricIdx, - funnelAggregateByHogQL: value, - }) - } else { - setExperiment({ - filters: { - ...experiment.filters, - funnel_aggregate_by_hogql: value, - }, - }) - } + setFunnelsMetric({ + metricIdx, + funnelAggregateByHogQL: value, + }) }} /> { - // :FLAG: CLEAN UP AFTER MIGRATION - if (featureFlags[FEATURE_FLAGS.EXPERIMENTS_HOGQL]) { - return currentMetric.funnels_query?.funnelsFilter?.funnelWindowInterval - } - return (experiment.filters as FunnelsFilterType).funnel_window_interval - })()} - funnelWindowIntervalUnit={(() => { - // :FLAG: CLEAN UP AFTER MIGRATION - if (featureFlags[FEATURE_FLAGS.EXPERIMENTS_HOGQL]) { - return currentMetric.funnels_query?.funnelsFilter?.funnelWindowIntervalUnit - } - return (experiment.filters as FunnelsFilterType).funnel_window_interval_unit - })()} + funnelWindowInterval={currentMetric.funnels_query?.funnelsFilter?.funnelWindowInterval} + funnelWindowIntervalUnit={currentMetric.funnels_query?.funnelsFilter?.funnelWindowIntervalUnit} onFunnelWindowIntervalChange={(funnelWindowInterval) => { - // :FLAG: CLEAN UP AFTER MIGRATION - if (featureFlags[FEATURE_FLAGS.EXPERIMENTS_HOGQL]) { - setFunnelsMetric({ - metricIdx, - funnelWindowInterval: funnelWindowInterval, - }) - } else { - setExperiment({ - filters: { - ...experiment.filters, - funnel_window_interval: funnelWindowInterval, - }, - }) - } + setFunnelsMetric({ + metricIdx, + funnelWindowInterval: funnelWindowInterval, + }) }} onFunnelWindowIntervalUnitChange={(funnelWindowIntervalUnit) => { - // :FLAG: CLEAN UP AFTER MIGRATION - if (featureFlags[FEATURE_FLAGS.EXPERIMENTS_HOGQL]) { - setFunnelsMetric({ - metricIdx, - funnelWindowIntervalUnit: funnelWindowIntervalUnit || undefined, - }) - } else { - setExperiment({ - filters: { - ...experiment.filters, - funnel_window_interval_unit: funnelWindowIntervalUnit || undefined, - }, - }) - } + setFunnelsMetric({ + metricIdx, + funnelWindowIntervalUnit: funnelWindowIntervalUnit || undefined, + }) }} /> { - // :FLAG: CLEAN UP AFTER MIGRATION - let breakdownAttributionType - let breakdownAttributionValue - if (featureFlags[FEATURE_FLAGS.EXPERIMENTS_HOGQL]) { - breakdownAttributionType = - currentMetric.funnels_query?.funnelsFilter?.breakdownAttributionType - breakdownAttributionValue = - currentMetric.funnels_query?.funnelsFilter?.breakdownAttributionValue - } else { - breakdownAttributionType = (experiment.filters as FunnelsFilterType) - .breakdown_attribution_type - breakdownAttributionValue = (experiment.filters as FunnelsFilterType) - .breakdown_attribution_value - } + const breakdownAttributionType = + currentMetric.funnels_query?.funnelsFilter?.breakdownAttributionType + const breakdownAttributionValue = + currentMetric.funnels_query?.funnelsFilter?.breakdownAttributionValue const currentValue: BreakdownAttributionType | `${BreakdownAttributionType.Step}/${number}` = !breakdownAttributionType @@ -224,64 +123,25 @@ export function PrimaryGoalFunnels(): JSX.Element { })()} onChange={(value) => { const [breakdownAttributionType, breakdownAttributionValue] = (value || '').split('/') - // :FLAG: CLEAN UP AFTER MIGRATION - if (featureFlags[FEATURE_FLAGS.EXPERIMENTS_HOGQL]) { - setFunnelsMetric({ - metricIdx, - breakdownAttributionType: breakdownAttributionType as BreakdownAttributionType, - breakdownAttributionValue: breakdownAttributionValue - ? parseInt(breakdownAttributionValue) - : undefined, - }) - } else { - setExperiment({ - filters: { - ...experiment.filters, - breakdown_attribution_type: breakdownAttributionType as BreakdownAttributionType, - breakdown_attribution_value: breakdownAttributionValue - ? parseInt(breakdownAttributionValue) - : 0, - }, - }) - } + setFunnelsMetric({ + metricIdx, + breakdownAttributionType: breakdownAttributionType as BreakdownAttributionType, + breakdownAttributionValue: breakdownAttributionValue + ? parseInt(breakdownAttributionValue) + : undefined, + }) }} stepsLength={(() => { - // :FLAG: CLEAN UP AFTER MIGRATION - if (featureFlags[FEATURE_FLAGS.EXPERIMENTS_HOGQL]) { - return currentMetric.funnels_query?.series?.length - } - return Math.max( - experiment.filters.actions?.length ?? 0, - experiment.filters.events?.length ?? 0, - experiment.filters.data_warehouse?.length ?? 0 - ) + return currentMetric.funnels_query?.series?.length })()} /> { - // :FLAG: CLEAN UP AFTER MIGRATION - if (featureFlags[FEATURE_FLAGS.EXPERIMENTS_HOGQL]) { - const val = (experiment.metrics[0] as ExperimentFunnelsQuery).funnels_query - ?.filterTestAccounts - return hasFilters ? !!val : false - } - return hasFilters ? !!experiment.filters.filter_test_accounts : false - })()} + checked={hasFilters ? !!currentMetric.funnels_query?.filterTestAccounts : false} onChange={(checked: boolean) => { - // :FLAG: CLEAN UP AFTER MIGRATION - if (featureFlags[FEATURE_FLAGS.EXPERIMENTS_HOGQL]) { - setFunnelsMetric({ - metricIdx, - filterTestAccounts: checked, - }) - } else { - setExperiment({ - filters: { - ...experiment.filters, - filter_test_accounts: checked, - }, - }) - } + setFunnelsMetric({ + metricIdx, + filterTestAccounts: checked, + }) }} fullWidth /> @@ -293,17 +153,10 @@ export function PrimaryGoalFunnels(): JSX.Element { )}
- {/* :FLAG: CLEAN UP AFTER MIGRATION */} { - // :FLAG: CLEAN UP AFTER MIGRATION - if (featureFlags[FEATURE_FLAGS.EXPERIMENTS_HOGQL]) { - return currentMetric.funnels_query - } - return filtersToQueryNode(experiment.filters) - })(), + source: currentMetric.funnels_query, showTable: false, showLastComputation: true, showLastComputationRefresh: false,