: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): record how a step drag ends on the tile canvas (#128255)
Michael Reichenbach8e767063aef7
diff --git a/products/workflows/frontend/Workflows/hogflows/editor/tile-canvas/TileStepNode.tsx b/products/workflows/frontend/Workflows/hogflows/editor/tile-canvas/TileStepNode.tsxindex ba00fb389384..6d1befc3e832 100644--- a/products/workflows/frontend/Workflows/hogflows/editor/tile-canvas/TileStepNode.tsx+++ b/products/workflows/frontend/Workflows/hogflows/editor/tile-canvas/TileStepNode.tsx@@ -82,7 +82,7 @@ export function TileStepNode({}: undefined}- onDragEnd={draggable ? endDraggingStep : undefined}+ onDragEnd={draggable ? (event) => endDraggingStep(event.dataTransfer.dropEffect) : undefined}onContextMenu={interactive && hasStepMenu(action)? (event) => {diff --git a/products/workflows/frontend/Workflows/hogflows/editor/tile-canvas/tileCanvasLogic.test.ts b/products/workflows/frontend/Workflows/hogflows/editor/tile-canvas/tileCanvasLogic.test.tsindex 0ebb100f7ebc..d63d5ac396b1 100644--- a/products/workflows/frontend/Workflows/hogflows/editor/tile-canvas/tileCanvasLogic.test.ts+++ b/products/workflows/frontend/Workflows/hogflows/editor/tile-canvas/tileCanvasLogic.test.ts@@ -281,6 +281,8 @@ describe('tileCanvasLogic', () => {logic.values.workflow.edges.find((candidate) => candidate.from === from && candidate.to === to)const edgePairs = (): string[] =>logic.values.workflow.edges.map((candidate) => `${candidate.from}->${candidate.to}`).sort()+ const dragEndedCalls = (capture: jest.SpyInstance): unknown[][] =>+ capture.mock.calls.filter(([event]) => event === 'workflows tile canvas step drag ended')beforeEach(async () => {jest.mocked(loadAppMetricsTotals).mockResolvedValue({})@@ -296,7 +298,9 @@ describe('tileCanvasLogic', () => {logic.actions.startDraggingStep('b2')logic.actions.dropAt(edge('split', 'b1') as HogFlowEdge)- logic.actions.endDraggingStep()+ // The moved tile can re-render before its dragend, so the drop itself must send the event.+ const atDrop = dragEndedCalls(capture)+ logic.actions.endDraggingStep('move')expect(edgePairs()).toEqual([@@ -314,6 +318,25 @@ describe('tileCanvasLogic', () => {source: 'drag',step_type: 'delay',})+ const moved = [['workflows tile canvas step drag ended', { outcome: 'moved', step_type: 'delay' }]]+ expect(atDrop).toEqual(moved)+ expect(dragEndedCalls(capture)).toEqual(moved)+ })++ it('records a drag let go away from every + with the drop effect the browser reported', async () => {+ const before = edgePairs()+ const capture = jest.spyOn(posthog, 'capture')++ logic.actions.startDraggingStep('b2')+ logic.actions.endDraggingStep('none')++ expect(edgePairs()).toEqual(before)+ expect(logic.values.isMovingNode).toBe(false)+ expect(capture).toHaveBeenCalledWith('workflows tile canvas step drag ended', {+ outcome: 'let_go_elsewhere',+ step_type: 'delay',+ drop_effect: 'none',+ })})it.each(['trigger_node', 'split', 'exit_node'])('does not let %s be dragged', async (actionId) => {@@ -367,10 +390,16 @@ describe('tileCanvasLogic', () => {expect(logic.values.placeableEdgeKeys).toContain(getEdgeId(edge('a2', 'join') as HogFlowEdge))logic.actions.dropAt(edge('join', 'exit_node') as HogFlowEdge)- logic.actions.endDraggingStep()+ const atDrop = dragEndedCalls(capture)+ logic.actions.endDraggingStep('move')expect(edgePairs()).toEqual(before)expect(capture).not.toHaveBeenCalledWith('workflows tile canvas step moved', expect.anything())+ const noSpot = [+ ['workflows tile canvas step drag ended', { outcome: 'no_matching_spot', step_type: 'delay' }],+ ]+ expect(atDrop).toEqual(noSpot)+ expect(dragEndedCalls(capture)).toEqual(noSpot)})})diff --git a/products/workflows/frontend/Workflows/hogflows/editor/tile-canvas/tileCanvasLogic.ts b/products/workflows/frontend/Workflows/hogflows/editor/tile-canvas/tileCanvasLogic.tsindex 377889960c70..e7a51589dcb1 100644--- a/products/workflows/frontend/Workflows/hogflows/editor/tile-canvas/tileCanvasLogic.ts+++ b/products/workflows/frontend/Workflows/hogflows/editor/tile-canvas/tileCanvasLogic.ts@@ -68,6 +68,13 @@ export type TileCanvasPanelMode = HogFlowEditorMode | 'history'export type StepAddSource = 'palette' | 'command bar' | 'quick add' | 'drag'export type StepMoveSource = 'menu' | 'drag'+export type StepDragOutcome = 'moved' | 'no_matching_spot' | 'let_go_elsewhere'++interface StepDrag {+ stepType: string+ dropped: boolean+}+export type StepCountOf = (actionId: string) => number | undefinedexport type TemplateNameOf = (templateId: string) => string | undefined@@ -123,6 +130,14 @@ function captureStepAdded(source: StepAddSource, stepType: string): void {posthog.capture('workflows tile canvas step added', { source, step_type: stepType })}+function captureStepDragEnded(outcome: StepDragOutcome, stepType: string, dropEffect?: string | null): void {+ posthog.capture('workflows tile canvas step drag ended', {+ outcome,+ step_type: stepType,+ ...(dropEffect !== undefined ? { drop_effect: dropEffect } : {}),+ })+}+const SURFACES_WITH_THEIR_OWN_KEYS = ['input','textarea',@@ -294,8 +309,8 @@ export interface tileCanvasLogicActions {dropAt: (edge: HogFlowEdge) => {edge: HogFlowEdge}- endDraggingStep: () => {- value: true+ endDraggingStep: (dropEffect?: string | null) => {+ dropEffect: string | null}fitNextLayout: () => {value: true@@ -532,7 +547,7 @@ export const tileCanvasLogic = kea<tileCanvasLogicType>([setDropTargetEdgeKey: (edgeKey: string | null) => ({ edgeKey }),dropAt: (edge: HogFlowEdge) => ({ edge }),startDraggingStep: (actionId: string) => ({ actionId }),- endDraggingStep: true,+ endDraggingStep: (dropEffect: string | null = null) => ({ dropEffect }),selectStep: (actionId: string) => ({ actionId }),revealStep: (actionId: string, openPanel: boolean = true) => ({ actionId, openPanel }),openPanel: (mode: TileCanvasPanelMode) => ({ mode }),@@ -792,9 +807,19 @@ export const tileCanvasLogic = kea<tileCanvasLogicType>([actions.setOpenPathIds([...new Set([...values.openPathIds, ...containing.map((group) => group.id)])])actions.focusPathAfterLayout(innermost.id)}+ const recordStepDrop = (outcome: StepDragOutcome): void => {+ const drag = cache.stepDrag as StepDrag | null | undefined+ if (drag && !drag.dropped) {+ drag.dropped = true+ captureStepDragEnded(outcome, drag.stepType)+ }+ }const placeExistingStep = (edge: HogFlowEdge, source: StepMoveSource): void => {const dropzone = values.dropzoneNodes.find((zone) => zone.data.edge.id === getEdgeId(edge))if (!dropzone) {+ if (source === 'drag') {+ recordStepDrop('no_matching_spot')+ }return}actions.setHighlightedDropzoneNodeId(dropzone.id)@@ -802,6 +827,9 @@ export const tileCanvasLogic = kea<tileCanvasLogicType>([const stepType = values.nodesById[values.movingNodeId ?? '']?.data.typeactions.moveNodeToHighlightedDropzone()posthog.capture('workflows tile canvas step moved', { source, step_type: stepType })+ if (source === 'drag') {+ recordStepDrop('moved')+ }} else {actions.copyNodeToHighlightedDropzone()}@@ -883,13 +911,20 @@ export const tileCanvasLogic = kea<tileCanvasLogicType>([actions.setNodeToBeAdded(null)dropPendingMoveOrCopy()actions.startMovingNode(node)+ cache.stepDrag = { stepType: node.data.type, dropped: false }posthog.capture('workflows tile canvas step drag started', { step_type: node.data.type })},- endDraggingStep: () => {+ endDraggingStep: ({ dropEffect }) => {// A drop that moved the step already ended the move, so only a drag let go elsewhere is still moving.if (values.isMovingNode) {actions.stopMovingNode()}+ const drag = cache.stepDrag as StepDrag | null | undefined+ // The browser reports dropEffect "none" when no drop target accepted the drag.+ if (drag && !drag.dropped) {+ captureStepDragEnded('let_go_elsewhere', drag.stepType, dropEffect)+ }+ cache.stepDrag = null},dropAt: ({ edge }) => {const step = values.nodeToBeAdded