diff --git a/frontend/src/queries/nodes/InsightQuery/utils/cleanProperties.test.ts b/frontend/src/queries/nodes/InsightQuery/utils/cleanProperties.test.ts index 97c388dd7d9dc..12bc28757ea8b 100644 --- a/frontend/src/queries/nodes/InsightQuery/utils/cleanProperties.test.ts +++ b/frontend/src/queries/nodes/InsightQuery/utils/cleanProperties.test.ts @@ -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' }]) + }) }) diff --git a/frontend/src/queries/nodes/InsightQuery/utils/cleanProperties.ts b/frontend/src/queries/nodes/InsightQuery/utils/cleanProperties.ts index 4474b6423dbf6..82edbfb56cfb9 100644 --- a/frontend/src/queries/nodes/InsightQuery/utils/cleanProperties.ts +++ b/frontend/src/queries/nodes/InsightQuery/utils/cleanProperties.ts @@ -142,6 +142,14 @@ const cleanProperty = (property: Record): 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)