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(workflows): let the editor zoom out further and show branch audience size (#77563)

jake sciotto061a81908a96
diff --git a/products/workflows/frontend/Workflows/hogflows/HogFlowEditor.tsx b/products/workflows/frontend/Workflows/hogflows/HogFlowEditor.tsx
index 68d81cdd18e8..cb4ee9bc7edb 100644
--- a/products/workflows/frontend/Workflows/hogflows/HogFlowEditor.tsx
+++ b/products/workflows/frontend/Workflows/hogflows/HogFlowEditor.tsx
@@ -21,6 +21,7 @@ import { themeLogic } from '~/layout/navigation-3000/themeLogic'
import { workflowLogic } from '../workflowLogic'
import { hogFlowEditorLogic } from './hogFlowEditorLogic'
import { HogFlowEditorPanel } from './panel/HogFlowEditorPanel'
+import { LOW_DETAIL_ZOOM, MIN_ZOOM } from './react_flow_utils/constants'
import { REACT_FLOW_EDGE_TYPES } from './react_flow_utils/SmartEdge'
import { REACT_FLOW_NODE_TYPES } from './steps/Nodes'
import { HogFlowActionEdge, HogFlowActionNode } from './types'
@@ -29,7 +30,7 @@ import { HogFlowActionEdge, HogFlowActionNode } from './types'
function HogFlowEditorContent(): JSX.Element {
const { isDarkModeOn } = useValues(themeLogic)
- const { nodes, edges, dropzoneNodes, isMovingNode, isCopyingNode } = useValues(hogFlowEditorLogic)
+ const { nodes, edges, dropzoneNodes, isMovingNode, isCopyingNode, isZoomedOutFar } = useValues(hogFlowEditorLogic)
const {
onEdgesChange,
onNodesChange,
@@ -41,6 +42,7 @@ function HogFlowEditorContent(): JSX.Element {
onDrop,
setReactFlowWrapper,
handlePaneClick,
+ setIsZoomedOutFar,
} = useActions(hogFlowEditorLogic)
const reactFlowWrapper = useRef<HTMLDivElement>(null)
@@ -66,6 +68,15 @@ function HogFlowEditorContent(): JSX.Element {
<ReactFlow<HogFlowActionNode, HogFlowActionEdge>
className="grow"
fitView
+ minZoom={MIN_ZOOM}
+ // Only dispatched when the detail tier flips, so panning and zooming don't put a
+ // Redux action on every animation frame.
+ onMove={(_, viewport) => {
+ const zoomedOutFar = viewport.zoom < LOW_DETAIL_ZOOM
+ if (zoomedOutFar !== isZoomedOutFar) {
+ setIsZoomedOutFar(zoomedOutFar)
+ }
+ }}
nodes={nodesWithDropzones}
edges={edges}
onNodesChange={onNodesChange}
diff --git a/products/workflows/frontend/Workflows/hogflows/hogFlowEditorLogic.tsx b/products/workflows/frontend/Workflows/hogflows/hogFlowEditorLogic.tsx
index 66e137a103c3..867887b8dccf 100644
--- a/products/workflows/frontend/Workflows/hogflows/hogFlowEditorLogic.tsx
+++ b/products/workflows/frontend/Workflows/hogflows/hogFlowEditorLogic.tsx
@@ -172,6 +172,7 @@ export interface hogFlowEditorLogicValues {
highlightedDropzoneNodeId: string | null
isCopyingNode: boolean
isMovingNode: boolean
+ isZoomedOutFar: boolean
mode: HogFlowEditorMode
movingNodeId: string | null
nodeToBeAdded: CreateActionType | HogFlowActionNode | null
@@ -1886,6 +1887,9 @@ export interface hogFlowEditorLogicActions {
setHighlightedDropzoneNodeId: (highlightedDropzoneNodeId: string | null) => {
highlightedDropzoneNodeId: string | null
}
+ setIsZoomedOutFar: (isZoomedOutFar: boolean) => {
+ isZoomedOutFar: boolean
+ }
setMode: (mode: HogFlowEditorMode) => {
mode: 'build' | 'logs' | 'metrics' | 'test' | 'variables'
}
@@ -2004,6 +2008,7 @@ export const hogFlowEditorLogic = kea<hogFlowEditorLogicType>([
) => ({ params, timezone }),
fitView: (options: { duration?: number; noZoom?: boolean } = {}) => options,
handlePaneClick: true,
+ setIsZoomedOutFar: (isZoomedOutFar: boolean) => ({ isZoomedOutFar }),
}),
reducers(() => ({
mode: [
@@ -2056,6 +2061,12 @@ export const hogFlowEditorLogic = kea<hogFlowEditorLogicType>([
stopMovingNode: () => false,
},
],
+ isZoomedOutFar: [
+ false,
+ {
+ setIsZoomedOutFar: (_, { isZoomedOutFar }) => isZoomedOutFar,
+ },
+ ],
movingNodeId: [
null as string | null,
{
diff --git a/products/workflows/frontend/Workflows/hogflows/react_flow_utils/constants.ts b/products/workflows/frontend/Workflows/hogflows/react_flow_utils/constants.ts
index 4b1d02824336..1c02bb6edbb3 100644
--- a/products/workflows/frontend/Workflows/hogflows/react_flow_utils/constants.ts
+++ b/products/workflows/frontend/Workflows/hogflows/react_flow_utils/constants.ts
@@ -10,6 +10,14 @@ export const MINIMUM_EDGE_SPACING = 170
export const NODE_EDGE_GAP = MINIMUM_EDGE_SPACING - 1
export const NODE_LAYER_GAP = 75
+// React Flow defaults to a 0.5 floor, which isn't enough to fit a wide branching workflow on screen.
+// This also raises the ceiling on the initial fitView, which is bounded by the instance's minZoom.
+export const MIN_ZOOM = 0.1
+
+// Below this, a node's description renders as an illegible smudge (it's 0.3rem at zoom 1), so we drop
+// it and leave the node as a labelled block for reading the overall shape of the workflow.
+export const LOW_DETAIL_ZOOM = 0.4
+
export const TOP_HANDLE_POSITION = {
x: NODE_WIDTH / 2,
y: 0,
diff --git a/products/workflows/frontend/Workflows/hogflows/steps/StepConditionalBranch.tsx b/products/workflows/frontend/Workflows/hogflows/steps/StepConditionalBranch.tsx
index c56164d576a2..c6b4e29c7915 100644
--- a/products/workflows/frontend/Workflows/hogflows/steps/StepConditionalBranch.tsx
+++ b/products/workflows/frontend/Workflows/hogflows/steps/StepConditionalBranch.tsx
@@ -3,17 +3,68 @@ import { useActions, useValues } from 'kea'
import { useMemo } from 'react'
import { IconPlus, IconX } from '@posthog/icons'
+import { Spinner, Tooltip } from '@posthog/lemon-ui'
import { LemonButton } from 'lib/lemon-ui/LemonButton'
import { LemonField } from 'lib/lemon-ui/LemonField'
import { LemonInput } from 'lib/lemon-ui/LemonInput'
import { LemonLabel } from 'lib/lemon-ui/LemonLabel'
+import { humanFriendlyNumber } from 'lib/utils/numbers'
import { HogFlowPropertyFilters } from '../filters/HogFlowFilters'
import { hogFlowEditorLogic } from '../hogFlowEditorLogic'
import { HogFlow, HogFlowAction } from '../types'
+import { batchTriggerLogic } from './batchTriggerLogic'
import { StepSchemaErrors } from './components/StepSchemaErrors'
-import { getBranchRemovalDisabledReason, removeBranchEdge, useDebouncedNameInputs } from './utils'
+import { getBranchRemovalDisabledReason, isCountableCondition, removeBranchEdge, useDebouncedNameInputs } from './utils'
+
+type ConditionFilters = Extract<
+ HogFlowAction,
+ { type: 'conditional_branch' }
+>['config']['conditions'][number]['filters']
+
+function ConditionAudienceEstimate({
+ actionId,
+ index,
+ filters,
+}: {
+ actionId: string
+ index: number
+ filters: ConditionFilters
+}): JSX.Element | null {
+ // Counting persons, not sends, so this deliberately skips the email dedup the batch trigger applies.
+ const { blastRadius, blastRadiusLoading, blastRadiusError } = useValues(
+ batchTriggerLogic({
+ id: `${actionId}-condition-${index}`,
+ filters: { properties: filters?.properties ?? [] },
+ })
+ )
+
+ if (blastRadiusLoading) {
+ return <Spinner className="text-xs" />
+ }
+
+ // A failed estimate is not worth interrupting the person over: the condition itself is still valid.
+ if (blastRadiusError || !blastRadius) {
+ return null
+ }
+
+ const { affected, total } = blastRadius
+ if (affected == null || total == null || total === 0) {
+ return null
+ }
+
+ const percentage = (affected / total) * 100
+ const roundedPercentage = percentage > 0 && percentage < 1 ? '<1' : humanFriendlyNumber(percentage, 1)
+
+ return (
+ <Tooltip title="Share of all persons matching this condition right now. Each person is checked again when they reach this step.">
+ <span className="text-xs text-muted whitespace-nowrap">
+ {roundedPercentage}% of persons ({humanFriendlyNumber(affected)} of {humanFriendlyNumber(total)})
+ </span>
+ </Tooltip>
+ )
+}
export function StepConditionalBranchConfiguration({
node,
@@ -86,8 +137,17 @@ export function StepConditionalBranchConfiguration({
<StepSchemaErrors />
{conditions.map((condition, index) => (
<div key={index} className="flex flex-col gap-2 p-2 rounded border">
- <div className="flex justify-between items-center">
- <LemonLabel>Condition {index + 1}</LemonLabel>
+ <div className="flex justify-between items-center gap-2">
+ <div className="flex items-center gap-2 min-w-0">
+ <LemonLabel>Condition {index + 1}</LemonLabel>
+ {isCountableCondition(condition.filters) && (
+ <ConditionAudienceEstimate
+ actionId={action.id}
+ index={index}
+ filters={condition.filters}
+ />
+ )}
+ </div>
<LemonButton
size="xsmall"
icon={<IconX />}
diff --git a/products/workflows/frontend/Workflows/hogflows/steps/components/StepView.tsx b/products/workflows/frontend/Workflows/hogflows/steps/components/StepView.tsx
index a27ff01dfeb5..b40e32211e69 100644
--- a/products/workflows/frontend/Workflows/hogflows/steps/components/StepView.tsx
+++ b/products/workflows/frontend/Workflows/hogflows/steps/components/StepView.tsx
@@ -28,6 +28,7 @@ export function StepView({ action }: { action: HogFlowAction }): JSX.Element {
selectedNodeCanBeCopiedOrMoved,
animatingEdgePair,
workflow,
+ isZoomedOutFar,
} = useValues(hogFlowEditorLogic)
const { setSelectedNodeId, startCopyingNode, startMovingNode } = useActions(hogFlowEditorLogic)
const { actionValidationErrorsById, logicProps, scheduleState, scheduleStartsAt, isScheduleRepeating } =
@@ -184,7 +185,7 @@ export function StepView({ action }: { action: HogFlowAction }): JSX.Element {
className="text-[0.3rem] text-muted !bg-transparent !border-0 !shadow-none !p-0 !px-1 !m-0 !min-h-0 !max-h-[0.9rem] !leading-[0.45rem] !resize-none !overflow-hidden !rounded-sm"
/>
</div>
- ) : (
+ ) : isZoomedOutFar ? null : (
<Tooltip title={scheduleDescription ?? action.description ?? ''}>
<div
className={`text-[0.3rem]/1.5 text-muted line-clamp-2 !rounded-sm px-0.5 -mx-0.5 transition-colors pl-1 min-w-0 min-h-[0.45rem] overflow-hidden ${isSelected && !isScheduleTrigger(action) ? 'cursor-text hover:bg-fill-button-tertiary-hover' : ''}`}
diff --git a/products/workflows/frontend/Workflows/hogflows/steps/utils.test.ts b/products/workflows/frontend/Workflows/hogflows/steps/utils.test.ts
index ba7edaae6469..d9dc086fd851 100644
--- a/products/workflows/frontend/Workflows/hogflows/steps/utils.test.ts
+++ b/products/workflows/frontend/Workflows/hogflows/steps/utils.test.ts
@@ -1,6 +1,7 @@
import {
cohortPercentagesAddUp,
getBranchRemovalDisabledReason,
+ isCountableCondition,
normalizeCohortPercentages,
parseCohortPercentage,
removeBranchEdge,
@@ -392,4 +393,50 @@ describe('utils', () => {
expect(result).toEqual([])
})
})
+
+ describe('isCountableCondition', () => {
+ it.each([
+ {
+ case: 'person properties only',
+ properties: [{ type: 'person', key: 'plan', value: 'free' }],
+ expected: true,
+ },
+ { case: 'a cohort reference', properties: [{ type: 'cohort', key: 'id', value: 42 }], expected: true },
+ {
+ case: 'person and cohort mixed',
+ properties: [
+ { type: 'person', key: 'plan' },
+ { type: 'cohort', key: 'id' },
+ ],
+ expected: true,
+ },
+ // An event property is evaluated against the triggering event, so counting persons would
+ // report a percentage that answers a different question than the one asked.
+ { case: 'an event property', properties: [{ type: 'event', key: '$current_url' }], expected: false },
+ {
+ case: 'a person property alongside an event property',
+ properties: [{ type: 'person' }, { type: 'event' }],
+ expected: false,
+ },
+ {
+ case: 'a group property',
+ properties: [{ type: 'group', key: 'name', group_type_index: 0 }],
+ expected: false,
+ },
+ { case: 'a feature flag property', properties: [{ type: 'feature', key: 'my-flag' }], expected: false },
+ {
+ case: 'a HogQL expression',
+ properties: [{ type: 'hogql', key: "properties.plan = 'free'" }],
+ expected: false,
+ },
+ { case: 'an empty property row', properties: [{}], expected: false },
+ { case: 'no properties', properties: [], expected: false },
+ ])('$case -> $expected', ({ properties, expected }) => {
+ expect(isCountableCondition({ properties })).toBe(expected)
+ })
+
+ it.each([[undefined], [null], [{}]])('returns false for missing filters (%s)', (filters) => {
+ expect(isCountableCondition(filters)).toBe(false)
+ })
+ })
})
diff --git a/products/workflows/frontend/Workflows/hogflows/steps/utils.ts b/products/workflows/frontend/Workflows/hogflows/steps/utils.ts
index d2d773fac7ef..83b8c6bbed0d 100644
--- a/products/workflows/frontend/Workflows/hogflows/steps/utils.ts
+++ b/products/workflows/frontend/Workflows/hogflows/steps/utils.ts
@@ -1,10 +1,29 @@
import { useEffect, useState } from 'react'
import { useDebouncedCallback } from 'use-debounce'
+import { AnyPropertyFilter, PropertyFilterType } from '~/types'
+
import { HogFlow } from '../types'
type HogFlowEdge = HogFlow['edges'][number]
+// The audience endpoint compiles filters against the persons table, so only person-scoped properties
+// resolve. An event or group property comes back as a validation error rather than a count.
+const COUNTABLE_PROPERTY_TYPES: string[] = [PropertyFilterType.Person, PropertyFilterType.Cohort]
+
+/**
+ * Whether a branch condition's filters can be counted as a share of persons. A condition evaluated
+ * against an event rather than a person would produce a misleading percentage, so it gets no estimate.
+ */
+export function isCountableCondition(filters?: { properties?: unknown[] } | null): boolean {
+ const properties = (filters?.properties ?? []) as AnyPropertyFilter[]
+ // An unconfigured condition matches everyone, so an estimate of it carries no information.
+ if (properties.length === 0) {
+ return false
+ }
+ return properties.every((property) => property.type != null && COUNTABLE_PROPERTY_TYPES.includes(property.type))
+}
+
/**
* Check whether removing a branch edge at the given condition index would
* orphan its target node (i.e. the target has no other incoming edges).