Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(experiments): keep freeze exposure dialog open with loading state (#69683)

Marcel Poelkerd786bfc711a5
diff --git a/frontend/src/scenes/experiments/ExperimentView/ExperimentSceneMenuBar.tsx b/frontend/src/scenes/experiments/ExperimentView/ExperimentSceneMenuBar.tsx
index d4946c94e1f3..5bc7938408e8 100644
--- a/frontend/src/scenes/experiments/ExperimentView/ExperimentSceneMenuBar.tsx
+++ b/frontend/src/scenes/experiments/ExperimentView/ExperimentSceneMenuBar.tsx
@@ -1,4 +1,4 @@
-import { useActions, useValues } from 'kea'
+import { useActions, useAsyncActions, useValues } from 'kea'
import { router } from 'kea-router'
import { useState } from 'react'
@@ -83,10 +83,10 @@ function ExperimentSceneMenuBarInner(): JSX.Element | null {
createExposureCohort,
createExperimentDashboard,
resetRunningExperiment,
- freezeExposure,
- unfreezeExposure,
toggleDebugPanel,
} = useActions(experimentLogic)
+ // Promise-returning dispatch so the confirm dialogs can await completion (shouldAwaitSubmit).
+ const { freezeExposure, unfreezeExposure } = useAsyncActions(experimentLogic)
const { currentProjectId } = useValues(projectLogic)
const { currentOrganization } = useValues(organizationLogic)
const { openPauseExperimentModal, openResumeExperimentModal } = useActions(modalsLogic)
@@ -305,7 +305,7 @@ function ExperimentSceneMenuBarInner(): JSX.Element | null {
{showFreezeExposure && (
<SceneMenuBarItem
opensFloatingUi
- onClick={() => confirmFreezeExposure(freezeExposure)}
+ onClick={() => confirmFreezeExposure(() => freezeExposure())}
disabled={freezeExposureLoading}
tooltip={freezeExposureLoading ? 'Freezing exposure…' : undefined}
data-attr={`${RESOURCE_TYPE}-menubar-freeze-exposure`}
@@ -317,7 +317,7 @@ function ExperimentSceneMenuBarInner(): JSX.Element | null {
{isExperimentExposureFrozen(experiment) && (
<SceneMenuBarItem
opensFloatingUi
- onClick={() => confirmUnfreezeExposure(unfreezeExposure)}
+ onClick={() => confirmUnfreezeExposure(() => unfreezeExposure())}
disabled={unfreezeExposureLoading}
tooltip={unfreezeExposureLoading ? 'Unfreezing exposure…' : undefined}
data-attr={`${RESOURCE_TYPE}-menubar-unfreeze-exposure`}
diff --git a/frontend/src/scenes/experiments/ExperimentView/PageHeader.tsx b/frontend/src/scenes/experiments/ExperimentView/PageHeader.tsx
index 8100ffb66d88..b3de10126bb1 100644
--- a/frontend/src/scenes/experiments/ExperimentView/PageHeader.tsx
+++ b/frontend/src/scenes/experiments/ExperimentView/PageHeader.tsx
@@ -1,4 +1,4 @@
-import { useActions, useValues } from 'kea'
+import { useActions, useAsyncActions, useValues } from 'kea'
import { router } from 'kea-router'
import { useState } from 'react'
@@ -74,9 +74,9 @@ export function PageHeaderCustom(): JSX.Element {
createExperimentDashboard,
updateExperiment,
setHogfettiTrigger,
- freezeExposure,
- unfreezeExposure,
} = useActions(experimentLogic)
+ // Promise-returning dispatch so the confirm dialogs can await completion (shouldAwaitSubmit).
+ const { freezeExposure, unfreezeExposure } = useAsyncActions(experimentLogic)
const { currentProjectId } = useValues(projectLogic)
const { currentOrganization } = useValues(organizationLogic)
const hasMultipleProjects = (currentOrganization?.projects?.length ?? 0) > 1
@@ -267,7 +267,7 @@ export function PageHeaderCustom(): JSX.Element {
<ButtonPrimitive
menuItem
data-attr="freeze-exposure"
- onClick={() => confirmFreezeExposure(freezeExposure)}
+ onClick={() => confirmFreezeExposure(() => freezeExposure())}
disabledReasons={{
'Freezing exposure...': freezeExposureLoading,
}}
@@ -279,7 +279,7 @@ export function PageHeaderCustom(): JSX.Element {
<ButtonPrimitive
menuItem
data-attr="unfreeze-exposure"
- onClick={() => confirmUnfreezeExposure(unfreezeExposure)}
+ onClick={() => confirmUnfreezeExposure(() => unfreezeExposure())}
disabledReasons={{
'Unfreezing exposure...': unfreezeExposureLoading,
}}
diff --git a/frontend/src/scenes/experiments/experimentActions.tsx b/frontend/src/scenes/experiments/experimentActions.tsx
index 9f7cb857d909..6484e6c44400 100644
--- a/frontend/src/scenes/experiments/experimentActions.tsx
+++ b/frontend/src/scenes/experiments/experimentActions.tsx
@@ -46,7 +46,7 @@ export function canFreezeExposure(
)
}
-export function confirmFreezeExposure(onConfirm: () => void): void {
+export function confirmFreezeExposure(onConfirm: () => Promise<void>): void {
LemonDialog.open({
title: 'Freeze exposure?',
content: (
@@ -64,12 +64,14 @@ export function confirmFreezeExposure(onConfirm: () => void): void {
From a frozen state you can end an experiment or ship a variant at any time. You can unfreeze as
well to reopen enrollment.
</p>
+ <p>Freezing can take a little while on projects with many users, so keep this dialog open.</p>
</div>
),
+ shouldAwaitSubmit: true,
primaryButton: {
children: 'Freeze exposure',
type: 'primary',
- onClick: onConfirm,
+ onClick: () => onConfirm(),
size: 'small',
},
secondaryButton: {
@@ -80,7 +82,7 @@ export function confirmFreezeExposure(onConfirm: () => void): void {
})
}
-export function confirmUnfreezeExposure(onConfirm: () => void): void {
+export function confirmUnfreezeExposure(onConfirm: () => Promise<void>): void {
LemonDialog.open({
title: 'Unfreeze exposure?',
content: (
@@ -93,12 +95,14 @@ export function confirmUnfreezeExposure(onConfirm: () => void): void {
Heads up: users enrolled before the freeze and after the unfreeze joined at different times, which
can mix populations and cause bias in your results.
</p>
+ <p>Unfreezing can take a little while on projects with many users, so keep this dialog open.</p>
</div>
),
+ shouldAwaitSubmit: true,
primaryButton: {
children: 'Unfreeze exposure',
type: 'primary',
- onClick: onConfirm,
+ onClick: () => onConfirm(),
size: 'small',
},
secondaryButton: {