Skip to content

Commit

Permalink
fix(insights): handle negation property in cohort property filters (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
skoob13 authored Oct 18, 2024
1 parent f56e4c1 commit a585c33
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,26 @@ describe('cleanEntityProperties', () => {
},
])
})

it('handles negation for cohorts', () => {
let properties: any = [
{
key: 'id',
type: 'cohort',
value: 1,
operator: 'exact',
negation: false,
},
]
let result = cleanEntityProperties(properties)
expect(result).toEqual([{ key: 'id', type: 'cohort', value: 1, operator: 'exact' }])

properties = [{ key: 'id', type: 'cohort', value: 1, operator: 'exact', negation: true }]
result = cleanEntityProperties(properties)
expect(result).toEqual([{ key: 'id', type: 'cohort', value: 1, operator: 'not_in' }])

properties = [{ key: 'id', type: 'cohort', value: 1, negation: true }]
result = cleanEntityProperties(properties)
expect(result).toEqual([{ key: 'id', type: 'cohort', value: 1, operator: 'not_in' }])
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,14 @@ const cleanProperty = (property: Record<string, any>): AnyPropertyFilter => {
delete property['operator']
}

// convert `negation` for cohorts
if (property['type'] === 'cohort' && property['negation'] !== undefined) {
if (property['operator'] === PropertyOperator.Exact && property['negation']) {
property['operator'] = PropertyOperator.NotIn
}
delete property['negation']
}

// remove none from values
if (Array.isArray(property['value'])) {
property['value'] = property['value'].filter((x) => x !== null)
Expand Down

0 comments on commit a585c33

Please sign in to comment.