Skip to content

Commit

Permalink
WIP handle new set metric
Browse files Browse the repository at this point in the history
  • Loading branch information
andehen committed Feb 11, 2025
1 parent 72990f2 commit ef82712
Showing 1 changed file with 15 additions and 17 deletions.
32 changes: 15 additions & 17 deletions frontend/src/scenes/experiments/Metrics/NewMetricForm.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import './TrendsMetricForm.scss'

import { LemonButton, LemonInput, LemonLabel } from '@posthog/lemon-ui'
import { LemonInput, LemonLabel } from '@posthog/lemon-ui'
import { useActions, useValues } from 'kea'
import { TestAccountFilterSwitch } from 'lib/components/TestAccountFiltersSwitch'
import { useState } from 'react'
import { ActionFilter } from 'scenes/insights/filters/ActionFilter/ActionFilter'
import { MathAvailability } from 'scenes/insights/filters/ActionFilter/ActionFilterRow/ActionFilterRow'
import { teamLogic } from 'scenes/teamLogic'

import { actionsAndEventsToSeries } from '~/queries/nodes/InsightQuery/utils/filtersToQueryNode'
import { Query } from '~/queries/Query/Query'
import { ExperimentQuery, NodeKind } from '~/queries/schema/schema-general'
import { ExperimentQuery, NodeKind, ExperimentMetricType } from '~/queries/schema/schema-general'
import { FilterType } from '~/types'

import { experimentLogic } from '../experimentLogic'
Expand All @@ -20,7 +18,7 @@ import { metricQueryToFilter } from '../utils'
export function NewMetricForm({ isSecondary = false }: { isSecondary?: boolean }): JSX.Element {
const { experiment, isExperimentRunning, editingPrimaryMetricIndex, editingSecondaryMetricIndex } =
useValues(experimentLogic)
const { setExperiment } = useActions(experimentLogic)
const { setMetric } = useActions(experimentLogic)
const { currentTeam } = useValues(teamLogic)
const hasFilters = (currentTeam?.test_account_filters || []).length > 0

Expand All @@ -34,23 +32,19 @@ export function NewMetricForm({ isSecondary = false }: { isSecondary?: boolean }
// Cast to unknown first to avoid type errors when transitioning to the new ExperimentQuery type
const currentMetric = metrics[metricIdx] as unknown as ExperimentQuery

const handleMetricChange = (updates: Partial<ExperimentQuery>): void => {
console.log('Metric change:', { metricIdx, updates, isSecondary })
const metricsField = isSecondary ? 'metrics_secondary' : 'metrics'
setExperiment({
...experiment,
[metricsField]: metrics.map((metric, idx) => (idx === metricIdx ? { ...metric, ...updates } : metric)),
})
}

return (
<>
<div className="mb-4">
<LemonLabel>Name (optional)</LemonLabel>
<LemonInput
value={currentMetric.name}
onChange={(newName) => {
handleMetricChange({ name: newName })
setMetric({
metricIdx,
name: newName,
metric: currentMetric.metric,
isSecondary,
})
}}
/>
</div>
Expand All @@ -61,9 +55,12 @@ export function NewMetricForm({ isSecondary = false }: { isSecondary?: boolean }
// We only support one event/action for experiment metrics
const entity = events?.[0] || actions?.[0]
if (entity) {
handleMetricChange({
setMetric({
metricIdx,
name: currentMetric.name,
metric: {
...currentMetric.metric,
kind: 'ExperimentMetric',
metric_type: ExperimentMetricType.COUNT,
metric_config: {
kind: 'ExperimentEventMetricConfig',
event: entity.id as string,
Expand All @@ -72,6 +69,7 @@ export function NewMetricForm({ isSecondary = false }: { isSecondary?: boolean }
math_hogql: entity.math_hogql,
},
},
isSecondary,
})
}
}}
Expand Down

0 comments on commit ef82712

Please sign in to comment.