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.

fix(workflows): keep every stored event entry in goal and wait editors (#127109)

Michael Reichenbacha650806c764f
diff --git a/frontend/src/lib/constants.tsx b/frontend/src/lib/constants.tsx
index a3ba54a3eb73..f1d88dbbcbb7 100644
--- a/frontend/src/lib/constants.tsx
+++ b/frontend/src/lib/constants.tsx
@@ -625,6 +625,7 @@ export const FEATURE_FLAGS = {
WORKFLOWS_EMAIL_DOMAIN_AGENT_SETUP: 'workflows-email-domain-agent-setup', // owner: @silthus #team-workflows
WORKFLOWS_EMAIL_DOMAIN_WIZARD: 'workflows-email-domain-wizard', // owner: @silthus #team-workflows
WORKFLOWS_EMAIL_SENDER_ROTATION: 'workflows-email-sender-rotation', // owner: @arthurdedeus #team-workflows
+ WORKFLOWS_GOAL_EVENT_ENTRIES: 'workflows-goal-event-entries', // owner: @silthus #team-workflows, shows and keeps every stored event entry in goal and wait step editors
WORKFLOWS_INTERNAL_EVENT_FILTERS: 'workflows-internal-event-filters', // owner: @haven #team-workflows
WORKFLOWS_LINEAR_VIEW: 'workflows-linear-view', // owner: #team-workflows
WORKFLOWS_PUSH_NOTIFICATIONS: 'workflows-push-notifications', // owner: #team-workflows
diff --git a/products/workflows/frontend/Workflows/hogflows/steps/StepWaitUntilCondition.tsx b/products/workflows/frontend/Workflows/hogflows/steps/StepWaitUntilCondition.tsx
index c749704d8795..408132e150e2 100644
--- a/products/workflows/frontend/Workflows/hogflows/steps/StepWaitUntilCondition.tsx
+++ b/products/workflows/frontend/Workflows/hogflows/steps/StepWaitUntilCondition.tsx
@@ -8,11 +8,12 @@ import { useFeatureFlag } from 'lib/hooks/useFeatureFlag'
import { LemonInput } from 'lib/lemon-ui/LemonInput'
import { workflowLogic } from '../../workflowLogic'
-import { HogFlowEventFilters, HogFlowPropertyFilters } from '../filters/HogFlowFilters'
+import { HogFlowPropertyFilters } from '../filters/HogFlowFilters'
import { HogFlowAction } from '../types'
import { joinCohortMembershipEntry, splitCohortMembershipEntry } from './components/cohortMembershipEvent'
import { CohortMembershipEventPicker } from './components/CohortMembershipEventPicker'
import { HogFlowDuration } from './components/HogFlowDuration'
+import { HogFlowEventEntriesFilters } from './components/HogFlowEventEntriesFilters'
import { StepSchemaErrors } from './components/StepSchemaErrors'
import { useDebouncedNameInput } from './utils'
@@ -32,7 +33,6 @@ export function StepWaitUntilConditionConfiguration({
const cohortConditionsEnabled = useFeatureFlag('WORKFLOWS_COHORT_CONDITIONS')
const { eventEntries, cohort } = splitCohortMembershipEntry(events)
- const eventFilters = eventEntries[0]?.filters ?? {}
return (
<>
@@ -46,12 +46,11 @@ export function StepWaitUntilConditionConfiguration({
<span className="text-xs text-muted">
The workflow continues on the matched path when any of these events fire.
</span>
- <HogFlowEventFilters
- filtersKey={`wait-until-events-${action.id}`}
- filters={eventFilters}
- setFilters={(newFilters) =>
+ <HogFlowEventEntriesFilters
+ entries={eventEntries}
+ onChange={(nextEventEntries) =>
partialSetWorkflowActionConfig(action.id, {
- events: joinCohortMembershipEntry(newFilters ? [{ filters: newFilters }] : [], cohort),
+ events: joinCohortMembershipEntry(nextEventEntries, cohort),
})
}
typeKey="workflow-wait-until-event"
diff --git a/products/workflows/frontend/Workflows/hogflows/steps/components/ConversionGoalEditor.test.tsx b/products/workflows/frontend/Workflows/hogflows/steps/components/ConversionGoalEditor.test.tsx
new file mode 100644
index 000000000000..48941ff5c8d8
--- /dev/null
+++ b/products/workflows/frontend/Workflows/hogflows/steps/components/ConversionGoalEditor.test.tsx
@@ -0,0 +1,106 @@
+import '@testing-library/jest-dom'
+
+import { cleanup, fireEvent, render, screen, within } from '@testing-library/react'
+import { BindLogic } from 'kea'
+
+import { FEATURE_FLAGS } from 'lib/constants'
+import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
+
+import { useMocks } from '~/mocks/jest'
+import { actionsModel } from '~/models/actionsModel'
+import { groupsModel } from '~/models/groupsModel'
+import { initKeaTests } from '~/test/init'
+
+import { WorkflowLogicProps, workflowLogic } from '../../../workflowLogic'
+import { ConversionGoalEditor, ConversionGoalValue } from './ConversionGoalEditor'
+
+const LOGIC_PROPS: WorkflowLogicProps = { id: 'new' }
+
+const downloadedFileEntry = {
+ filters: {
+ events: [
+ { id: 'downloaded_file', name: 'downloaded_file', type: 'events', order: 0 },
+ { id: 'opened_invite', name: 'opened_invite', type: 'events', order: 1 },
+ ],
+ properties: [{ key: 'plan', value: 'pro', operator: 'exact', type: 'person' }],
+ },
+}
+const signedUpEntry = {
+ filters: { events: [{ id: 'signed_up', name: 'signed_up', type: 'events', order: 0 }] },
+}
+
+describe('ConversionGoalEditor', () => {
+ let unmountWorkflowLogic: (() => void) | null = null
+
+ beforeEach(() => {
+ useMocks({
+ get: {
+ '/api/projects/:team/event_definitions': { results: [], count: 0 },
+ '/api/projects/:team/actions': { results: [] },
+ },
+ })
+ initKeaTests()
+ actionsModel.mount()
+ groupsModel.mount()
+ featureFlagLogic.mount()
+ unmountWorkflowLogic = workflowLogic(LOGIC_PROPS).mount()
+ })
+
+ afterEach(() => {
+ unmountWorkflowLogic?.()
+ unmountWorkflowLogic = null
+ cleanup()
+ })
+
+ function renderEditor(allEntriesEnabled: boolean): jest.Mock {
+ featureFlagLogic.actions.setFeatureFlags([], {
+ [FEATURE_FLAGS.WORKFLOWS_GOAL_EVENT_ENTRIES]: allEntriesEnabled,
+ })
+ const onChange = jest.fn()
+ const conversion: ConversionGoalValue = { filters: [], events: [downloadedFileEntry, signedUpEntry] }
+ render(
+ <BindLogic logic={workflowLogic} props={LOGIC_PROPS}>
+ <ConversionGoalEditor conversion={conversion} onChange={onChange} pageKey="goal" />
+ </BindLogic>
+ )
+ return onChange
+ }
+
+ it.each([
+ {
+ flag: 'on',
+ allEntriesEnabled: true,
+ firstEntryProperties: downloadedFileEntry.filters.properties,
+ otherEntries: [signedUpEntry],
+ },
+ { flag: 'off', allEntriesEnabled: false, firstEntryProperties: undefined, otherEntries: [] },
+ ])(
+ 'with the flag $flag, an event edit writes the expected entries',
+ async ({ allEntriesEnabled, firstEntryProperties, otherEntries }) => {
+ const onChange = renderEditor(allEntriesEnabled)
+
+ fireEvent.click(screen.getByTestId('more-button-1'))
+ fireEvent.click(await screen.findByTestId('delete-prop-filter-1'))
+
+ const [firstEntry, ...restEntries] = onChange.mock.lastCall[0].events
+ expect(Object.keys(firstEntry)).toEqual(['filters'])
+ expect(firstEntry.filters.events).toEqual([downloadedFileEntry.filters.events[0]])
+ expect(firstEntry.filters.properties).toEqual(firstEntryProperties)
+ expect(restEntries).toEqual(otherEntries)
+ expect(screen.queryByText('signed_up') !== null).toBe(allEntriesEnabled)
+ }
+ )
+
+ it("shows an entry's own property filters and removes one from that entry only", () => {
+ const onChange = renderEditor(true)
+
+ const propertyFilter = screen.getByText(/plan/).closest('.PropertyFilterButton') as HTMLElement
+ fireEvent.click(within(propertyFilter).getByRole('button'))
+
+ expect(onChange).toHaveBeenLastCalledWith(
+ expect.objectContaining({
+ events: [{ filters: { ...downloadedFileEntry.filters, properties: [] } }, signedUpEntry],
+ })
+ )
+ })
+})
diff --git a/products/workflows/frontend/Workflows/hogflows/steps/components/ConversionGoalEditor.tsx b/products/workflows/frontend/Workflows/hogflows/steps/components/ConversionGoalEditor.tsx
index 0941f7d4650c..fff5606e7d77 100644
--- a/products/workflows/frontend/Workflows/hogflows/steps/components/ConversionGoalEditor.tsx
+++ b/products/workflows/frontend/Workflows/hogflows/steps/components/ConversionGoalEditor.tsx
@@ -5,10 +5,11 @@ import { PropertyFilters } from 'lib/components/PropertyFilters/PropertyFilters'
import { TaxonomicFilterGroupType } from 'lib/components/TaxonomicFilter/types'
import { useFeatureFlag } from 'lib/hooks/useFeatureFlag'
-import { HogFlowEventFilters, WORKFLOW_OPERATOR_ALLOWLIST } from '../../filters/HogFlowFilters'
+import { WORKFLOW_OPERATOR_ALLOWLIST } from '../../filters/HogFlowFilters'
import { joinCohortMembershipEntry, splitCohortMembershipEntry } from './cohortMembershipEvent'
import { CohortMembershipEventPicker } from './CohortMembershipEventPicker'
import { HogFlowDuration, MAX_CONVERSION_WINDOW_FOR_DURATION_UNIT } from './HogFlowDuration'
+import { HogFlowEventEntriesFilters } from './HogFlowEventEntriesFilters'
// Structural shape of a workflow conversion goal, compatible with both the frontend HogFlow
// type and the generated HogFlowConversionApi type.
@@ -31,7 +32,6 @@ const DEFAULT_CONVERSION_WINDOW = '90d'
export function ConversionGoalEditor({ conversion, onChange, pageKey }: ConversionGoalEditorProps): JSX.Element {
const cohortConditionsEnabled = useFeatureFlag('WORKFLOWS_COHORT_CONDITIONS')
const { eventEntries, cohort } = splitCohortMembershipEntry(conversion?.events)
- const conversionEventFilters = eventEntries[0]?.filters ?? {}
const conversionWindow = conversion?.window ?? DEFAULT_CONVERSION_WINDOW
return (
@@ -56,14 +56,13 @@ export function ConversionGoalEditor({ conversion, onChange, pageKey }: Conversi
<div className="flex flex-col gap-1 items-start w-full">
<LemonLabel>Detect conversion from events</LemonLabel>
- <HogFlowEventFilters
- filtersKey={`${pageKey}-events`}
- filters={conversionEventFilters}
- setFilters={(newFilters) =>
+ <HogFlowEventEntriesFilters
+ entries={eventEntries}
+ onChange={(nextEventEntries) =>
onChange({
filters: [],
...conversion,
- events: joinCohortMembershipEntry(newFilters ? [{ filters: newFilters }] : [], cohort),
+ events: joinCohortMembershipEntry(nextEventEntries, cohort),
})
}
typeKey={`${pageKey}-event`}
diff --git a/products/workflows/frontend/Workflows/hogflows/steps/components/HogFlowEventEntriesFilters.tsx b/products/workflows/frontend/Workflows/hogflows/steps/components/HogFlowEventEntriesFilters.tsx
new file mode 100644
index 000000000000..6436c6e7ca90
--- /dev/null
+++ b/products/workflows/frontend/Workflows/hogflows/steps/components/HogFlowEventEntriesFilters.tsx
@@ -0,0 +1,75 @@
+import { Fragment } from 'react'
+
+import { useFeatureFlag } from 'lib/hooks/useFeatureFlag'
+
+import { HogFlowEventFilters, HogFlowFiltersProps, HogFlowPropertyFilters } from '../../filters/HogFlowFilters'
+import { EventEntry } from './cohortMembershipEvent'
+
+export interface HogFlowEventEntriesFiltersProps extends Pick<
+ HogFlowFiltersProps,
+ 'buttonCopy' | 'excludeGroupProperties'
+> {
+ entries: EventEntry[]
+ onChange: (entries: EventEntry[]) => void
+ typeKey: string
+}
+
+export function HogFlowEventEntriesFilters({
+ entries,
+ onChange,
+ typeKey,
+ ...filterProps
+}: HogFlowEventEntriesFiltersProps): JSX.Element {
+ const allEntriesEnabled = useFeatureFlag('WORKFLOWS_GOAL_EVENT_ENTRIES')
+
+ if (!allEntriesEnabled) {
+ return (
+ <HogFlowEventFilters
+ {...filterProps}
+ filtersKey={typeKey}
+ typeKey={typeKey}
+ filters={entries[0]?.filters ?? {}}
+ setFilters={(filters) => onChange(filters ? [{ filters }] : [])}
+ />
+ )
+ }
+
+ const shownEntries: EventEntry[] = entries.length ? entries : [{}]
+ const replaceEntry = (index: number, nextEntry: EventEntry): void =>
+ onChange(shownEntries.map((entry, i) => (i === index ? nextEntry : entry)))
+
+ return (
+ <div className="flex flex-col gap-2 items-start w-full">
+ {shownEntries.map((entry, index) => {
+ const entryTypeKey = `${typeKey}-${index}`
+ return (
+ <Fragment key={index}>
+ {index > 0 ? <span className="text-xs text-tertiary uppercase tracking-wide">or</span> : null}
+ <HogFlowEventFilters
+ {...filterProps}
+ filtersKey={entryTypeKey}
+ typeKey={entryTypeKey}
+ filters={entry.filters ?? {}}
+ setFilters={(filters) =>
+ replaceEntry(index, { ...entry, filters: { ...entry.filters, ...filters } })
+ }
+ />
+ {entry.filters?.properties?.length ? (
+ <HogFlowPropertyFilters
+ filtersKey={`${entryTypeKey}-properties`}
+ filters={entry.filters}
+ setFilters={(filters) =>
+ replaceEntry(index, {
+ ...entry,
+ filters: { ...entry.filters, properties: filters?.properties ?? [] },
+ })
+ }
+ excludeGroupProperties={filterProps.excludeGroupProperties}
+ />
+ ) : null}
+ </Fragment>
+ )
+ })}
+ </div>
+ )
+}