Skip to content

Commit 0b66c8f

Browse files
authored
fix(cdp): fix filter overrides for hog functions (#42222)
1 parent 18544fc commit 0b66c8f

File tree

2 files changed

+69
-1
lines changed

2 files changed

+69
-1
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import { initKeaTests } from '~/test/init'
2+
import {
3+
CyclotronJobFiltersType,
4+
HogFunctionTemplateWithSubTemplateType,
5+
PropertyFilterType,
6+
PropertyOperator,
7+
} from '~/types'
8+
9+
import { hogFunctionTemplateListLogic } from './hogFunctionTemplateListLogic'
10+
11+
describe('hogFunctionTemplateListLogic - configuration structure', () => {
12+
beforeEach(() => {
13+
initKeaTests()
14+
})
15+
16+
it('should wrap filters in configuration object, not spread at top level', () => {
17+
const alertId = 'test-alert-id-123'
18+
const getConfigurationOverrides = (): CyclotronJobFiltersType => ({
19+
properties: [
20+
{
21+
key: 'alert_id',
22+
value: alertId,
23+
operator: PropertyOperator.Exact,
24+
type: PropertyFilterType.Event,
25+
},
26+
],
27+
events: [{ id: '$insight_alert_firing', type: 'events' as const }],
28+
})
29+
30+
const logic = hogFunctionTemplateListLogic.build({
31+
type: 'destination',
32+
getConfigurationOverrides,
33+
})
34+
logic.mount()
35+
36+
const template: HogFunctionTemplateWithSubTemplateType = {
37+
id: 'template-slack',
38+
name: 'Slack',
39+
type: 'destination',
40+
status: 'stable',
41+
free: true,
42+
code: 'return event',
43+
code_language: 'hog',
44+
sub_template_id: 'insight-alert-firing',
45+
}
46+
47+
const url = logic.values.urlForTemplate(template)
48+
expect(url).toBeTruthy()
49+
50+
// Parse URL to verify structure
51+
const urlObj = new URL(url!, window.location.origin)
52+
const hashParams = new URLSearchParams(urlObj.hash.substring(1))
53+
const configuration = JSON.parse(decodeURIComponent(hashParams.get('configuration') || '{}'))
54+
55+
// filters must be wrapped, not at top level
56+
expect(configuration).toHaveProperty('filters')
57+
expect(configuration.filters).toHaveProperty('properties')
58+
expect(configuration).not.toHaveProperty('properties') // Should not be at top level
59+
})
60+
})

frontend/src/scenes/hog-functions/list/hogFunctionTemplateListLogic.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,9 +250,17 @@ export const hogFunctionTemplateListLogic = kea<hogFunctionTemplateListLogicType
250250
? getConfigurationOverrides(subTemplate?.sub_template_id)
251251
: null
252252

253+
const filters =
254+
configurationOverrides || subTemplate?.filters
255+
? {
256+
...(subTemplate?.filters ?? {}),
257+
...(configurationOverrides ?? {}),
258+
}
259+
: undefined
260+
253261
const configuration: Record<string, any> = {
254262
...subTemplate,
255-
...configurationOverrides,
263+
...(filters ? { filters } : {}),
256264
}
257265

258266
return combineUrl(

0 commit comments

Comments
 (0)