: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(workflows): keep broadcast drafts with a custom recipient editable (#111077)
Daniel Marchuk58faec58e1dd
diff --git a/products/workflows/frontend/Broadcasts/BroadcastSummary.tsx b/products/workflows/frontend/Broadcasts/BroadcastSummary.tsxindex 89acc4e5fbcb..9016afd819ca 100644--- a/products/workflows/frontend/Broadcasts/BroadcastSummary.tsx+++ b/products/workflows/frontend/Broadcasts/BroadcastSummary.tsx@@ -20,6 +20,7 @@ import { LemonTabs } from 'lib/lemon-ui/LemonTabs'import { cn } from 'lib/utils/css-classes'import { humanFriendlyNumber } from 'lib/utils/numbers'import { capitalizeFirstLetter } from 'lib/utils/strings'+import { urls } from 'scenes/urls'import { SceneContent } from '~/layout/scenes/components/SceneContent'@@ -381,6 +382,19 @@ export function BroadcastSummary(): JSX.Element {<BroadcastSceneHeader nameSuffix={<BroadcastStatusTag status={summaryStatus} />} actions={actionsMenu} /><div className="mx-auto w-full max-w-6xl space-y-4">{broadcastPath(broadcastId) === 'composer' ? <ComposerDraftFeedback /> : null}+ {broadcast?.status === 'draft' ? (+ <LemonBanner+ type="info"+ action={{+ children: 'Open in workflow editor',+ to: urls.workflow(broadcastId ?? '', 'workflow'),+ 'data-attr': 'broadcast-draft-open-in-workflow-editor',+ }}+ >+ This draft has steps or an audience the broadcast editor can't show, so it opens here read-only.+ Edit it in the workflow editor.+ </LemonBanner>+ ) : null}{summaryStatus === 'failed' && !latestBatchJob && !batchJobsLoading ? (<LemonBannertype="warning"diff --git a/products/workflows/frontend/Broadcasts/broadcastWorkflowEdits.test.ts b/products/workflows/frontend/Broadcasts/broadcastWorkflowEdits.test.tsindex aa9f58cf8f5e..73307df309fb 100644--- a/products/workflows/frontend/Broadcasts/broadcastWorkflowEdits.test.ts+++ b/products/workflows/frontend/Broadcasts/broadcastWorkflowEdits.test.ts@@ -30,7 +30,8 @@ describe('broadcast edits to broadcast-shaped workflows', () => {it.each([['a person audience sent to each person', [trigger(), email(), exit], edges, true],['an account audience', [trigger({ audience_type: 'accounts', properties: [] }), email(), exit], edges, false],- ['a custom recipient expression', [trigger(), email('{{ inputs.owner_email }}'), exit], edges, false],+ ['a custom recipient expression', [trigger(), email('{{ inputs.owner_email }}'), exit], edges, true],+ ['a fixed recipient address', [trigger(), email('[email protected]'), exit], edges, true],['a trigger that skips the email',[trigger(), email(), exit],@@ -54,35 +55,28 @@ describe('broadcast edits to broadcast-shaped workflows', () => {HogFlowApi['status'],HogFlowScheduleApi['status'][],HogFlowBatchJobApi['status'][] | null,- string | undefined,+ boolean,boolean,]>([- ['a scheduled broadcast', 'active', ['active'], [], undefined, true],- ['a recurring broadcast between runs', 'active', ['active'], ['completed'], undefined, true],- ['a broadcast whose schedule was paused', 'active', ['paused'], [], undefined, true],- ['a broadcast sent right away', 'active', [], ['completed'], undefined, false],- ['a broadcast whose launch never finished', 'active', [], [], undefined, true],- ['a one-time broadcast that already sent', 'active', ['completed'], ['completed'], undefined, false],- ['a one-time schedule that never started a run', 'active', ['completed'], [], undefined, true],- [- 'a workflow with a sent one-time schedule and another',- 'active',- ['completed', 'active'],- [],- undefined,- false,- ],- ['a broadcast mid-send', 'active', ['active'], ['active'], undefined, false],- ['a broadcast with an older run still queued', 'active', ['active'], ['completed', 'queued'], undefined, false],- ['a broadcast whose runs have not loaded', 'active', ['active'], null, undefined, false],- ['a draft', 'draft', ['active'], [], undefined, false],- ['a workflow the wizard cannot edit', 'active', ['active'], [], '{{ inputs.owner }}', false],- ])('lets %s be stopped: %s', (_, status, scheduleStatuses, jobStatuses, recipient, expected) => {+ ['a scheduled broadcast', 'active', ['active'], [], false, true],+ ['a recurring broadcast between runs', 'active', ['active'], ['completed'], false, true],+ ['a broadcast whose schedule was paused', 'active', ['paused'], [], false, true],+ ['a broadcast sent right away', 'active', [], ['completed'], false, false],+ ['a broadcast whose launch never finished', 'active', [], [], false, true],+ ['a one-time broadcast that already sent', 'active', ['completed'], ['completed'], false, false],+ ['a one-time schedule that never started a run', 'active', ['completed'], [], false, true],+ ['a workflow with a sent one-time schedule and another', 'active', ['completed', 'active'], [], false, false],+ ['a broadcast mid-send', 'active', ['active'], ['active'], false, false],+ ['a broadcast with an older run still queued', 'active', ['active'], ['completed', 'queued'], false, false],+ ['a broadcast whose runs have not loaded', 'active', ['active'], null, false, false],+ ['a draft', 'draft', ['active'], [], false, false],+ ['a workflow the wizard cannot edit', 'active', ['active'], [], true, false],+ ])('lets %s be stopped: %s', (_, status, scheduleStatuses, jobStatuses, extraStep, expected) => {const broadcast: StoppableBroadcast = {status,schedules: scheduleStatuses.map((scheduleStatus) => ({ status: scheduleStatus })),- actions: [trigger(), email(recipient), exit],+ actions: extraStep ? [trigger(), email(), exit, { ...exit, id: 'exit_2' }] : [trigger(), email(), exit],edges,}const jobs = jobStatuses === null ? null : jobStatuses.map((jobStatus) => ({ status: jobStatus }))diff --git a/products/workflows/frontend/Broadcasts/broadcastsLogic.ts b/products/workflows/frontend/Broadcasts/broadcastsLogic.tsindex f79bb8276ed5..8f9e57c31f23 100644--- a/products/workflows/frontend/Broadcasts/broadcastsLogic.ts+++ b/products/workflows/frontend/Broadcasts/broadcastsLogic.ts@@ -76,14 +76,13 @@ export function isBroadcastShaped()}-const DEFAULT_RECIPIENT = '{{ person.properties.email }}'-type FlowStep = { id?: string; type?: string; config?: Record<string, any> }type FlowEdge = { from?: string; to?: string }/*** Whether the broadcast wizard can edit a broadcast-shaped workflow without misdescribing it. The- * wizard only models a person audience sent to each person's own email along trigger, email, exit;+ * wizard only models a person audience along trigger, email, exit. Its Content step edits the email's+ * "To" like any other field, so a custom recipient is fine;* anything else opens as the read-only summary instead.*/export function canEditInWizard(actions: FlowStep[] | null | undefined, edges: FlowEdge[] | null | undefined): boolean {@@ -95,13 +94,11 @@ export function canEditInWizard(actions: FlowStep[] | null | undefined, edges: Fif (steps.length !== 3 || trigger.length !== 1 || email.length !== 1 || exit.length !== 1) {return false}- const recipient = email[0].config?.inputs?.email?.value?.to?.email// Exactly trigger -> email -> exit: any other edge is a path the wizard cannot show, such as one// that skips the email.const paths = new Set((edges ?? []).map((edge) => `${edge.from}->${edge.to}`))return (trigger[0].config?.filters?.audience_type !== 'accounts' &&- (!recipient || recipient === DEFAULT_RECIPIENT) &&paths.size === 2 &&paths.has(`${trigger[0].id}->${email[0].id}`) &&paths.has(`${email[0].id}->${exit[0].id}`)diff --git a/products/workflows/frontend/Broadcasts/steps/BroadcastContentStep.tsx b/products/workflows/frontend/Broadcasts/steps/BroadcastContentStep.tsxindex 7314539cb4d1..1054e754f017 100644--- a/products/workflows/frontend/Broadcasts/steps/BroadcastContentStep.tsx+++ b/products/workflows/frontend/Broadcasts/steps/BroadcastContentStep.tsx@@ -100,6 +100,12 @@ export function BroadcastContentStep(): JSX.Element {variables={buildSampleGlobals({ type: 'batch' }, null)}fieldErrors={fieldErrors}/>+ {email.to?.email && !email.to.email.includes('{{') ? (+ <span className="text-xs text-warning" data-attr="broadcast-fixed-recipient-hint">+ Every email in this broadcast goes to {email.to.email}, not to each person in the audience. Use{' '}+ <code>{'{{ person.properties.email }}'}</code> to send each person their own email.+ </span>+ ) : null}<LemonSwitchlabel="Track opens and link clicks"checked={emailSettings.trackingEnabled}