Skip to content

Commit

Permalink
chore(experiments): hogql migration cleanup - SecondaryMetricModal (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
andehen authored Dec 19, 2024
1 parent fc875b3 commit e264551
Showing 1 changed file with 24 additions and 61 deletions.
85 changes: 24 additions & 61 deletions frontend/src/scenes/experiments/Metrics/SecondaryMetricModal.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { LemonButton, LemonModal, LemonSelect } from '@posthog/lemon-ui'
import { useActions, useValues } from 'kea'
import { FEATURE_FLAGS } from 'lib/constants'

import { Experiment, InsightType } from '~/types'

import { experimentLogic, getDefaultFilters, getDefaultFunnelsMetric, getDefaultTrendsMetric } from '../experimentLogic'
import { experimentLogic, getDefaultFunnelsMetric, getDefaultTrendsMetric } from '../experimentLogic'
import { SecondaryGoalFunnels } from './SecondaryGoalFunnels'
import { SecondaryGoalTrends } from './SecondaryGoalTrends'

Expand All @@ -19,9 +18,7 @@ export function SecondaryMetricModal({
isOpen: boolean
onClose: () => void
}): JSX.Element {
const { experiment, experimentLoading, getSecondaryMetricType, featureFlags } = useValues(
experimentLogic({ experimentId })
)
const { experiment, experimentLoading, getSecondaryMetricType } = useValues(experimentLogic({ experimentId }))
const { setExperiment, updateExperiment } = useActions(experimentLogic({ experimentId }))
const metricType = getSecondaryMetricType(metricIdx)

Expand All @@ -37,28 +34,15 @@ export function SecondaryMetricModal({
type="secondary"
status="danger"
onClick={() => {
// :FLAG: CLEAN UP AFTER MIGRATION
if (featureFlags[FEATURE_FLAGS.EXPERIMENTS_HOGQL]) {
const newMetricsSecondary = experiment.metrics_secondary.filter(
(_, idx) => idx !== metricIdx
)
setExperiment({
metrics_secondary: newMetricsSecondary,
})
updateExperiment({
metrics_secondary: newMetricsSecondary,
})
} else {
const newSecondaryMetrics = experiment.secondary_metrics.filter(
(_, idx) => idx !== metricIdx
)
setExperiment({
secondary_metrics: newSecondaryMetrics,
})
updateExperiment({
secondary_metrics: newSecondaryMetrics,
})
}
const newMetricsSecondary = experiment.metrics_secondary.filter(
(_, idx) => idx !== metricIdx
)
setExperiment({
metrics_secondary: newMetricsSecondary,
})
updateExperiment({
metrics_secondary: newMetricsSecondary,
})
}}
>
Delete
Expand All @@ -69,16 +53,9 @@ export function SecondaryMetricModal({
</LemonButton>
<LemonButton
onClick={() => {
// :FLAG: CLEAN UP AFTER MIGRATION
if (featureFlags[FEATURE_FLAGS.EXPERIMENTS_HOGQL]) {
updateExperiment({
metrics_secondary: experiment.metrics_secondary,
})
} else {
updateExperiment({
secondary_metrics: experiment.secondary_metrics,
})
}
updateExperiment({
metrics_secondary: experiment.metrics_secondary,
})
}}
type="primary"
loading={experimentLoading}
Expand All @@ -96,30 +73,16 @@ export function SecondaryMetricModal({
data-attr="metrics-selector"
value={metricType}
onChange={(newMetricType) => {
// :FLAG: CLEAN UP AFTER MIGRATION
if (featureFlags[FEATURE_FLAGS.EXPERIMENTS_HOGQL]) {
setExperiment({
...experiment,
metrics_secondary: [
...experiment.metrics_secondary.slice(0, metricIdx),
newMetricType === InsightType.TRENDS
? getDefaultTrendsMetric()
: getDefaultFunnelsMetric(),
...experiment.metrics_secondary.slice(metricIdx + 1),
],
})
} else {
setExperiment({
...experiment,
secondary_metrics: [
...experiment.secondary_metrics.slice(0, metricIdx),
newMetricType === InsightType.TRENDS
? { name: '', filters: getDefaultFilters(InsightType.TRENDS, undefined) }
: { name: '', filters: getDefaultFilters(InsightType.FUNNELS, undefined) },
...experiment.secondary_metrics.slice(metricIdx + 1),
],
})
}
setExperiment({
...experiment,
metrics_secondary: [
...experiment.metrics_secondary.slice(0, metricIdx),
newMetricType === InsightType.TRENDS
? getDefaultTrendsMetric()
: getDefaultFunnelsMetric(),
...experiment.metrics_secondary.slice(metricIdx + 1),
],
})
}}
options={[
{ value: InsightType.TRENDS, label: <b>Trends</b> },
Expand Down

0 comments on commit e264551

Please sign in to comment.