Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
thmsobrmlr committed Mar 26, 2024
1 parent 2b3dcc5 commit 75e1799
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,23 @@ describe('cleanGlobalProperties', () => {
expect(result).toEqual(properties)
})

it('handles property group filters without nested property group filter values', () => {
it('handles property group filters values', () => {
const properties = {
type: 'AND',
values: [{ key: 'id', type: 'cohort', value: 850, operator: null }],
}

const result = cleanGlobalProperties(properties)

expect(result).toEqual(properties)
expect(result).toEqual({
type: 'AND',
values: [
{
type: 'AND',
values: [{ key: 'id', type: 'cohort', value: 850 }],
},
],
})
})
})

Expand Down Expand Up @@ -100,7 +108,7 @@ describe('cleanEntityProperties', () => {
expect(result).toEqual(properties)
})

it('handles property group filters without nested property group filter values', () => {
it('handles property group values', () => {
const properties = {
type: 'AND',
values: [
Expand Down
10 changes: 10 additions & 0 deletions frontend/src/queries/nodes/InsightQuery/utils/cleanProperties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ export const cleanGlobalProperties = (
values: [{ type: 'AND', values: properties }],
}
return cleanPropertyGroupFilter(properties)
} else if (
(properties['type'] === 'AND' || properties['type'] === 'OR') &&
!properties['values'].some((property) => property['type'] === 'AND' || property['type'] === 'OR')

Check failure on line 41 in frontend/src/queries/nodes/InsightQuery/utils/cleanProperties.ts

View workflow job for this annotation

GitHub Actions / Code quality checks

Parameter 'property' implicitly has an 'any' type.
) {
// property group filter value
properties = {
type: 'AND',
values: [properties],
}
return cleanPropertyGroupFilter(properties)
} else {
// property group filter
return cleanPropertyGroupFilter(properties)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,46 @@ describe('filtersToQueryNode', () => {
expect(result).toEqual(query)
})

it('converts broken grouped properties', () => {
const filters: Partial<FilterType> = {
insight: InsightType.RETENTION,
properties: {
type: FilterLogicalOperator.And,
values: [
{
key: 'email',
type: PropertyFilterType.Person,
value: 'is_set',
operator: PropertyOperator.IsSet,
},
] as any,
},
}

const result = filtersToQueryNode(filters)

const query: InsightQueryNode = {
kind: NodeKind.RetentionQuery,
properties: {
type: FilterLogicalOperator.And,
values: [
{
type: FilterLogicalOperator.And,
values: [
{
key: 'email',
type: PropertyFilterType.Person,
value: 'is_set',
operator: PropertyOperator.IsSet,
},
],
},
],
},
} as InsightQueryNode
expect(result).toEqual(query)
})

it('converts date range', () => {
const filters: Partial<FilterType> = {
insight: InsightType.RETENTION,
Expand Down

0 comments on commit 75e1799

Please sign in to comment.