: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): show global property filters on the event trigger (#88923)
posthog[bot]96e7582a9771
diff --git a/frontend/snapshots.yml b/frontend/snapshots.ymlindex 7e80e882780e..5e67d459b30c 100644--- a/frontend/snapshots.yml+++ b/frontend/snapshots.yml@@ -6333,9 +6333,9 @@ snapshots:products-workflows-editor-configuration-panel--test--light:hash: v1.k794b7964.77e439c596febbef403bb59ac7479c423a034cca8657970821ac4ec0918584cb.VyTiPbd6I_VSVPXWvG_w1csrciseUEIxMYL7WX2EdP8products-workflows-editor-configuration-panel--trigger--dark:- hash: v1.k794b7964.f87dda2f9c27f65bcc6745d1732801fc46f364ffdbd880b912d786822f9bbf0a.8qefE9GrPI_A7rK73q8D4TyBYQB1mLlkASC8YTOB_P4+ hash: v1.k794b7964.24086e087c3259ab0632a32e834c80d15ddc7d5349ce2a8a58ad30c6a6ac3a3a.uGTkRrvb873NTEKX0jum4ltekgUmsIbbDvZclDSdlOMproducts-workflows-editor-configuration-panel--trigger--light:- hash: v1.k794b7964.42af8e81ab682f18d4918aa28718b5c611925a9325b50b7ade47ebb247ccd08f.Im6_Ee5xssBUgp9NJbkJ25j98_Tar3bl6v4Uf5LAiFg+ hash: v1.k794b7964.2e2669fec49872d5656b14d5ddcea2b4c95d17161b5f30b052e57281cc0c8956.Y6RgOCfSDzZ_j_3N-HLCpG70wNfx3WqlmBBGspAbqrQproducts-workflows-editor-configuration-panel--variables--dark:hash: v1.k794b7964.c936a553b0ecd3a1a7cd478e4848cb6ad5d3c7c566e7c47aca7c164b663ce106.PFeB3oTy3Wr4fmTcYgVv56Ur35h7UpA9BOFeO-8Y63sproducts-workflows-editor-configuration-panel--variables--light:diff --git a/products/workflows/frontend/Workflows/hogflows/steps/StepTrigger.test.tsx b/products/workflows/frontend/Workflows/hogflows/steps/StepTrigger.test.tsxnew file mode 100644index 000000000000..6c7c7218b6c4--- /dev/null+++ b/products/workflows/frontend/Workflows/hogflows/steps/StepTrigger.test.tsx@@ -0,0 +1,95 @@+import '@testing-library/jest-dom'++import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react'+import { Node } from '@xyflow/react'+import { BindLogic } from 'kea'++import { recentTaxonomicFiltersLogic } from 'lib/components/TaxonomicFilter/recentTaxonomicFiltersLogic'++import { useMocks } from '~/mocks/jest'+import { actionsModel } from '~/models/actionsModel'+import { groupsModel } from '~/models/groupsModel'+import { propertyDefinitionsModel } from '~/models/propertyDefinitionsModel'+import { initKeaTests } from '~/test/init'+import { mockActionDefinition, mockGetEventDefinitions, mockGetPropertyDefinitions } from '~/test/mocks'++import { WorkflowLogicProps, workflowLogic } from '../../workflowLogic'+import { HogFlowAction } from '../types'+import { StepTriggerConfiguration } from './StepTrigger'++type TriggerAction = Extract<HogFlowAction, { type: 'trigger' }>++const LOGIC_PROPS: WorkflowLogicProps = { id: 'new' }++describe('StepTriggerConfiguration', () => {+ let unmountWorkflowLogic: (() => void) | null = null++ beforeEach(() => {+ useMocks({+ get: {+ '/api/projects/:team/event_definitions': mockGetEventDefinitions,+ '/api/projects/:team/property_definitions': mockGetPropertyDefinitions,+ '/api/projects/:team/actions': { results: [mockActionDefinition] },+ '/api/environments/:team/persons/properties': [],+ '/api/environments/:team/events/values': { results: [], refreshing: false },+ '/api/environments/:team_id/quick_filters/': { results: [] },+ },+ post: {+ '/api/environments/:team/query': { results: [] },+ },+ })+ initKeaTests()+ actionsModel.mount()+ groupsModel.mount()+ propertyDefinitionsModel.mount()+ recentTaxonomicFiltersLogic.mount()+ unmountWorkflowLogic = workflowLogic(LOGIC_PROPS).mount()+ })++ afterEach(() => {+ unmountWorkflowLogic?.()+ unmountWorkflowLogic = null+ cleanup()+ })++ function renderTrigger(properties: NonNullable<HogFlowAction['filters']>['properties']): void {+ const action = {+ id: 'trigger_node',+ type: 'trigger',+ name: 'Trigger',+ description: '',+ config: { type: 'event', filters: { events: [], properties } },+ } as TriggerAction+ render(+ <BindLogic logic={workflowLogic} props={LOGIC_PROPS}>+ <StepTriggerConfiguration node={{ id: action.id, data: action } as Node<TriggerAction>} />+ </BindLogic>+ )+ }++ it('keeps a stored global property filter when the trigger events change', async () => {+ const properties = [{ type: 'hogql', key: "properties.plan = 'pro'" }] as NonNullable<+ HogFlowAction['filters']+ >['properties']+ renderTrigger(properties)++ fireEvent.click(screen.getByText('Add trigger event'))++ await waitFor(() => {+ const trigger = workflowLogic(LOGIC_PROPS).values.workflow.trigger as TriggerAction['config']+ expect(trigger.type).toEqual('event')+ expect((trigger as Extract<TriggerAction['config'], { type: 'event' }>).filters?.properties).toEqual(+ properties+ )+ })+ })++ it('shows a global HogQL property filter stored on the event trigger', async () => {+ renderTrigger([{ type: 'hogql', key: "properties.plan = 'pro'" }])++ expect(screen.getByText('Additional filters')).toBeInTheDocument()+ await waitFor(() => {+ expect(screen.getByText("properties.plan = 'pro'")).toBeInTheDocument()+ })+ })+})diff --git a/products/workflows/frontend/Workflows/hogflows/steps/StepTrigger.tsx b/products/workflows/frontend/Workflows/hogflows/steps/StepTrigger.tsxindex a2b8eae6b6b4..1f504f396480 100644--- a/products/workflows/frontend/Workflows/hogflows/steps/StepTrigger.tsx+++ b/products/workflows/frontend/Workflows/hogflows/steps/StepTrigger.tsx@@ -55,7 +55,7 @@ import { ACCOUNT_CUSTOM_PROPERTY_OPERATOR_ALLOWLIST } from 'products/customer_animport 'products/workflows/frontend/Workflows/hogflows/registry/triggers'import { workflowLogic } from '../../workflowLogic'-import { HogFlowEventFilters, WORKFLOW_OPERATOR_ALLOWLIST } from '../filters/HogFlowFilters'+import { HogFlowEventFilters, HogFlowPropertyFilters, WORKFLOW_OPERATOR_ALLOWLIST } from '../filters/HogFlowFilters'import { TriggerFrequencyOption, getRegisteredTriggerTypes } from '../registry/triggers/triggerTypeRegistry'import { HogFlowAction } from '../types'import { createAccountAssignmentFilterUpdate, parseAccountAssignmentFilter } from './accountAssignmentFilter'@@ -417,7 +417,13 @@ function StepTriggerConfigurationEvents({setFilters={(filters) =>setWorkflowActionConfig(action.id, {type: 'event',- filters: { ...filters, filter_test_accounts: filterTestAccounts },+ // The event filter only returns events/actions, so carry the global+ // property array through or an event edit drops it.+ filters: {+ ...filters,+ properties: config.filters?.properties,+ filter_test_accounts: filterTestAccounts,+ },})}filtersKey={`workflow-trigger-${action.id}`}@@ -426,6 +432,23 @@ function StepTriggerConfigurationEvents({/></LemonField.Pure>+ <LemonField.Pure+ label="Additional filters"+ info="These filters apply to every trigger event above. Use them for conditions shared across all events, such as a SQL expression."+ >+ <HogFlowPropertyFilters+ filters={config.filters ?? {}}+ setFilters={(filters) =>+ setWorkflowActionConfig(action.id, {+ type: 'event',+ filters: { ...config.filters, properties: filters?.properties ?? [] },+ })+ }+ filtersKey={`workflow-trigger-${action.id}`}+ buttonCopy="Add filter"+ />+ </LemonField.Pure>+<TestAccountFilterfilters={{ filter_test_accounts: filterTestAccounts }}onChange={({ filter_test_accounts }) =>