: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
feat(workflows): clarify paths in the linear editor (#102419)
Daniel Marchukc660d0fc76ef
diff --git a/frontend/snapshots.yml b/frontend/snapshots.ymlindex 9d99bfc22539..1d61833bdcce 100644--- a/frontend/snapshots.yml+++ b/frontend/snapshots.yml@@ -6729,9 +6729,9 @@ snapshots:products-workflows-editor-configuration-panel--cohort-branch--light:hash: v1.k794b7964.4fd0f6ff9c17a685913afb00d14a5804d28eac0f4dbe5b89ab2b60c9258d757f.dGeUSO7-kt1SuNSTiOTtQ0yWrCXD3wWCrJ0JkzXqPHQproducts-workflows-editor-configuration-panel--conditional-branch--dark:- hash: v1.k794b7964.28ef96bdb240694b8b0786bccdeec07dffc677410a0977d2b16d7794ccc85c14.cVh6dFIr01Hi6QIOwO31L9RqOP4rLQJUHKMucRSdljE+ hash: v1.k794b7964.1eb79775e70860dc633e482b88508c068b4d58c7215e66c934843917ffb77a35.E5WSfkL1VqIXna_-48aVNC5ob6HVZdbK8cOe31xs5RAproducts-workflows-editor-configuration-panel--conditional-branch--light:- hash: v1.k794b7964.cf5243dc2191758d2b098416822df172ac32e54c51f7b8ff5d441fa54cdf9501.PUjF_kDSbjW4Kd9AJGy1JSIwipvVVWu4tZ4QSL9TumA+ hash: v1.k794b7964.3691f905593cd2084ec01847e80b3eeda4c834bd1c34a9d0f37e2d36db9c5f0c.2xvXivEkevaUXKSag8wYob1Hi2ZyfxUcr7VE46qW50wproducts-workflows-editor-configuration-panel--email--dark:hash: v1.k794b7964.8bd1cbc2e385de536325edd73c88c9d7ca6c469d14c6801f9cf5893fbf59f363.I7QY9S5gNoHyFoLb41azlksnSKoKvszQM0s_BqKPkNEproducts-workflows-editor-configuration-panel--email--light:@@ -6789,13 +6789,17 @@ snapshots:products-workflows-editor-graph--support-sla-routing--light:hash: v1.k794b7964.96264d77ca9e5d4897c48f8552d051ab6a414675e9a5d62b1878c40955e60a12.veQ0qlbkuVu45XgikLqMm6GhiTqaU-iYLBAUuvq-W_oproducts-workflows-editor-tree--add-on-promotion-emails--dark:- hash: v1.k794b7964.3f467ba43f620a6ab76627e3c2bcab8fba80fb995b3985058c276913dcf87fd8.a4q6H9DcziTVWvaV9s2WmxTDidmAS4QRhedWvPFYmIU+ hash: v1.k794b7964.f28f743921b108a3d7ce5c5f7f373407609e4f131790261d27afd7107909381f.Ji6HKS277Nou8dc2Ow4IG0TDdXKMQOCiNg6StWNB1Kcproducts-workflows-editor-tree--add-on-promotion-emails--light:- hash: v1.k794b7964.b2655d00c1332a5690e80b1aa9202312670a815f62a517e4c750b2cb9d61ce33.AAngxEes0W4TfS91rLR6QoYQ4v6SvirOmoomVFSd6fs+ hash: v1.k794b7964.d9492ca9c5923da55188d7827e6cd6e34359a1b42059a52133c06aa6115d1385.G_Bm0tdhNcMCg6pf4IvqqMtAYDDacZ1hC6VjaZ7WOQ0products-workflows-editor-tree--customer-onboarding-and-retention--dark:- hash: v1.k794b7964.f716dbc29bbc783c8306945a6552b9f92a7870012ec585f8045b4880c4277561.rFS529pMFqmTgOTnEC9L8Qui5n0aOBp7PHjwSew5zbU+ hash: v1.k794b7964.a1eea512dceef0734f0230262b0d9bbba86ad6dd1c30d18060ad86792da2c691.TcDujKWIKFMZLUe5CIB5zKf9UrMq7DbGmswP5W3fnzEproducts-workflows-editor-tree--customer-onboarding-and-retention--light:- hash: v1.k794b7964.43771fde6f41243f9f49b5b13e548f7f868b3963a40b4d215498911aeabbbca8.RnWWanLedM9xmYvdqVYR0f6fz-QJqzyFU0EstvxUPv8+ hash: v1.k794b7964.9751d8128711d7a67ed4792016eb9c6deb42272fcb39ec7697386d5e09e7a79a.pGWmJ5TxOhMzVDbd3qlmr41uZc-LUWHP81TqzgQzf0s+ products-workflows-editor-tree--narrow-customer-onboarding-and-retention--dark:+ hash: v1.k794b7964.59326f730d2663850a2c564c195229980b90b6acf9ef3b90bce018d7f3912aa1.RlRzWe8X0Tz75sv8hiW9G7wwVMpEp3Y_4WU5I-LdTxs+ products-workflows-editor-tree--narrow-customer-onboarding-and-retention--light:+ hash: v1.k794b7964.08bd055172418c2107be4d819e1befa05ef9ff190ffa8b1e837cc749a70e570b.BnHwELtbqNAlGLSF8aRzFzkOnAQZwa2RSxPODpxF97sproducts-workflows-editor-tree--narrow-workflow--dark:hash: v1.k794b7964.5987a1e8ac93211af4c06f3f437f67ace8a6cd85792f6bc808db270ca9755590.8iPtpr3uRGPKFkTO6uSb5Fc6HTdcoRpJy9O68FlnZOEproducts-workflows-editor-tree--narrow-workflow--light:@@ -6805,17 +6809,17 @@ snapshots:products-workflows-editor-tree--new-workflow--light:hash: v1.k794b7964.ff0bba1e26b26956788b9fa0a2981a79beaf9f4d762b5bbd30357c2dfca44987.uBlKUX22jca_ikhP9gzNrHPg0CmpY2aRIv5gcp3ZIvEproducts-workflows-editor-tree--pending-ticket-cleanup--dark:- hash: v1.k794b7964.ef29c76df282d635c19053eb5c4a8470756f223b3253972a5d035526432b9cc8.Nq2mwLceLrO_aON4h4tr_vJTveIIejvHeu5exfS4LBk+ hash: v1.k794b7964.eb803061f2c9f5ab389be0db9abc77f7cc0e0bf632b4442cfab86e0868ec51ff.uB0vmBKsSLmqC9teiRnsev4dOQzHbcIsXZ6IWrVYLpkproducts-workflows-editor-tree--pending-ticket-cleanup--light:- hash: v1.k794b7964.9a4ff3b1ae20df23ddbb53230f54d9577f259bc978582666c222a89caf1e37fd.YBn19jcB_KLQCWH7lVIAdbT5WC5TuVicFxQZTR298w4+ hash: v1.k794b7964.0deac6edd44774bd90f3a2f53153fef80bc8422b9d4f252bc93e3b294c70fdec.4NhpHZXe0L2-iDtNAR3QzOKYS9A-MsGCSTPitzLC1isproducts-workflows-editor-tree--renewal-window-alerts--dark:- hash: v1.k794b7964.5e2fb6d30a2f0c538bd6ded0bc7a8f4b5dba3074c72902939c5172e21cddc405._gaDonn4sfpv_54B4TJTUCmCEsnHcHFaXdGNHGeuezA+ hash: v1.k794b7964.5fa5bdf0d05e60dc842eb90c199a6c842c72735df0118402e4743567d7d79c43.81698-6VLZyI6eFw2Cy6jXhqbOcUQaEQga-rUuUQEkkproducts-workflows-editor-tree--renewal-window-alerts--light:- hash: v1.k794b7964.0ff004435bb78b67c5ca5db63507f2d1e6b7c5419e1976b9d5d38adb2c96f471.-822Wv6pUIIAxwDwXaL2zxhMdF68Vgu4POQPlAJyp6c+ hash: v1.k794b7964.652d3b0b171d3f4407cc62a1af91bbe039cde7151166fccaa7cd49a44ba5a742.o48dp58JkyBVTNALRE0PfYOnsFXqly4J1Jw83U0bVPEproducts-workflows-editor-tree--support-sla-routing--dark:- hash: v1.k794b7964.0c9cc82caa488aa7884e030738dddd072d4114978f2b9d3225f710457274b2b8.8taKWaKNwFQr1Z0OYIzI0xApEDAl-rVGa4A87G7csdU+ hash: v1.k794b7964.a331ac11a24a5b09d04cb05bfa2bc27aae0eec8c9a7ce4f9b7f981b0795db88e.zY2D1OKwi3IDdgtzUmOVzF0gkvQVzGKpnK3J_tiBdMMproducts-workflows-editor-tree--support-sla-routing--light:- hash: v1.k794b7964.24439cc151709b993cc5ad3169593b1d621fdfbabc53a9407bc831cfef833392.aXfXmLBVCcdgFpb3x-lRtyUAXd11jCSjgbn6X0CgyT8+ hash: v1.k794b7964.16c77e09a6f8f58899e2eaf9d7cb463e03b6d7147dc70bccd874dca76614c97d.I0bPsqygUl6Tl0MOMdWcQVPJ8xYt5xt-KpGM_kuWdfEproducts-workflows-reputation--domain-withheld-from-caller--dark:hash: v1.k794b7964.c2e39d5fe9b32f1b638e90e39ce2cce629ade26846acc2d2530fa8c89986d4ec.un8cpP-nRmKMMaLVxSAP7vc-2PZ1zELYwqHEgXQ33L8products-workflows-reputation--domain-withheld-from-caller--light:diff --git a/products/workflows/frontend/Workflows/hogflows/steps/StepConditionalBranch.tsx b/products/workflows/frontend/Workflows/hogflows/steps/StepConditionalBranch.tsxindex ef9f895513aa..75a21911fcda 100644--- a/products/workflows/frontend/Workflows/hogflows/steps/StepConditionalBranch.tsx+++ b/products/workflows/frontend/Workflows/hogflows/steps/StepConditionalBranch.tsx@@ -136,6 +136,7 @@ export function StepConditionalBranchConfiguration({return (<div className="flex flex-col gap-3"><StepSchemaErrors />+ <p className="mb-0 text-secondary">Conditions run from top to bottom. The first match sets the path.</p>{conditions.map((condition, index) => {return (<HogFlowBranchCarddiff --git a/products/workflows/frontend/Workflows/hogflows/tree/HogFlowTreeBranch.tsx b/products/workflows/frontend/Workflows/hogflows/tree/HogFlowTreeBranch.tsxnew file mode 100644index 000000000000..f80a34ec332b--- /dev/null+++ b/products/workflows/frontend/Workflows/hogflows/tree/HogFlowTreeBranch.tsx@@ -0,0 +1,200 @@+import { useActions } from 'kea'+import type { CSSProperties, ReactNode } from 'react'++import { IconArrowRight, IconChevronDown, IconEllipsis } from '@posthog/icons'++import PropertyFiltersDisplay from 'lib/components/PropertyFilters/components/PropertyFiltersDisplay'+import { LemonButton } from 'lib/lemon-ui/LemonButton'+import { LemonMenu } from 'lib/lemon-ui/LemonMenu'+import { LemonTag } from 'lib/lemon-ui/LemonTag'+import { cn } from 'lib/utils/css-classes'++import { getHogFlowBranchColor, useHogFlowBranchSelection } from '../HogFlowBranchSelection'+import { hogFlowEditorLogic } from '../hogFlowEditorLogic'+import type { HogFlowEdge } from '../types'+import { HogFlowTreeBranchConnector } from './HogFlowTreeBranchConnector'+import { getWaitTimeoutLabel, type WorkflowTreeBranch, type WorkflowTreeNode } from './workflowTree'+import { getWorkflowTreeBranchSummary, getWorkflowTreeOccurrenceKey } from './workflowTreePresentation'++export function HogFlowTreeBranch({+ node,+ branch,+ index,+ isLast,+ branchCollapsed,+ onToggleCollapsed,+ onFocusBranch,+ onSelectContinuation,+ path,+ children,+}: {+ node: WorkflowTreeNode+ branch: WorkflowTreeBranch+ index: number+ isLast: boolean+ branchCollapsed: boolean+ onToggleCollapsed: () => void+ onFocusBranch?: (path: HogFlowEdge[]) => void+ onSelectContinuation: (actionId: string, path: HogFlowEdge[]) => void+ path: HogFlowEdge[]+ children: ReactNode+}): JSX.Element {+ const { setSelectedNodeId } = useActions(hogFlowEditorLogic)+ const { selectedBranch, setSelectedBranch } = useHogFlowBranchSelection()+ const joinAction = node.joinAction+ const branchIndex = branch.edge.type === 'branch' ? (branch.edge.index ?? index) : null+ const pathColor = getHogFlowBranchColor(branchIndex)+ const isBranchSelected = selectedBranch?.actionId === node.action.id && selectedBranch.index === branchIndex+ const branchFilters =+ branchIndex !== null && node.action.type === 'conditional_branch'+ ? (node.action.config.conditions[branchIndex]?.filters.properties ?? [])+ : []+ const percentage =+ branchIndex !== null && node.action.type === 'random_cohort_branch'+ ? node.action.config.cohorts[branchIndex]?.percentage+ : undefined+ const badge =+ node.action.type === 'conditional_branch'+ ? branchIndex === null+ ? 'Else'+ : `If #${branchIndex + 1}`+ : node.action.type === 'wait_until_condition'+ ? branchIndex === null+ ? getWaitTimeoutLabel(node.action.config.max_wait_duration)+ ? 'Timeout'+ : 'No match'+ : 'Match'+ : branchIndex === null+ ? 'Fallback'+ : percentage !== undefined+ ? `${percentage}%`+ : `${branchIndex + 1}`++ const selectContinuation = (): void => {+ if (joinAction) {+ setSelectedBranch(null)+ setSelectedNodeId(joinAction.id)+ onSelectContinuation(joinAction.id, path)+ }+ }++ return (+ <div+ className="relative min-w-0 ps-6 [--workflow-branch-line-color:var(--border-bold-3000)] has-[>[data-workflow-branch-highlight]>[data-workflow-branch-header]:is(:hover,:focus-within)]:[--workflow-branch-line-color:var(--workflow-branch-color)]"+ style={{ '--workflow-branch-color': pathColor } as CSSProperties}+ data-workflow-branch-index={branchIndex ?? 'continue'}+ >+ <HogFlowTreeBranchConnector isLast={isLast} />+ <div className="min-w-0" data-workflow-branch-highlight>+ <div+ data-workflow-branch-header+ className={cn(+ 'flex min-w-0 items-start gap-2 rounded p-2',+ isBranchSelected && 'bg-surface-secondary ring-1 ring-primary'+ )}+ >+ <LemonButton+ type="tertiary"+ size="xsmall"+ className="!bg-transparent"+ aria-label={`${branchCollapsed ? 'Show' : 'Hide'} branch steps`}+ aria-expanded={!branchCollapsed}+ icon={<IconChevronDown className={cn(branchCollapsed && '-rotate-90')} />}+ onClick={() => onToggleCollapsed()}+ />+ <div className="min-w-0 flex-1">+ <div className="flex min-w-0 flex-wrap items-center gap-x-3 gap-y-1">+ <LemonButton+ type="tertiary"+ size="xsmall"+ className="!px-0 max-w-full"+ aria-label={`Edit ${branch.label} path from ${node.action.name}`}+ aria-pressed={isBranchSelected}+ // A focused path returns focus here. Every branch header renders this+ // button, but the actions menu below it is conditional.+ id={`workflow-tree-path-${getWorkflowTreeOccurrenceKey(node.action.id, [...path, branch.edge])}`}+ onClick={() => {+ setSelectedNodeId(node.action.id)+ setSelectedBranch({+ actionId: node.action.id,+ index: branchIndex,+ })+ }}+ data-attr="workflow-tree-select-branch"+ >+ <span className="flex min-w-0 flex-wrap items-center gap-2">+ <LemonTag+ size={node.action.type === 'conditional_branch' ? 'medium' : 'small'}+ className={cn(+ 'shrink-0',+ node.action.type === 'conditional_branch' && 'uppercase'+ )}+ style={{+ color:+ node.action.type === 'conditional_branch'+ ? `color-mix(in srgb, ${pathColor} 60%, var(--text-3000))`+ : pathColor,+ borderColor: pathColor,+ }}+ >+ {badge}+ </LemonTag>+ <span className="break-words whitespace-normal">{branch.label}</span>+ </span>+ </LemonButton>+ {branchFilters.length > 0 && (+ <div className="pointer-events-none ms-auto min-w-0 max-w-full text-xs">+ <PropertyFiltersDisplay filters={branchFilters} compact />+ </div>+ )}+ </div>+ {branchCollapsed && (+ <p className="mb-0 mt-1 break-words text-xs text-secondary">+ {getWorkflowTreeBranchSummary(node, branch)}+ </p>+ )}+ </div>+ {onFocusBranch &&+ (branch.sequence.nodes.length > 1 ||+ branch.sequence.nodes.some((child) => child.branches.length > 0)) && (+ <LemonMenu+ items={[+ {+ label: 'Focus on this path',+ onClick: () => onFocusBranch([...path, branch.edge]),+ },+ ]}+ >+ <LemonButton+ type="tertiary"+ size="xsmall"+ className="!bg-transparent shrink-0"+ icon={<IconEllipsis />}+ aria-label={`Actions for ${branch.label}`}+ tooltip="Path actions"+ data-attr="workflow-tree-focus-branch"+ />+ </LemonMenu>+ )}+ </div>+ <div className={cn('min-w-0 ps-3 ms-2 mt-2', branchCollapsed && 'hidden')}>+ {children}+ {joinAction && (+ <div className="relative py-1">+ <LemonButton+ type="tertiary"+ size="xsmall"+ className="!px-0"+ icon={<IconArrowRight />}+ onClick={selectContinuation}+ data-attr="workflow-tree-select-continuation"+ >+ <span className="break-words whitespace-normal">{`Continue to: ${joinAction.name}`}</span>+ </LemonButton>+ </div>+ )}+ </div>+ </div>+ </div>+ )+}diff --git a/products/workflows/frontend/Workflows/hogflows/tree/HogFlowTreeBranchConnector.tsx b/products/workflows/frontend/Workflows/hogflows/tree/HogFlowTreeBranchConnector.tsxnew file mode 100644index 000000000000..0b2c87bd22ed--- /dev/null+++ b/products/workflows/frontend/Workflows/hogflows/tree/HogFlowTreeBranchConnector.tsx@@ -0,0 +1,24 @@+export function HogFlowTreeBranchConnector({ isLast }: { isLast: boolean }): JSX.Element {+ return (+ <>+ <svg+ aria-hidden="true"+ className="pointer-events-none absolute start-2 -top-3 h-9 w-4 text-[var(--workflow-branch-line-color)] rtl:-scale-x-100"+ viewBox="0 0 16 36"+ fill="none"+ >+ <path+ d={`M 1 0 V 23 A 12 12 0 0 0 13 35 H 16${!isLast ? ' M 1 23 V 36' : ''}`}+ stroke="currentColor"+ strokeWidth={2}+ />+ </svg>+ {!isLast && (+ <span+ aria-hidden="true"+ className="pointer-events-none absolute start-2 top-6 -bottom-3 border-s-2 border-[var(--workflow-branch-line-color)]"+ />+ )}+ </>+ )+}diff --git a/products/workflows/frontend/Workflows/hogflows/tree/HogFlowTreeBranchIndicator.tsx b/products/workflows/frontend/Workflows/hogflows/tree/HogFlowTreeBranchIndicator.tsxdeleted file mode 100644index f166b18fdf6e..000000000000--- a/products/workflows/frontend/Workflows/hogflows/tree/HogFlowTreeBranchIndicator.tsx+++ /dev/null@@ -1,11 +0,0 @@-import { cn } from 'lib/ui/quill'--export function HogFlowTreeBranchIndicator({ color, className }: { color: string; className?: string }): JSX.Element {- return (- <span- aria-hidden="true"- className={cn('pointer-events-none absolute -start-4 w-0.5 rounded-full', className)}- style={{ backgroundColor: color }}- />- )-}diff --git a/products/workflows/frontend/Workflows/hogflows/tree/HogFlowTreeDropzone.tsx b/products/workflows/frontend/Workflows/hogflows/tree/HogFlowTreeDropzone.tsxindex 7480256fc3b5..e2535300671b 100644--- a/products/workflows/frontend/Workflows/hogflows/tree/HogFlowTreeDropzone.tsx+++ b/products/workflows/frontend/Workflows/hogflows/tree/HogFlowTreeDropzone.tsx@@ -4,7 +4,8 @@ import type { DragEvent } from 'react'import { IconPlus } from '@posthog/icons'-import { Button, cn, Popover, PopoverContent, PopoverTrigger } from 'lib/ui/quill'+import { LemonButton } from 'lib/lemon-ui/LemonButton'+import { cn, Popover, PopoverContent, PopoverTrigger } from 'lib/ui/quill'import { type CreateActionType, hogFlowEditorLogic } from '../hogFlowEditorLogic'import { HogFlowEditorPanelBuild } from '../panel/HogFlowEditorPanelBuild'@@ -21,6 +22,8 @@ export function HogFlowTreeDropzone({joinEdges,showConnector = true,compact = false,+ insertionLabel,+ alwaysVisible = false,}: {active: booleandraggedActionId: string | null@@ -31,6 +34,8 @@ export function HogFlowTreeDropzone({joinEdges?: HogFlowEdge[]showConnector?: booleancompact?: boolean+ insertionLabel?: string+ alwaysVisible?: boolean}): JSX.Element {const { workflow } = useValues(hogFlowEditorLogic)const {@@ -92,7 +97,10 @@ export function HogFlowTreeDropzone({}return (<div- className={cn('group relative flex w-full items-center justify-center', compact ? 'h-2' : 'h-4')}+ className={cn(+ 'group relative flex w-full items-center justify-center',+ alwaysVisible ? 'min-h-8' : compact ? 'h-2' : 'h-4'+ )}data-workflow-tree-dropzone-candidatedata-workflow-tree-dropzone-disabled={isAdjacentToDraggedAction || undefined}>@@ -106,33 +114,43 @@ export function HogFlowTreeDropzone({aria-hidden="true"className={cn('absolute inset-x-0 top-1/2 h-px -translate-y-1/2 bg-muted-foreground/50 opacity-0 transition-opacity',- (pickerOpen || !showConnector) && 'opacity-100',- showConnector && 'group-hover:opacity-100'+ pickerOpen && 'opacity-100',+ (showConnector || insertionLabel) && 'group-hover:opacity-100 group-focus-within:opacity-100')}/><Popover open={pickerOpen} onOpenChange={setPickerOpen}><PopoverTriggerrender={- <Button- type="button"- variant="outline"- size="icon-sm"+ <LemonButton+ htmlType="button"+ type="tertiary"+ size="xsmall"+ tooltip={insertionLabel ?? 'Insert step here'}className={cn(- 'absolute -right-2 top-1/2 z-10 !size-4 -translate-y-1/2 border-0 bg-transparent p-0 hover:bg-transparent focus-visible:outline-none'+ alwaysVisible+ ? 'relative z-10 me-auto min-w-0 max-w-full bg-transparent text-muted-foreground'+ : 'absolute -right-2 top-1/2 z-10 !size-4 -translate-y-1/2 border-0 !bg-transparent !p-0')}- aria-label="Insert step here"+ aria-label={insertionLabel ?? 'Insert step here'}data-attr="workflow-tree-insert-action"/>}>- <span- className={cn(- 'flex size-4 items-center justify-center rounded-full border border-primary bg-primary text-primary-foreground opacity-0 transition-[opacity,box-shadow] group-hover:opacity-100 group-hover:shadow-sm',- pickerOpen && 'opacity-100 shadow-sm'- )}- >- <IconPlus className="size-3" />- </span>+ {alwaysVisible ? (+ <>+ <IconPlus className="size-3 shrink-0" />+ <span className="truncate">{insertionLabel}</span>+ </>+ ) : (+ <span+ className={cn(+ 'flex size-4 items-center justify-center rounded-full border border-primary bg-primary text-primary-foreground opacity-0 transition-[opacity,box-shadow] group-hover:opacity-100 group-focus-within:opacity-100 group-hover:shadow-sm',+ pickerOpen && 'opacity-100 shadow-sm'+ )}+ >+ <IconPlus className="size-3" />+ </span>+ )}</PopoverTrigger><PopoverContent side="bottom" align="end" className="w-72 max-h-96 overflow-hidden p-0"><HogFlowEditorPanelBuild className="max-h-96 p-2" onActionSelect={handleInsertAction} />diff --git a/products/workflows/frontend/Workflows/hogflows/tree/HogFlowTreeEditor.stories.tsx b/products/workflows/frontend/Workflows/hogflows/tree/HogFlowTreeEditor.stories.tsxindex 32d09afa4db6..efb63a9a1bc2 100644--- a/products/workflows/frontend/Workflows/hogflows/tree/HogFlowTreeEditor.stories.tsx+++ b/products/workflows/frontend/Workflows/hogflows/tree/HogFlowTreeEditor.stories.tsx@@ -359,6 +359,9 @@ const InteractiveWorkflow = ({ id, className }: { id: string; className?: string)export const CustomerOnboardingAndRetention: StoryFn = () => <InteractiveWorkflow id={COMPLEX_WORKFLOW_ID} />+export const NarrowCustomerOnboardingAndRetention: StoryFn = () => (+ <InteractiveWorkflow id={COMPLEX_WORKFLOW_ID} className="w-5xl max-w-full" />+)export const NewWorkflow: StoryFn = () => <InteractiveWorkflow id="new" />export const NarrowWorkflow: StoryFn = () => <InteractiveWorkflow id="new" className="w-[40rem] max-w-full" />export const SupportSlaRouting: StoryFn = () => <InteractiveWorkflow id="example-support-sla-routing" />diff --git a/products/workflows/frontend/Workflows/hogflows/tree/HogFlowTreeEditor.tsx b/products/workflows/frontend/Workflows/hogflows/tree/HogFlowTreeEditor.tsxindex 58d60472263b..56b8b84b97b2 100644--- a/products/workflows/frontend/Workflows/hogflows/tree/HogFlowTreeEditor.tsx+++ b/products/workflows/frontend/Workflows/hogflows/tree/HogFlowTreeEditor.tsx@@ -1,17 +1,35 @@-import { useValues } from 'kea'+import { useActions, useValues } from 'kea'import { useEffect, useMemo, useRef, useState } from 'react'import type { DragEvent } from 'react'+import { LemonButton } from 'lib/lemon-ui/LemonButton'import { ScrollArea, ScrollBar } from 'lib/ui/quill'import { setHogFlowDragImage } from '../dragPreview'+import { useHogFlowBranchSelection } from '../HogFlowBranchSelection'import { hogFlowEditorLogic } from '../hogFlowEditorLogic'+import type { HogFlowEdge } from '../types'+import { HogFlowTreeDropzone } from './HogFlowTreeDropzone'import { HogFlowTreeFeaturePreview } from './HogFlowTreeFeaturePreview'+import { HogFlowTreeFocusHeader } from './HogFlowTreeFocusHeader'import { HogFlowTreeNode } from './HogFlowTreeNode'import { buildWorkflowTree } from './workflowTree'+import {+ findWorkflowTreePath,+ getWorkflowTreeContinuationPath,+ getWorkflowTreeOccurrenceKey,+ getWorkflowTreeStepId,+ WORKFLOW_TREE_BRANCH_LIMIT,+ type WorkflowTreeNodeViewState,+} from './workflowTreePresentation'export function HogFlowTreeEditor(): JSX.Element {const { nodeToBeAdded, workflow } = useValues(hogFlowEditorLogic)+ const { setSelectedNodeId } = useActions(hogFlowEditorLogic)+ const { setSelectedBranch } = useHogFlowBranchSelection()+ const [focusedEdges, setFocusedEdges] = useState<HogFlowEdge[]>([])+ const [focusTarget, setFocusTarget] = useState<string | null>(null)+ const [viewStates, setViewStates] = useState<Record<string, WorkflowTreeNodeViewState>>({})const treeRef = useRef<HTMLDivElement>(null)const draggedActionIdRef = useRef<string | null>(null)const [draggedActionId, setDraggedActionId] = useState<string | null>(null)@@ -19,8 +37,76 @@ export function HogFlowTreeEditor(): JSX.Element {const closestDropzoneRef = useRef<HTMLElement | null>(null)const dragStartYRef = useRef<number | null>(null)const tree = useMemo(() => buildWorkflowTree(workflow), [workflow])+ const focusedPath = useMemo(() => findWorkflowTreePath(tree, focusedEdges), [tree, focusedEdges])+ const focused = focusedPath.at(-1)const activeDropzones = !!nodeToBeAdded+ const updateViewState = (key: string, state: WorkflowTreeNodeViewState): void => {+ setViewStates((current) => ({ ...current, [key]: { ...current[key], ...state } }))+ }++ const focusBranch = (edges: HogFlowEdge[]): void => {+ setSelectedBranch(null)+ setSelectedNodeId(null)+ setFocusedEdges(edges)+ setFocusTarget('workflow-tree-exit-focus')+ }++ const revealPath = (path: HogFlowEdge[]): void => {+ for (const [index, { node, branch }] of findWorkflowTreePath(tree, path).entries()) {+ const key = getWorkflowTreeOccurrenceKey(node.action.id, path.slice(0, index))+ const collapsedBranches = new Set(viewStates[key]?.collapsedBranches)+ collapsedBranches.delete(`${branch.edge.from}-${branch.edge.type}-${branch.edge.index ?? 'continue'}`)+ updateViewState(key, {+ branchesOpen: true,+ showAllBranches:+ viewStates[key]?.showAllBranches ||+ node.branches.filter((item) => item.edge.type === 'branch').indexOf(branch) >=+ WORKFLOW_TREE_BRANCH_LIMIT,+ collapsedBranches,+ })+ }+ }++ const returnToWorkflow = (): void => {+ if (focused) {+ revealPath(focusedEdges.slice(0, -1))+ setFocusedEdges([])+ setFocusTarget(`workflow-tree-path-${getWorkflowTreeOccurrenceKey(focused.node.action.id, focusedEdges)}`)+ }+ }++ const selectContinuation = (actionId: string, path: HogFlowEdge[]): void => {+ setSelectedBranch(null)+ setSelectedNodeId(actionId)+ const destinationPath = getWorkflowTreeContinuationPath(tree, path, actionId)+ revealPath(destinationPath)+ // A path inside the focused view can join at a step that the focused view also shows, so leave+ // focus only for a join that the user cannot already see.+ if (+ focused &&+ getWorkflowTreeOccurrenceKey(actionId, destinationPath.slice(0, focusedEdges.length)) !==+ getWorkflowTreeOccurrenceKey(actionId, focusedEdges)+ ) {+ setFocusedEdges([])+ }+ setFocusTarget(getWorkflowTreeStepId(actionId, destinationPath))+ }++ useEffect(() => {+ if (!focusTarget) {+ return+ }+ const frame = requestAnimationFrame(() => {+ const target = document.getElementById(focusTarget)+ const control = target instanceof HTMLButtonElement ? target : target?.querySelector('button')+ control?.focus({ preventScroll: true })+ target?.scrollIntoView({ block: 'nearest' })+ setFocusTarget(null)+ })+ return () => cancelAnimationFrame(frame)+ }, [focusTarget])+const clearClosestDropzone = (): void => {closestDropzoneRef.current?.removeAttribute('data-workflow-tree-dropzone-closest')closestDropzoneRef.current = null@@ -145,7 +231,10 @@ export function HogFlowTreeEditor(): JSX.Element {onDragOver={onTreeDragOver}onDropCapture={onTreeDropCapture}>- {tree.nodes.map((node) => (+ {focused && (+ <HogFlowTreeFocusHeader focusedPath={focusedPath} onReturnToWorkflow={returnToWorkflow} />+ )}+ {(focused?.branch.sequence ?? tree).nodes.map((node) => (<HogFlowTreeNodekey={node.action.id}node={node}@@ -154,8 +243,35 @@ export function HogFlowTreeEditor(): JSX.Element {draggedActionIdRef={draggedActionIdRef}onDragStart={onDragStart}onDragEnd={onDragEnd}+ onFocusBranch={focusBranch}+ onSelectContinuation={selectContinuation}+ path={focused ? focusedEdges : []}+ viewStates={viewStates}+ onViewStateChange={updateViewState}/>))}+ {focused?.branch.sequence.trailingEdge && (+ <HogFlowTreeDropzone+ active={activeDropzones}+ draggedActionId={draggedActionId}+ draggedActionIdRef={draggedActionIdRef}+ onDragEnd={onDragEnd}+ edge={focused.branch.sequence.trailingEdge}+ alwaysVisible={focused.branch.sequence.nodes.length === 0}+ insertionLabel={`Add step to ${focused.branch.label}`}+ />+ )}+ {focused?.node.joinAction && (+ <LemonButton+ type="secondary"+ size="small"+ className="self-start max-w-full mt-3"+ onClick={() => selectContinuation(focused.node.joinAction!.id, focusedEdges.slice(0, -1))}+ data-attr="workflow-tree-focus-continuation"+ >+ <span className="break-words whitespace-normal">{`Continue to: ${focused.node.joinAction.name}`}</span>+ </LemonButton>+ )}</div><ScrollBar orientation="vertical" /></ScrollArea>diff --git a/products/workflows/frontend/Workflows/hogflows/tree/HogFlowTreeFocusHeader.tsx b/products/workflows/frontend/Workflows/hogflows/tree/HogFlowTreeFocusHeader.tsxnew file mode 100644index 000000000000..13a2d6bf9b64--- /dev/null+++ b/products/workflows/frontend/Workflows/hogflows/tree/HogFlowTreeFocusHeader.tsx@@ -0,0 +1,37 @@+import { LemonButton } from 'lib/lemon-ui/LemonButton'+import { LemonCard } from 'lib/lemon-ui/LemonCard'++import { getWorkflowTreeBranchSummary, type WorkflowTreePath } from './workflowTreePresentation'++export function HogFlowTreeFocusHeader({+ focusedPath,+ onReturnToWorkflow,+}: {+ focusedPath: WorkflowTreePath[]+ onReturnToWorkflow: () => void+}): JSX.Element | null {+ const focused = focusedPath.at(-1)+ if (!focused) {+ return null+ }+ return (+ <LemonCard hoverEffect={false} className="mb-3 p-3">+ <LemonButton+ type="tertiary"+ size="small"+ onClick={onReturnToWorkflow}+ id="workflow-tree-exit-focus"+ data-attr="workflow-tree-exit-focus"+ >+ Back to workflow+ </LemonButton>+ <p className="my-2 break-words text-xs text-secondary">+ {focusedPath.map(({ node, branch }) => `${node.action.name} › ${branch.label}`).join(' › ')}+ </p>+ <h3 className="mb-1 break-words">{focused.branch.label}</h3>+ <p className="mb-0 break-words text-xs text-secondary">+ {getWorkflowTreeBranchSummary(focused.node, focused.branch)}+ </p>+ </LemonCard>+ )+}diff --git a/products/workflows/frontend/Workflows/hogflows/tree/HogFlowTreeNode.tsx b/products/workflows/frontend/Workflows/hogflows/tree/HogFlowTreeNode.tsxindex 74d41a585538..338108f5a082 100644--- a/products/workflows/frontend/Workflows/hogflows/tree/HogFlowTreeNode.tsx+++ b/products/workflows/frontend/Workflows/hogflows/tree/HogFlowTreeNode.tsx@@ -1,21 +1,24 @@-import { useActions } from 'kea'-import { useEffect, useRef, useState } from 'react'+import { Fragment, useEffect, useRef } from 'react'import type { DragEvent } from 'react'-import { IconArrowRight, IconChevronDown } from '@posthog/icons'+import { IconChevronDown } from '@posthog/icons'-import PropertyFiltersDisplay from 'lib/components/PropertyFilters/components/PropertyFiltersDisplay'-import { Tooltip } from 'lib/lemon-ui/Tooltip'-import { Badge, Button, Item, ItemContent, ItemTitle, Text, cn } from 'lib/ui/quill'+import { LemonButton } from 'lib/lemon-ui/LemonButton'+import { cn } from 'lib/utils/css-classes'-import { getHogFlowBranchColor, useHogFlowBranchSelection } from '../HogFlowBranchSelection'-import { hogFlowEditorLogic } from '../hogFlowEditorLogic'-import { HogFlowTreeBranchIndicator } from './HogFlowTreeBranchIndicator'+import { useHogFlowBranchSelection } from '../HogFlowBranchSelection'+import type { HogFlowEdge } from '../types'+import { HogFlowTreeBranch } from './HogFlowTreeBranch'import { HogFlowTreeDropzone } from './HogFlowTreeDropzone'import { HogFlowTreeStep } from './HogFlowTreeStep'import type { WorkflowTreeNode } from './workflowTree'+import {+ getWorkflowTreeOccurrenceKey,+ getWorkflowTreeStepId,+ WORKFLOW_TREE_BRANCH_LIMIT,+ type WorkflowTreeNodeViewState,+} from './workflowTreePresentation'-const BRANCH_LIMIT = 6export function HogFlowTreeNode({activeDropzones,draggedActionId,@@ -23,8 +26,12 @@ export function HogFlowTreeNode({node,onDragEnd,onDragStart,- branchColor,showIncomingConnector = true,+ onFocusBranch,+ onSelectContinuation,+ path,+ viewStates,+ onViewStateChange,}: {activeDropzones: booleandraggedActionId: string | null@@ -32,28 +39,57 @@ export function HogFlowTreeNode({node: WorkflowTreeNodeonDragEnd: () => voidonDragStart: (event: DragEvent<HTMLDivElement>, actionId: string, dragPreviewElement: HTMLDivElement | null) => void- branchColor?: stringshowIncomingConnector?: boolean+ onFocusBranch?: (path: HogFlowEdge[]) => void+ onSelectContinuation: (actionId: string, path: HogFlowEdge[]) => void+ path: HogFlowEdge[]+ viewStates: Record<string, WorkflowTreeNodeViewState>+ onViewStateChange: (key: string, state: WorkflowTreeNodeViewState) => void}): JSX.Element {- const { setSelectedNodeId } = useActions(hogFlowEditorLogic)- const { selectedBranch, setSelectedBranch } = useHogFlowBranchSelection()- const [branchesOpen, setBranchesOpen] = useState(true)- const [collapsedBranches, setCollapsedBranches] = useState<Set<string>>(new Set())- const [showAllBranches, setShowAllBranches] = useState(false)+ const { selectedBranch } = useHogFlowBranchSelection()+ const occurrenceKey = getWorkflowTreeOccurrenceKey(node.action.id, path)+ const {+ branchesOpen = true,+ collapsedBranches = new Set<string>(),+ showAllBranches = false,+ } = viewStates[occurrenceKey] ?? {}const nodeRef = useRef<HTMLDivElement>(null)- const visibleBranches = showAllBranches ? node.branches : node.branches.slice(0, BRANCH_LIMIT)+ const branchContentRef = useRef<HTMLDivElement>(null)+ const branchToggleRef = useRef<HTMLButtonElement>(null)+ const pendingBranchToggle = useRef(false)+ const conditionBranches = node.branches.filter((branch) => branch.edge.type === 'branch')+ const visibleBranches = showAllBranches+ ? node.branches+ : [+ ...conditionBranches.slice(0, WORKFLOW_TREE_BRANCH_LIMIT),+ ...node.branches.filter((branch) => branch.edge.type === 'continue'),+ ]const hiddenBranchCount = node.branches.length - visibleBranches.length+ const visibleConditionCount = showAllBranches ? conditionBranches.length : WORKFLOW_TREE_BRANCH_LIMIT+ const firstHiddenBranchIndex = conditionBranches[WORKFLOW_TREE_BRANCH_LIMIT]?.edge.indexconst joinEdge = node.joinEdges[0]- const joinAction = node.joinAction- const branchNoun = node.action.type === 'random_cohort_branch' ? 'paths' : 'conditions'+ const branchNoun = node.action.type === 'conditional_branch' ? 'conditions' : 'paths'+const toggleBranchCollapsed = (branchKey: string): void => {- setCollapsedBranches((current) => {- const next = new Set(current)- next.has(branchKey) ? next.delete(branchKey) : next.add(branchKey)- return next- })+ const next = new Set(collapsedBranches)+ next.has(branchKey) ? next.delete(branchKey) : next.add(branchKey)+ onViewStateChange(occurrenceKey, { collapsedBranches: next })}+ useEffect(() => {+ if (!pendingBranchToggle.current) {+ return+ }+ pendingBranchToggle.current = false+ const target = showAllBranches+ ? branchContentRef.current?.querySelector<HTMLButtonElement>(+ `:scope > [data-workflow-branch-index="${firstHiddenBranchIndex}"] [data-attr="workflow-tree-select-branch"]`+ )+ : branchToggleRef.current+ target?.focus({ preventScroll: true })+ target?.scrollIntoView({ block: showAllBranches ? 'start' : 'nearest' })+ }, [showAllBranches, firstHiddenBranchIndex])+useEffect(() => {if (selectedBranch?.actionId === node.action.id) {nodeRef.current@@ -65,22 +101,19 @@ export function HogFlowTreeNode({const step = (<HogFlowTreeStepaction={node.action}- branchColor={branchColor}+ stepId={getWorkflowTreeStepId(node.action.id, path)}collapseControl={node.branches.length > 0 ? (- <Tooltip title={`${branchesOpen ? 'Hide' : 'Show'} ${branchNoun}`}>- <Button- type="button"- variant="default"- size="icon"- aria-label={`${branchesOpen ? 'Hide' : 'Show'} ${branchNoun}`}- onClick={() => setBranchesOpen((open) => !open)}- >- <IconChevronDown- className={cn('size-5 transition-transform', !branchesOpen && '-rotate-90')}- />- </Button>- </Tooltip>+ <LemonButton+ type="tertiary"+ size="small"+ className="!bg-transparent"+ aria-label={`${branchesOpen ? 'Hide' : 'Show'} ${branchNoun}`}+ aria-expanded={branchesOpen}+ tooltip={`${branchesOpen ? 'Hide' : 'Show'} ${branchNoun}`}+ icon={<IconChevronDown className={cn(!branchesOpen && '-rotate-90')} />}+ onClick={() => onViewStateChange(occurrenceKey, { branchesOpen: !branchesOpen })}+ />) : undefined}onDragStart={onDragStart}@@ -94,7 +127,7 @@ export function HogFlowTreeNode({)return (- <div ref={nodeRef} className="flex w-full flex-col">+ <div ref={nodeRef} className="flex w-full min-w-0 flex-col">{node.incomingEdge && (<HogFlowTreeDropzoneactive={activeDropzones}@@ -110,195 +143,93 @@ export function HogFlowTreeNode({step) : (<>- {step}- {branchesOpen && (- <div className="flex flex-col gap-3 pt-2" data-workflow-tree-branch-content={node.action.id}>- {visibleBranches.map((branch, index) => {- const branchIndex = branch.edge.type === 'branch' ? (branch.edge.index ?? index) : null- const branchColor = getHogFlowBranchColor(branchIndex)- const isBranchSelected =- selectedBranch?.actionId === node.action.id && selectedBranch.index === branchIndex- const branchFilters =- branchIndex !== null && node.action.type === 'conditional_branch'- ? (node.action.config.conditions[branchIndex]?.filters.properties ?? [])- : []- const cohortPercentage =- branchIndex !== null && node.action.type === 'random_cohort_branch'- ? node.action.config.cohorts[branchIndex]?.percentage- : undefined-- const branchKey = `${branch.edge.from}-${branch.edge.type}-${branch.edge.index ?? 'continue'}`- const branchCollapsed = collapsedBranches.has(branchKey)- const hiddenStepCount = branch.sequence.nodes.length-- return (- <div- key={branchKey}- className="relative flex min-w-0 flex-col ps-0"- data-workflow-branch-index={branchIndex ?? 'continue'}- >- <Item- variant="outline"- size="xs"- className="relative z-10 flex-nowrap bg-card text-start"- style={{- borderColor: branchColor,- borderWidth: isBranchSelected ? 2 : undefined,- }}- data-attr="workflow-tree-select-branch"- >- <Button- type="button"- variant="link"- className="absolute inset-0 z-0 h-full w-full"- aria-label={`Edit ${branch.label} path from ${node.action.name}`}- aria-pressed={isBranchSelected}- onClick={() => {- setSelectedNodeId(node.action.id)- setSelectedBranch({ actionId: node.action.id, index: branchIndex })- }}- />- <Badge- variant="default"- className="pointer-events-none relative z-10 font-mono text-xxs"- style={{ color: branchColor, borderColor: branchColor }}+ <div className="min-w-0">+ {step}+ {branchesOpen && (+ <div+ ref={branchContentRef}+ className="flex min-w-0 flex-col gap-3 pt-3"+ data-workflow-tree-branch-content={node.action.id}+ >+ {visibleBranches.map((branch, index) => {+ const branchKey = `${branch.edge.from}-${branch.edge.type}-${branch.edge.index ?? 'continue'}`+ return (+ <Fragment key={branchKey}>+ <HogFlowTreeBranch+ node={node}+ branch={branch}+ index={index}+ isLast={index === visibleBranches.length - 1}+ branchCollapsed={collapsedBranches.has(branchKey)}+ onToggleCollapsed={() => toggleBranchCollapsed(branchKey)}+ onFocusBranch={onFocusBranch}+ onSelectContinuation={onSelectContinuation}+ path={path}>- {branch.edge.type === 'continue' ? 'ELSE' : 'IF'}- </Badge>- <ItemContent className="pointer-events-none relative z-10 min-w-0">- <ItemTitle className="max-w-full truncate text-xs">- {branch.label}- </ItemTitle>- </ItemContent>- {branchFilters.length > 0 && (- <div className="pointer-events-none relative z-10 ms-auto min-w-0 max-w-[60%] overflow-hidden [&_.PropertyFilterButton]:!gap-1 [&_.PropertyFilterButton]:!px-1.5 [&_.PropertyFilterButton]:!py-px [&_.PropertyFilterButton]:!text-xs [&_.PropertyFilterButton>_.LemonIcon]:!text-xs">- <PropertyFiltersDisplay filters={branchFilters} compact />- </div>- )}- {cohortPercentage !== undefined && (- <Text- size="xs"- variant="muted"- render={<span />}- className="pointer-events-none relative z-10 ms-auto shrink-0"- >- {cohortPercentage}%- </Text>- )}- <div className="relative z-20 ms-auto flex shrink-0 items-center gap-1">- <Tooltip title={`${branchCollapsed ? 'Show' : 'Hide'} branch steps`}>- <Button- type="button"- variant="default"- size="xs"- className={cn(- !(branchCollapsed && hiddenStepCount > 0) && '!w-5 !px-0'- )}- aria-label={`${branchCollapsed ? 'Show' : 'Hide'} branch steps`}- onClick={() => toggleBranchCollapsed(branchKey)}- >- {branchCollapsed &&- hiddenStepCount > 0 &&- `${hiddenStepCount} ${hiddenStepCount === 1 ? 'step' : 'steps'} hidden`}- <IconChevronDown- className={cn(- 'size-4 transition-transform',- branchCollapsed && '-rotate-90'- )}- />- </Button>- </Tooltip>- </div>- </Item>- <div className={cn('flex flex-col ps-8', branchCollapsed && 'hidden')}>- {branch.sequence.nodes.length === 0 && (- <div className="relative">- <HogFlowTreeBranchIndicator- color={branchColor}- className="inset-y-2"+ {branch.sequence.nodes.map((childNode, childIndex) => (+ <HogFlowTreeNode+ key={childNode.action.id}+ node={childNode}+ activeDropzones={activeDropzones}+ draggedActionId={draggedActionId}+ draggedActionIdRef={draggedActionIdRef}+ onDragStart={onDragStart}+ onDragEnd={onDragEnd}+ showIncomingConnector={childIndex > 0}+ onFocusBranch={onFocusBranch}+ onSelectContinuation={onSelectContinuation}+ path={[...path, branch.edge]}+ viewStates={viewStates}+ onViewStateChange={onViewStateChange}/>- <Text size="xs" variant="muted" className="py-2">- No steps in this branch.- </Text>- </div>- )}- {branch.sequence.nodes.map((childNode, childIndex) => (- <HogFlowTreeNode- key={childNode.action.id}- node={childNode}- activeDropzones={activeDropzones}- draggedActionId={draggedActionId}- draggedActionIdRef={draggedActionIdRef}- onDragStart={onDragStart}- onDragEnd={onDragEnd}- branchColor={branchColor}- showIncomingConnector={childIndex > 0}- />- ))}- {branch.sequence.trailingEdge && (- <HogFlowTreeDropzone- active={activeDropzones}- draggedActionId={draggedActionId}- draggedActionIdRef={draggedActionIdRef}- onDragEnd={onDragEnd}- edge={branch.sequence.trailingEdge}- showConnector={false}- compact- />- )}- {joinAction && (- <div className="relative flex items-center gap-1">- <HogFlowTreeBranchIndicator- color={branchColor}- className="inset-y-1"+ ))}+ {branch.sequence.trailingEdge && (+ <HogFlowTreeDropzone+ active={activeDropzones}+ draggedActionId={draggedActionId}+ draggedActionIdRef={draggedActionIdRef}+ onDragEnd={onDragEnd}+ edge={branch.sequence.trailingEdge}+ showConnector={false}+ alwaysVisible={branch.sequence.nodes.length === 0}+ insertionLabel={`Add step to ${branch.label}`}/>- <Text size="xxs" variant="muted" render={<span />}>- {node.action.type === 'random_cohort_branch'- ? 'End of cohort split · continues to'- : 'End of condition · continues to'}- </Text>- <Button- type="button"- variant="link"- size="xs"- className="min-w-0 max-w-56 px-0"- onClick={() => {- setSelectedBranch(null)- setSelectedNodeId(joinAction.id)- document- .getElementById(`workflow-tree-step-${joinAction.id}`)- ?.scrollIntoView({- behavior: 'smooth',- block: 'center',+ )}+ </HogFlowTreeBranch>+ {conditionBranches.length > WORKFLOW_TREE_BRANCH_LIMIT &&+ index === visibleConditionCount - 1 && (+ <div className="relative ps-8">+ {index < visibleBranches.length - 1 && (+ <span+ aria-hidden="true"+ className="pointer-events-none absolute start-2 -top-3 -bottom-3 border-s-2 border-[var(--border-bold-3000)]"+ />+ )}+ <LemonButton+ ref={branchToggleRef}+ type="secondary"+ size="xsmall"+ aria-expanded={showAllBranches}+ onClick={() => {+ pendingBranchToggle.current = true+ onViewStateChange(occurrenceKey, {+ showAllBranches: !showAllBranches,})- }}- data-attr="workflow-tree-select-continuation"- >- <span className="truncate">{joinAction.name}</span>- <IconArrowRight className="size-3" />- </Button>- </div>- )}- </div>- </div>- )- })}- {node.branches.length > BRANCH_LIMIT && (- <Button- type="button"- variant="outline"- size="sm"- className="self-start border-dashed"- onClick={() => setShowAllBranches((showAll) => !showAll)}- data-attr="workflow-tree-toggle-more-branches"- >- {showAllBranches- ? 'Show fewer branches'- : `Show ${hiddenBranchCount} more branches`}- </Button>- )}- </div>- )}+ }}+ data-attr="workflow-tree-toggle-more-branches"+ >+ {showAllBranches+ ? 'Show fewer branches'+ : `Show ${hiddenBranchCount} more branches`}+ </LemonButton>+ </div>+ )}+ </Fragment>+ )+ })}+ </div>+ )}+ </div>{joinEdge && (<HogFlowTreeDropzoneactive={activeDropzones}@@ -308,6 +239,7 @@ export function HogFlowTreeNode({edge={joinEdge}isBranchJoinjoinEdges={node.joinEdges}+ insertionLabel={`Add step after ${node.action.name} paths`}/>)}</>diff --git a/products/workflows/frontend/Workflows/hogflows/tree/HogFlowTreeStep.tsx b/products/workflows/frontend/Workflows/hogflows/tree/HogFlowTreeStep.tsxindex 1a8222c099a7..93164e39e8e7 100644--- a/products/workflows/frontend/Workflows/hogflows/tree/HogFlowTreeStep.tsx+++ b/products/workflows/frontend/Workflows/hogflows/tree/HogFlowTreeStep.tsx@@ -12,22 +12,21 @@ import { hogFlowEditorLogic } from '../hogFlowEditorLogic'import { StepView } from '../steps/components/StepView'import { useHogFlowStep } from '../steps/HogFlowSteps'import type { HogFlowAction, HogFlowActionNode } from '../types'-import { HogFlowTreeBranchIndicator } from './HogFlowTreeBranchIndicator'import { isBranchingAction } from './workflowTree'export function HogFlowTreeStep({action,onDragEnd,onDragStart,- branchColor,collapseControl,+ stepId,canDrag = !['trigger', 'exit'].includes(action.type) && !isBranchingAction(action),}: {action: HogFlowActiononDragEnd: () => voidonDragStart: (event: DragEvent<HTMLDivElement>, actionId: string, dragPreviewElement: HTMLDivElement | null) => void- branchColor?: stringcollapseControl?: ReactNode+ stepId: stringcanDrag?: boolean}): JSX.Element {const { animatingEdgePair, nodesById, selectedNode } = useValues(hogFlowEditorLogic)@@ -58,7 +57,8 @@ export function HogFlowTreeStep({const hasValidationIssue =validationResult?.valid === false || Object.keys(validationResult?.warnings ?? {}).length > 0const isAnimationTarget = animatingEdgePair?.endsWith(`->${action.id}`) ?? false- const hasFooterContent = !!action.description || !!step?.previews.length+ const previews = step?.previews ?? []+ const hasFooterContent = !!action.description || previews.length > 0return (<Item@@ -71,9 +71,8 @@ export function HogFlowTreeStep({'data-[workflow-tree-dragging]:opacity-50')}data-attr="workflow-tree-step"- id={`workflow-tree-step-${action.id}`}+ id={stepId}>- {branchColor && <HogFlowTreeBranchIndicator color={branchColor} className="inset-y-1" />}<Buttontype="button"variant="link"@@ -114,7 +113,7 @@ export function HogFlowTreeStep({</ItemMedia><ItemContent className="pointer-events-none relative z-10 min-w-0 gap-0.5"><div className="flex min-w-0 items-center gap-1">- <ItemTitle className="pointer-events-none min-w-0 flex-1 max-w-full truncate leading-tight">+ <ItemTitle className="pointer-events-none min-w-0 flex-1 max-w-full break-words whitespace-normal leading-tight">{action.name}</ItemTitle>{canHaveActions && (@@ -157,19 +156,19 @@ export function HogFlowTreeStep({)}</div>{hasFooterContent && (- <div className="flex min-w-0 items-center gap-2">+ <div className="flex min-w-0 flex-wrap items-center gap-2">{action.description && (- <ItemDescription className="pointer-events-none min-w-0 flex-1 truncate leading-tight">+ <ItemDescription className="pointer-events-none min-w-0 flex-1 whitespace-normal break-words leading-tight">{action.description}</ItemDescription>)}- {!!step?.previews.length && (- <div className="pointer-events-none ms-auto flex min-w-0 shrink-0 items-center gap-1 overflow-hidden">- {step.previews.slice(0, 3).map((preview, index) => (+ {previews.length > 0 && (+ <div className="pointer-events-none ms-auto flex min-w-0 max-w-full flex-wrap items-center justify-end gap-1">+ {previews.slice(0, 3).map((preview, index) => (<Badgekey={`${preview.label}-${index}`}variant="default"- className="max-w-36 truncate"+ className="max-w-full whitespace-normal break-words h-auto min-h-4 py-0 leading-tight">{preview.icon}{preview.label}diff --git a/products/workflows/frontend/Workflows/hogflows/tree/workflowTree.test.ts b/products/workflows/frontend/Workflows/hogflows/tree/workflowTree.test.tsindex 3a382fe32303..eec040adab50 100644--- a/products/workflows/frontend/Workflows/hogflows/tree/workflowTree.test.ts+++ b/products/workflows/frontend/Workflows/hogflows/tree/workflowTree.test.ts@@ -1,5 +1,17 @@import type { HogFlow, HogFlowAction, HogFlowEdge } from '../types'-import { buildWorkflowTree, computeMoveTreeBranchEdges, isWorkflowTreeComplete } from './workflowTree'+import {+ buildWorkflowTree,+ computeMoveTreeBranchEdges,+ getWorkflowBranchLabel,+ isWorkflowTreeComplete,+} from './workflowTree'+import {+ findWorkflowTreePath,+ getWorkflowTreeBranchSummary,+ getWorkflowTreeContinuationPath,+ getWorkflowTreeStepId,+ getWorkflowTreeStepIds,+} from './workflowTreePresentation'const action = (id: string, type: HogFlowAction['type'] = 'function'): HogFlowAction =>({ id, type, name: id, description: '', config: {} }) as HogFlowAction@@ -57,6 +69,9 @@ describe('buildWorkflowTree', () => {])expect(tree.nodes[1].joinActionId).toBe('shared')expect(tree.nodes[1].joinAction?.id).toBe('shared')+ expect(getWorkflowTreeBranchSummary(tree.nodes[1], tree.nodes[1].branches[0])).toBe(+ '1 step · Continue to: shared'+ )})it('keeps immediate routes empty and exposes their insertion edges', () => {@@ -73,6 +88,9 @@ describe('buildWorkflowTree', () => {edge('condition', 'exit', 'branch', 0),edge('condition', 'exit'),])+ expect(getWorkflowTreeBranchSummary(tree.nodes[1], tree.nodes[1].branches[0])).toBe(+ '0 steps · Continue to: exit'+ )})it('leaves routes terminal when they have no shared continuation', () => {@@ -98,6 +116,7 @@ describe('buildWorkflowTree', () => {['left-exit'],['right-exit'],])+ expect(getWorkflowTreeBranchSummary(tree.nodes[1], tree.nodes[1].branches[0])).toBe('1 step · End workflow')})it('scopes a nested branch join to its own routes', () => {@@ -139,6 +158,170 @@ describe('buildWorkflowTree', () => {edge('self-serve', 'shared'),edge('onboarding', 'shared'),])+ expect(getWorkflowTreeBranchSummary(tree.nodes[1], tree.nodes[1].branches[1])).toBe(+ '4 steps · Continue to: shared'+ )+ expect(+ findWorkflowTreePath(tree, [+ edge('outer', 'trial', 'branch', 1),+ edge('onboarding', 'guided', 'branch', 0),+ ]).map(({ node, branch }) => [node.action.id, branch.edge.index])+ ).toEqual([+ ['outer', 1],+ ['onboarding', 0],+ ])+ expect(+ findWorkflowTreePath(tree, [+ edge('outer', 'trial', 'branch', 1),+ edge('deleted-branch', 'guided', 'branch', 0),+ ])+ ).toEqual([])+ })++ it('keeps a nested join inside the focused path and the outer join outside it', () => {+ const tree = buildWorkflowTree(+ workflow(+ [+ action('trigger', 'trigger'),+ action('outer', 'conditional_branch'),+ action('trial'),+ action('paid'),+ action('inner', 'conditional_branch'),+ action('guided'),+ action('self-serve'),+ action('followup'),+ action('shared'),+ action('exit', 'exit'),+ ],+ [+ edge('trigger', 'outer'),+ edge('outer', 'trial', 'branch', 0),+ edge('outer', 'paid'),+ edge('trial', 'inner'),+ edge('inner', 'guided', 'branch', 0),+ edge('inner', 'self-serve'),+ edge('guided', 'followup'),+ edge('self-serve', 'followup'),+ edge('followup', 'shared'),+ edge('paid', 'shared'),+ edge('shared', 'exit'),+ ]+ )+ )++ const [focused] = findWorkflowTreePath(tree, [edge('outer', 'trial', 'branch', 0)])++ expect(focused.branch.sequence.nodes.find((node) => node.action.id === 'inner')?.joinActionId).toBe('followup')+ expect(focused.node.joinActionId).toBe('shared')+ expect([...getWorkflowTreeStepIds(focused.branch.sequence)]).toEqual([+ 'trial',+ 'inner',+ 'guided',+ 'self-serve',+ 'followup',+ ])+ const innerPath = [edge('outer', 'trial', 'branch', 0), edge('inner', 'guided', 'branch', 0)]+ expect(getWorkflowTreeContinuationPath(tree, innerPath, 'followup')).toEqual(innerPath.slice(0, 1))+ expect(getWorkflowTreeContinuationPath(tree, innerPath, 'shared')).toEqual([])+ })++ it('keeps the selected occurrence when paths share a branching action', () => {+ const tree = buildWorkflowTree(+ workflow(+ [+ action('trigger', 'trigger'),+ action('outer', 'conditional_branch'),+ action('wait', 'wait_until_condition'),+ action('matched'),+ action('timeout'),+ action('exit', 'exit'),+ ],+ [+ edge('trigger', 'outer'),+ edge('outer', 'wait', 'branch', 0),+ edge('outer', 'wait', 'branch', 1),+ edge('outer', 'exit'),+ edge('wait', 'matched', 'branch', 0),+ edge('wait', 'timeout'),+ edge('matched', 'exit'),+ edge('timeout', 'exit'),+ ]+ )+ )+ const firstPath = [edge('outer', 'wait', 'branch', 0), edge('wait', 'matched', 'branch', 0)]+ const secondPath = [edge('outer', 'wait', 'branch', 1), edge('wait', 'matched', 'branch', 0)]++ for (const path of [firstPath, secondPath]) {+ expect(findWorkflowTreePath(tree, path).map(({ branch }) => branch.edge)).toEqual(path)+ expect(getWorkflowTreeContinuationPath(tree, path, 'matched')).toEqual(path)+ }+ expect(getWorkflowTreeStepId('matched', firstPath)).not.toBe(getWorkflowTreeStepId('matched', secondPath))+ expect(findWorkflowTreePath(tree, [edge('wait', 'matched', 'branch', 0)])).toEqual([])+ })++ it.each([+ [false, 'none', 'branch', 'Condition matched'],+ [false, 'targetless', 'branch', 'Condition matched'],+ [false, 'targeted', 'branch', 'Event received'],+ [true, 'none', 'branch', 'Condition matched'],+ [true, 'targetless', 'branch', 'Condition matched'],+ [true, 'targeted', 'branch', 'Condition or event matched'],+ [false, 'none', 'continue', 'No match within 2d'],+ [false, 'targeted', 'continue', 'No match within 2d'],+ ] as const)(+ 'labels wait outcomes for condition=%s events=%s and edge=%s',+ (hasCondition, events, edgeType, label) => {+ const eventConfigs = {+ none: [],+ targetless: [{ filters: { events: [], actions: [] } }],+ targeted: [{ filters: { events: [{ id: 'activated' }] } }],+ }+ const waitAction: HogFlowAction = {+ id: 'wait',+ type: 'wait_until_condition',+ name: 'Wait for activation',+ description: '',+ config: {+ condition: hasCondition ? { filters: { properties: [{ key: 'plan', value: 'pro' }] } } : {},+ max_wait_duration: '2d',+ events: eventConfigs[events],+ },+ }+ expect(getWorkflowBranchLabel(waitAction, edge('wait', 'next', edgeType, 0))).toBe(label)+ }+ )++ it.each([+ ['2d', 'No match within 2d'],+ ['31d', 'No match within 30d'],+ ['25h', 'No match within 24h'],+ ['90m', 'No match within 60m'],+ ['m', 'No match'],+ ['', 'No match'],+ [undefined, 'No match'],+ ] as const)('labels a wait timeout of %s on the continue edge', (maxWaitDuration, label) => {+ const waitAction = {+ id: 'wait',+ type: 'wait_until_condition',+ name: 'Wait for activation',+ description: '',+ config: { condition: {}, events: [], max_wait_duration: maxWaitDuration },+ } as HogFlowAction+ expect(getWorkflowBranchLabel(waitAction, edge('wait', 'next', 'continue'))).toBe(label)+ })++ it.each([+ ['branch', 'Loyal users'],+ ['continue', 'Fallback if no cohort has traffic'],+ ] as const)('labels random cohort outcomes for edge=%s', (edgeType, label) => {+ const cohortAction: HogFlowAction = {+ id: 'split',+ type: 'random_cohort_branch',+ name: 'Split traffic',+ description: '',+ config: { cohorts: [{ name: 'Loyal users', percentage: 30 }] },+ }+ expect(getWorkflowBranchLabel(cohortAction, edge('split', 'next', edgeType, 0))).toBe(label)})it('moves a branching action with all of its paths', () => {diff --git a/products/workflows/frontend/Workflows/hogflows/tree/workflowTree.ts b/products/workflows/frontend/Workflows/hogflows/tree/workflowTree.tsindex 4c44518008ca..286a8eddee14 100644--- a/products/workflows/frontend/Workflows/hogflows/tree/workflowTree.ts+++ b/products/workflows/frontend/Workflows/hogflows/tree/workflowTree.ts@@ -22,13 +22,68 @@ export interface WorkflowTreeBranch {sequence: WorkflowTreeSequence}+// A wait can run without a timeout, and the duration field keeps a unit-only value such as "m"+// while its number input is empty. Neither names a window, so accept only the complete duration+// that the step schema accepts. The alternation is the grammar the API and the worker already+// share: it keeps each digit run owned by one quantifier, where `\d*\.?\d+` lets both claim the+// same digits and backtracks quadratically on a long stored value that never matches.+const COMPLETE_DURATION_PATTERN = /^([0-9]+(?:\.[0-9]+)?|\.[0-9]+)([dhms])$/++// The executor holds a wait to the ceiling of its unit, and the API stores a larger amount+// unchanged. Use the same ceilings here so the label names the window the wait really honors.+const MAX_WAIT_AMOUNT_FOR_UNIT: Record<string, number> = {+ d: 30,+ h: 24,+ m: 60,+ s: 60,+}+export function isBranchingAction(action: Pick<HogFlowAction, 'type'>): boolean {return BRANCHING_ACTION_TYPES.includes(action.type as (typeof BRANCHING_ACTION_TYPES)[number])}+export function getWaitTimeoutLabel(maxWaitDuration: string | undefined): string | null {+ const parts = COMPLETE_DURATION_PATTERN.exec(maxWaitDuration ?? '')+ if (!parts) {+ return null+ }+ const [, amount, unit] = parts+ return `${Math.min(parseFloat(amount), MAX_WAIT_AMOUNT_FOR_UNIT[unit])}${unit}`+}+export function getWorkflowBranchLabel(action: HogFlowAction | undefined, edge: HogFlowEdge): string {+ if (action?.type === 'wait_until_condition') {+ if (edge.type === 'continue') {+ const timeout = getWaitTimeoutLabel(action.config.max_wait_duration)+ return timeout ? `No match within ${timeout}` : 'No match'+ }+ const { condition, events } = action.config+ if (condition?.name) {+ return condition.name+ }+ // The editor leaves an entry behind when the last event is removed, and the runtime skips+ // an entry that targets no event and no action. Such an entry cannot resolve the wait, so+ // it must not name an event here.+ const waitsForEvent = events?.some(+ (eventConfig) =>+ (eventConfig.filters?.events?.length ?? 0) > 0 || (eventConfig.filters?.actions?.length ?? 0) > 0+ )+ if (!waitsForEvent) {+ return 'Condition matched'+ }+ // The property condition and the events resolve the wait through this same edge, so a wait+ // that sets both must not name only one of them.+ const filters = condition?.filters+ const hasConditionFilters =+ (filters?.properties?.length ?? 0) > 0 ||+ (filters?.events?.length ?? 0) > 0 ||+ (filters?.actions?.length ?? 0) > 0+ return hasConditionFilters ? 'Condition or event matched' : 'Event received'+ }if (edge.type === 'continue') {- return 'No match'+ // A random cohort split scales its weights to their total and always picks a cohort, so this+ // edge carries the leftover of an unusable split rather than a share of the traffic.+ return action?.type === 'random_cohort_branch' ? 'Fallback if no cohort has traffic' : 'No match'}if (!action) {@@ -36,8 +91,6 @@ export function getWorkflowBranchLabel(action: HogFlowAction | undefined, edge:}switch (action.type) {- case 'wait_until_condition':- return action.config.condition?.name || 'If condition matches'case 'random_cohort_branch':return action.config.cohorts?.[edge.index ?? 0]?.name || `If cohort #${(edge.index ?? 0) + 1} matches`case 'conditional_branch':diff --git a/products/workflows/frontend/Workflows/hogflows/tree/workflowTreePresentation.ts b/products/workflows/frontend/Workflows/hogflows/tree/workflowTreePresentation.tsnew file mode 100644index 000000000000..8e7f010f3f64--- /dev/null+++ b/products/workflows/frontend/Workflows/hogflows/tree/workflowTreePresentation.ts@@ -0,0 +1,91 @@+import type { HogFlowEdge } from '../types'+import type { WorkflowTreeBranch, WorkflowTreeNode, WorkflowTreeSequence } from './workflowTree'++export const WORKFLOW_TREE_BRANCH_LIMIT = 6++export interface WorkflowTreePath {+ node: WorkflowTreeNode+ branch: WorkflowTreeBranch+}++export interface WorkflowTreeNodeViewState {+ branchesOpen?: boolean+ collapsedBranches?: Set<string>+ showAllBranches?: boolean+}++export function getWorkflowTreeOccurrenceKey(actionId: string, path: HogFlowEdge[]): string {+ return encodeURIComponent(JSON.stringify([path.map((edge) => [edge.from, edge.type, edge.index]), actionId]))+}++export function getWorkflowTreeStepId(actionId: string, path: HogFlowEdge[]): string {+ return `workflow-tree-step-${actionId}${path.length ? `-${getWorkflowTreeOccurrenceKey(actionId, path)}` : ''}`+}++export function findWorkflowTreePath(sequence: WorkflowTreeSequence, edges: HogFlowEdge[]): WorkflowTreePath[] {+ const [edge, ...remainingEdges] = edges+ if (!edge) {+ return []+ }+ for (const node of sequence.nodes) {+ for (const branch of node.branches) {+ const path = { node, branch }+ if (branch.edge.from === edge.from && branch.edge.type === edge.type && branch.edge.index === edge.index) {+ if (remainingEdges.length === 0) {+ return [path]+ }+ const nestedPath = findWorkflowTreePath(branch.sequence, remainingEdges)+ return nestedPath.length ? [path, ...nestedPath] : []+ }+ }+ }+ return []+}++export function getWorkflowTreeContinuationPath(+ tree: WorkflowTreeSequence,+ path: HogFlowEdge[],+ actionId: string+): HogFlowEdge[] {+ for (let depth = path.length; depth > 0; depth--) {+ const ancestorPath = path.slice(0, depth)+ const sequence = findWorkflowTreePath(tree, ancestorPath).at(-1)?.branch.sequence+ if (sequence?.nodes.some((node) => node.action.id === actionId)) {+ return ancestorPath+ }+ }+ return []+}++function collectStepIds(sequence: WorkflowTreeSequence, stepIds: Set<string>): void {+ for (const node of sequence.nodes) {+ stepIds.add(node.action.id)+ for (const branch of node.branches) {+ collectStepIds(branch.sequence, stepIds)+ }+ }+}++export function getWorkflowTreeStepIds(sequence: WorkflowTreeSequence): Set<string> {+ const stepIds = new Set<string>()+ collectStepIds(sequence, stepIds)+ return stepIds+}++function getPathDestination(sequence: WorkflowTreeSequence): string {+ const lastNode = sequence.nodes.at(-1)+ if (lastNode?.action.type === 'exit') {+ return 'End workflow'+ }+ if (lastNode?.branches.length) {+ const destinations = new Set(lastNode.branches.map((branch) => getPathDestination(branch.sequence)))+ return destinations.size === 1 ? [...destinations][0] : 'Paths have different destinations'+ }+ return 'No next step'+}++export function getWorkflowTreeBranchSummary(node: WorkflowTreeNode, branch: WorkflowTreeBranch): string {+ const count = getWorkflowTreeStepIds(branch.sequence).size+ const destination = node.joinAction ? `Continue to: ${node.joinAction.name}` : getPathDestination(branch.sequence)+ return `${count} ${count === 1 ? 'step' : 'steps'} · ${destination}`+}