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

feat(experiments): support multiple primary metrics #26899

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
449 changes: 0 additions & 449 deletions frontend/src/scenes/experiments/ExperimentView/DeltaViz.tsx

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { WebExperimentImplementationDetails } from 'scenes/experiments/WebExperi

import { ExperimentImplementationDetails } from '../ExperimentImplementationDetails'
import { experimentLogic } from '../experimentLogic'
import { MetricsView } from '../MetricsView/MetricsView'
import {
ExperimentLoadingAnimation,
LoadingState,
Expand Down Expand Up @@ -49,6 +50,7 @@ const ResultsTab = (): JSX.Element => {
)}
</>
)}
<MetricsView />
<SecondaryMetricsTable experimentId={experiment.id} />
</div>
)
Expand Down
16 changes: 4 additions & 12 deletions frontend/src/scenes/experiments/ExperimentView/Goal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,7 @@ export function ExposureMetric({ experimentId }: { experimentId: Experiment['id'
export function Goal(): JSX.Element {
const { experiment, experimentId, getMetricType, experimentMathAggregationForTrends, hasGoalSet, featureFlags } =
useValues(experimentLogic)
const { setExperiment, loadExperiment } = useActions(experimentLogic)
const [isModalOpen, setIsModalOpen] = useState(false)
const { setExperiment, openPrimaryMetricModal } = useActions(experimentLogic)
const metricType = getMetricType(0)

return (
Expand Down Expand Up @@ -292,7 +291,7 @@ export function Goal(): JSX.Element {
filters: getDefaultFilters(InsightType.FUNNELS, undefined),
})
}
setIsModalOpen(true)
openPrimaryMetricModal(0)
}}
>
Add goal
Expand All @@ -318,7 +317,7 @@ export function Goal(): JSX.Element {
) : (
<MetricDisplayOld filters={experiment.filters} />
)}
<LemonButton size="xsmall" type="secondary" onClick={() => setIsModalOpen(true)}>
<LemonButton size="xsmall" type="secondary" onClick={() => openPrimaryMetricModal(0)}>
Change goal
</LemonButton>
</div>
Expand All @@ -334,14 +333,7 @@ export function Goal(): JSX.Element {
)}
</div>
)}
<PrimaryMetricModal
experimentId={experimentId}
isOpen={isModalOpen}
onClose={() => {
setIsModalOpen(false)
loadExperiment()
}}
/>
<PrimaryMetricModal experimentId={experimentId} />
</div>
)
}
5 changes: 1 addition & 4 deletions frontend/src/scenes/experiments/ExperimentView/Results.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
import '../Experiment.scss'

import { useValues } from 'kea'
import { FEATURE_FLAGS } from 'lib/constants'

import { experimentLogic } from '../experimentLogic'
import { ResultsHeader, ResultsQuery } from './components'
import { DeltaViz } from './DeltaViz'
import { SummaryTable } from './SummaryTable'

export function Results(): JSX.Element {
const { experimentResults, featureFlags } = useValues(experimentLogic)
const { experimentResults } = useValues(experimentLogic)

return (
<div>
<ResultsHeader />
<SummaryTable />
{featureFlags[FEATURE_FLAGS.EXPERIMENTS_MULTIPLE_METRICS] && <DeltaViz />}
<ResultsQuery targetResults={experimentResults} showTable={true} />
</div>
)
Expand Down
11 changes: 8 additions & 3 deletions frontend/src/scenes/experiments/Metrics/PrimaryGoalFunnels.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,16 @@ import {
} from './Selectors'
export function PrimaryGoalFunnels(): JSX.Element {
const { currentTeam } = useValues(teamLogic)
const { experiment, isExperimentRunning, featureFlags } = useValues(experimentLogic)
const { experiment, isExperimentRunning, featureFlags, editingPrimaryMetricIndex } = useValues(experimentLogic)
const { setExperiment, setFunnelsMetric } = useActions(experimentLogic)
const hasFilters = (currentTeam?.test_account_filters || []).length > 0

const metricIdx = 0
if (!editingPrimaryMetricIndex && editingPrimaryMetricIndex !== 0) {
console.warn('editingPrimaryMetricIndex is null or undefined')
return <></>
}

const metricIdx = editingPrimaryMetricIndex
const currentMetric = experiment.metrics[metricIdx] as ExperimentFunnelsQuery

const actionFilterProps = {
Expand Down Expand Up @@ -261,7 +266,7 @@ export function PrimaryGoalFunnels(): JSX.Element {
checked={(() => {
// :FLAG: CLEAN UP AFTER MIGRATION
if (featureFlags[FEATURE_FLAGS.EXPERIMENTS_HOGQL]) {
const val = (experiment.metrics[0] as ExperimentFunnelsQuery).funnels_query
const val = (experiment.metrics[metricIdx] as ExperimentFunnelsQuery).funnels_query
?.filterTestAccounts
return hasFilters ? !!val : false
}
Expand Down
9 changes: 7 additions & 2 deletions frontend/src/scenes/experiments/Metrics/PrimaryGoalTrends.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,17 @@ import { experimentLogic } from '../experimentLogic'
import { commonActionFilterProps } from './Selectors'

export function PrimaryGoalTrends(): JSX.Element {
const { experiment, isExperimentRunning, featureFlags } = useValues(experimentLogic)
const { experiment, isExperimentRunning, featureFlags, editingPrimaryMetricIndex } = useValues(experimentLogic)
const { setExperiment, setTrendsMetric } = useActions(experimentLogic)
const { currentTeam } = useValues(teamLogic)
const hasFilters = (currentTeam?.test_account_filters || []).length > 0

const metricIdx = 0
if (!editingPrimaryMetricIndex && editingPrimaryMetricIndex !== 0) {
console.warn('editingPrimaryMetricIndex is null or undefined')
return <></>
}

const metricIdx = editingPrimaryMetricIndex
const currentMetric = experiment.metrics[metricIdx] as ExperimentTrendsQuery
// :FLAG: CLEAN UP AFTER MIGRATION
const isDataWarehouseMetric =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,17 @@ import { experimentLogic } from '../experimentLogic'
import { commonActionFilterProps } from './Selectors'

export function PrimaryGoalTrendsExposure(): JSX.Element {
const { experiment, isExperimentRunning, featureFlags } = useValues(experimentLogic)
const { experiment, isExperimentRunning, featureFlags, editingPrimaryMetricIndex } = useValues(experimentLogic)
const { setExperiment, setTrendsExposureMetric } = useActions(experimentLogic)
const { currentTeam } = useValues(teamLogic)
const hasFilters = (currentTeam?.test_account_filters || []).length > 0
const currentMetric = experiment.metrics[0] as ExperimentTrendsQuery

if (!editingPrimaryMetricIndex && editingPrimaryMetricIndex !== 0) {
console.warn('editingPrimaryMetricIndex is null or undefined')
return <></>
}

const currentMetric = experiment.metrics[editingPrimaryMetricIndex] as ExperimentTrendsQuery

return (
<>
Expand All @@ -43,7 +49,7 @@ export function PrimaryGoalTrendsExposure(): JSX.Element {
)

setTrendsExposureMetric({
metricIdx: 0,
metricIdx: editingPrimaryMetricIndex,
series,
})
} else {
Expand Down Expand Up @@ -109,7 +115,7 @@ export function PrimaryGoalTrendsExposure(): JSX.Element {
// :FLAG: CLEAN UP AFTER MIGRATION
if (featureFlags[FEATURE_FLAGS.EXPERIMENTS_HOGQL]) {
setTrendsExposureMetric({
metricIdx: 0,
metricIdx: editingPrimaryMetricIndex,
filterTestAccounts: checked,
})
} else {
Expand Down
85 changes: 56 additions & 29 deletions frontend/src/scenes/experiments/Metrics/PrimaryMetricModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,25 @@ import { experimentLogic, getDefaultFilters, getDefaultFunnelsMetric, getDefault
import { PrimaryGoalFunnels } from '../Metrics/PrimaryGoalFunnels'
import { PrimaryGoalTrends } from '../Metrics/PrimaryGoalTrends'

export function PrimaryMetricModal({
experimentId,
isOpen,
onClose,
}: {
experimentId: Experiment['id']
isOpen: boolean
onClose: () => void
}): JSX.Element {
const { experiment, experimentLoading, getMetricType, featureFlags } = useValues(experimentLogic({ experimentId }))
const { updateExperimentGoal, setExperiment } = useActions(experimentLogic({ experimentId }))
export function PrimaryMetricModal({ experimentId }: { experimentId: Experiment['id'] }): JSX.Element {
const {
experiment,
experimentLoading,
getMetricType,
featureFlags,
isPrimaryMetricModalOpen,
editingPrimaryMetricIndex,
} = useValues(experimentLogic({ experimentId }))
const { updateExperimentGoal, setExperiment, updateExperiment, closePrimaryMetricModal } = useActions(
experimentLogic({ experimentId })
)

if (!editingPrimaryMetricIndex && editingPrimaryMetricIndex !== 0) {
console.warn('editingPrimaryMetricIndex is null or undefined')
return <></>
}

const metricIdx = 0
const metricIdx = editingPrimaryMetricIndex
const metricType = getMetricType(metricIdx)

let funnelStepsLength = 0
Expand All @@ -34,31 +40,52 @@ export function PrimaryMetricModal({

return (
<LemonModal
isOpen={isOpen}
onClose={onClose}
isOpen={isPrimaryMetricModalOpen}
onClose={closePrimaryMetricModal}
width={1000}
title="Change experiment goal"
footer={
<div className="flex items-center gap-2">
<LemonButton form="edit-experiment-goal-form" type="secondary" onClick={onClose}>
Cancel
</LemonButton>
<div className="flex items-center w-full">
<LemonButton
disabledReason={
metricType === InsightType.FUNNELS &&
funnelStepsLength < 2 &&
'The experiment needs at least two funnel steps.'
}
form="edit-experiment-goal-form"
type="secondary"
status="danger"
onClick={() => {
updateExperimentGoal(experiment.filters)
const newMetrics = experiment.metrics.filter((_, idx) => idx !== metricIdx)
setExperiment({
metrics: newMetrics,
})
updateExperiment({
metrics: newMetrics,
})
}}
type="primary"
loading={experimentLoading}
data-attr="create-annotation-submit"
>
Save
Delete
</LemonButton>
<div className="flex items-center gap-2 ml-auto">
<LemonButton
form="edit-experiment-goal-form"
type="secondary"
onClick={closePrimaryMetricModal}
>
Cancel
</LemonButton>
<LemonButton
disabledReason={
metricType === InsightType.FUNNELS &&
funnelStepsLength < 2 &&
'The experiment needs at least two funnel steps.'
}
form="edit-experiment-goal-form"
onClick={() => {
updateExperimentGoal(experiment.filters)
}}
type="primary"
loading={experimentLoading}
data-attr="create-annotation-submit"
>
Save
</LemonButton>
</div>
</div>
}
>
Expand Down
Loading
Loading