-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(insights): fix legacy transformation of properties (#21165)
- Loading branch information
1 parent
a661b4b
commit 20304fe
Showing
96 changed files
with
622 additions
and
212 deletions.
There are no files selected for viewing
Binary file modified
BIN
+314 Bytes
(100%)
frontend/__snapshots__/scenes-app-batchexports--exports--dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-649 Bytes
(98%)
frontend/__snapshots__/scenes-app-batchexports--exports--light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+5.54 KB
(110%)
...napshots__/scenes-app-insights--funnel-historical-trends-edit--dark--webkit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+5.37 KB
(110%)
...tend/__snapshots__/scenes-app-insights--funnel-historical-trends-edit--dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+5.46 KB
(110%)
...apshots__/scenes-app-insights--funnel-historical-trends-edit--light--webkit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+5.47 KB
(110%)
...end/__snapshots__/scenes-app-insights--funnel-historical-trends-edit--light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+21.9 KB
(110%)
...ts__/scenes-app-insights--funnel-left-to-right-breakdown-edit--dark--webkit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+4.56 KB
(100%)
..._snapshots__/scenes-app-insights--funnel-left-to-right-breakdown-edit--dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+21.7 KB
(110%)
...s__/scenes-app-insights--funnel-left-to-right-breakdown-edit--light--webkit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+4.68 KB
(100%)
...snapshots__/scenes-app-insights--funnel-left-to-right-breakdown-edit--light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+5.6 KB
(100%)
.../__snapshots__/scenes-app-insights--funnel-left-to-right-edit--dark--webkit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+5.27 KB
(100%)
frontend/__snapshots__/scenes-app-insights--funnel-left-to-right-edit--dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+5.59 KB
(100%)
...__snapshots__/scenes-app-insights--funnel-left-to-right-edit--light--webkit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+4.99 KB
(100%)
frontend/__snapshots__/scenes-app-insights--funnel-left-to-right-edit--light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+5.59 KB
(100%)
..._snapshots__/scenes-app-insights--funnel-time-to-convert-edit--dark--webkit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+5.37 KB
(100%)
frontend/__snapshots__/scenes-app-insights--funnel-time-to-convert-edit--dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+5.57 KB
(100%)
...snapshots__/scenes-app-insights--funnel-time-to-convert-edit--light--webkit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+5.3 KB
(100%)
frontend/__snapshots__/scenes-app-insights--funnel-time-to-convert-edit--light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+5.7 KB
(100%)
...ts__/scenes-app-insights--funnel-top-to-bottom-breakdown-edit--dark--webkit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+5.36 KB
(100%)
..._snapshots__/scenes-app-insights--funnel-top-to-bottom-breakdown-edit--dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+5.43 KB
(100%)
...s__/scenes-app-insights--funnel-top-to-bottom-breakdown-edit--light--webkit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+5.3 KB
(100%)
...snapshots__/scenes-app-insights--funnel-top-to-bottom-breakdown-edit--light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+5.47 KB
(100%)
.../__snapshots__/scenes-app-insights--funnel-top-to-bottom-edit--dark--webkit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+5.38 KB
(100%)
frontend/__snapshots__/scenes-app-insights--funnel-top-to-bottom-edit--dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+5.96 KB
(100%)
...__snapshots__/scenes-app-insights--funnel-top-to-bottom-edit--light--webkit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+5.8 KB
(100%)
frontend/__snapshots__/scenes-app-insights--funnel-top-to-bottom-edit--light.png
Oops, something went wrong.
Binary file modified
BIN
+7.32 KB
(110%)
frontend/__snapshots__/scenes-app-insights--lifecycle-edit--dark--webkit.png
Oops, something went wrong.
Binary file modified
BIN
+6.48 KB
(110%)
frontend/__snapshots__/scenes-app-insights--lifecycle-edit--dark.png
Oops, something went wrong.
Binary file modified
BIN
+7.42 KB
(110%)
frontend/__snapshots__/scenes-app-insights--lifecycle-edit--light--webkit.png
Oops, something went wrong.
Binary file modified
BIN
+6.37 KB
(110%)
frontend/__snapshots__/scenes-app-insights--lifecycle-edit--light.png
Oops, something went wrong.
Binary file modified
BIN
+6.89 KB
(110%)
...d/__snapshots__/scenes-app-insights--retention-breakdown-edit--dark--webkit.png
Oops, something went wrong.
Binary file modified
BIN
+6.62 KB
(110%)
frontend/__snapshots__/scenes-app-insights--retention-breakdown-edit--dark.png
Oops, something went wrong.
Binary file modified
BIN
+6.86 KB
(110%)
.../__snapshots__/scenes-app-insights--retention-breakdown-edit--light--webkit.png
Oops, something went wrong.
Binary file modified
BIN
+6.93 KB
(110%)
frontend/__snapshots__/scenes-app-insights--retention-breakdown-edit--light.png
Oops, something went wrong.
Binary file modified
BIN
+5.88 KB
(100%)
frontend/__snapshots__/scenes-app-insights--retention-edit--dark--webkit.png
Oops, something went wrong.
Binary file modified
BIN
+5.8 KB
(100%)
frontend/__snapshots__/scenes-app-insights--retention-edit--dark.png
Oops, something went wrong.
Binary file modified
BIN
+5.99 KB
(100%)
frontend/__snapshots__/scenes-app-insights--retention-edit--light--webkit.png
Oops, something went wrong.
Binary file modified
BIN
+6.01 KB
(100%)
frontend/__snapshots__/scenes-app-insights--retention-edit--light.png
Oops, something went wrong.
Binary file modified
BIN
+6.03 KB
(110%)
frontend/__snapshots__/scenes-app-insights--stickiness-edit--dark--webkit.png
Oops, something went wrong.
Binary file modified
BIN
+6.81 KB
(110%)
frontend/__snapshots__/scenes-app-insights--stickiness-edit--dark.png
Oops, something went wrong.
Binary file modified
BIN
+6.08 KB
(110%)
frontend/__snapshots__/scenes-app-insights--stickiness-edit--light--webkit.png
Oops, something went wrong.
Binary file modified
BIN
+7.03 KB
(110%)
frontend/__snapshots__/scenes-app-insights--stickiness-edit--light.png
Oops, something went wrong.
Binary file modified
BIN
+6.79 KB
(110%)
.../__snapshots__/scenes-app-insights--trends-bar-breakdown-edit--dark--webkit.png
Oops, something went wrong.
Binary file modified
BIN
+5.17 KB
(110%)
frontend/__snapshots__/scenes-app-insights--trends-bar-breakdown-edit--dark.png
Oops, something went wrong.
Binary file modified
BIN
+6.44 KB
(110%)
...__snapshots__/scenes-app-insights--trends-bar-breakdown-edit--light--webkit.png
Oops, something went wrong.
Binary file modified
BIN
+5.05 KB
(110%)
frontend/__snapshots__/scenes-app-insights--trends-bar-breakdown-edit--light.png
Oops, something went wrong.
Binary file modified
BIN
+7.02 KB
(110%)
frontend/__snapshots__/scenes-app-insights--trends-bar-edit--dark--webkit.png
Oops, something went wrong.
Binary file modified
BIN
+5.98 KB
(110%)
frontend/__snapshots__/scenes-app-insights--trends-bar-edit--dark.png
Oops, something went wrong.
Binary file modified
BIN
+6.96 KB
(110%)
frontend/__snapshots__/scenes-app-insights--trends-bar-edit--light--webkit.png
Oops, something went wrong.
Binary file modified
BIN
+5.47 KB
(110%)
frontend/__snapshots__/scenes-app-insights--trends-bar-edit--light.png
Oops, something went wrong.
Binary file modified
BIN
+6.79 KB
(110%)
...__snapshots__/scenes-app-insights--trends-line-breakdown-edit--dark--webkit.png
Oops, something went wrong.
Binary file modified
BIN
+5.17 KB
(110%)
frontend/__snapshots__/scenes-app-insights--trends-line-breakdown-edit--dark.png
Oops, something went wrong.
Binary file modified
BIN
+6.45 KB
(110%)
..._snapshots__/scenes-app-insights--trends-line-breakdown-edit--light--webkit.png
Oops, something went wrong.
Binary file modified
BIN
+5.04 KB
(110%)
frontend/__snapshots__/scenes-app-insights--trends-line-breakdown-edit--light.png
Oops, something went wrong.
Binary file modified
BIN
+6.7 KB
(110%)
.../__snapshots__/scenes-app-insights--trends-pie-breakdown-edit--dark--webkit.png
Oops, something went wrong.
Binary file modified
BIN
+5.63 KB
(110%)
frontend/__snapshots__/scenes-app-insights--trends-pie-breakdown-edit--dark.png
Oops, something went wrong.
Binary file modified
BIN
+6.56 KB
(110%)
...__snapshots__/scenes-app-insights--trends-pie-breakdown-edit--light--webkit.png
Oops, something went wrong.
Binary file modified
BIN
+5.41 KB
(110%)
frontend/__snapshots__/scenes-app-insights--trends-pie-breakdown-edit--light.png
Oops, something went wrong.
Binary file modified
BIN
+6.31 KB
(110%)
frontend/__snapshots__/scenes-app-insights--trends-pie-edit--dark--webkit.png
Oops, something went wrong.
Binary file modified
BIN
+5.5 KB
(110%)
frontend/__snapshots__/scenes-app-insights--trends-pie-edit--dark.png
Oops, something went wrong.
Binary file modified
BIN
+5.95 KB
(110%)
frontend/__snapshots__/scenes-app-insights--trends-pie-edit--light--webkit.png
Oops, something went wrong.
Binary file modified
BIN
+5.36 KB
(110%)
frontend/__snapshots__/scenes-app-insights--trends-pie-edit--light.png
Oops, something went wrong.
Binary file modified
BIN
+6.34 KB
(110%)
..._snapshots__/scenes-app-insights--trends-table-breakdown-edit--dark--webkit.png
Oops, something went wrong.
Binary file modified
BIN
+5.92 KB
(110%)
frontend/__snapshots__/scenes-app-insights--trends-table-breakdown-edit--dark.png
Oops, something went wrong.
Binary file modified
BIN
+6.33 KB
(110%)
...snapshots__/scenes-app-insights--trends-table-breakdown-edit--light--webkit.png
Oops, something went wrong.
Binary file modified
BIN
+5.88 KB
(110%)
frontend/__snapshots__/scenes-app-insights--trends-table-breakdown-edit--light.png
Oops, something went wrong.
Binary file modified
BIN
+12.8 KB
(120%)
frontend/__snapshots__/scenes-app-insights--trends-table-edit--dark--webkit.png
Oops, something went wrong.
Binary file modified
BIN
+8.75 KB
(110%)
frontend/__snapshots__/scenes-app-insights--trends-table-edit--dark.png
Oops, something went wrong.
Binary file modified
BIN
+12.4 KB
(120%)
frontend/__snapshots__/scenes-app-insights--trends-table-edit--light--webkit.png
Oops, something went wrong.
Binary file modified
BIN
+7.86 KB
(110%)
frontend/__snapshots__/scenes-app-insights--trends-table-edit--light.png
Oops, something went wrong.
Binary file modified
BIN
+6.92 KB
(110%)
..._snapshots__/scenes-app-insights--trends-value-breakdown-edit--dark--webkit.png
Oops, something went wrong.
Binary file modified
BIN
+5.81 KB
(110%)
frontend/__snapshots__/scenes-app-insights--trends-value-breakdown-edit--dark.png
Oops, something went wrong.
Binary file modified
BIN
+6.83 KB
(110%)
...snapshots__/scenes-app-insights--trends-value-breakdown-edit--light--webkit.png
Oops, something went wrong.
Binary file modified
BIN
+5.51 KB
(110%)
frontend/__snapshots__/scenes-app-insights--trends-value-breakdown-edit--light.png
Oops, something went wrong.
Binary file modified
BIN
+6.58 KB
(110%)
frontend/__snapshots__/scenes-app-insights--trends-value-edit--dark--webkit.png
Oops, something went wrong.
Binary file modified
BIN
+5.41 KB
(110%)
frontend/__snapshots__/scenes-app-insights--trends-value-edit--dark.png
Oops, something went wrong.
Binary file modified
BIN
+6.19 KB
(110%)
frontend/__snapshots__/scenes-app-insights--trends-value-edit--light--webkit.png
Oops, something went wrong.
Binary file modified
BIN
+4.99 KB
(110%)
frontend/__snapshots__/scenes-app-insights--trends-value-edit--light.png
Oops, something went wrong.
Binary file modified
BIN
+4.61 KB
(100%)
...tend/__snapshots__/scenes-app-insights--trends-world-map-edit--dark--webkit.png
Oops, something went wrong.
Binary file modified
BIN
+5.38 KB
(100%)
frontend/__snapshots__/scenes-app-insights--trends-world-map-edit--dark.png
Oops, something went wrong.
Binary file modified
BIN
+4.71 KB
(100%)
...end/__snapshots__/scenes-app-insights--trends-world-map-edit--light--webkit.png
Oops, something went wrong.
Binary file modified
BIN
+4.93 KB
(100%)
frontend/__snapshots__/scenes-app-insights--trends-world-map-edit--light.png
Oops, something went wrong.
Binary file modified
BIN
+5.46 KB
(100%)
frontend/__snapshots__/scenes-app-insights--user-paths-edit--dark--webkit.png
Oops, something went wrong.
Binary file modified
BIN
+5.72 KB
(100%)
frontend/__snapshots__/scenes-app-insights--user-paths-edit--dark.png
Oops, something went wrong.
Binary file modified
BIN
+5.53 KB
(100%)
frontend/__snapshots__/scenes-app-insights--user-paths-edit--light--webkit.png
Oops, something went wrong.
Binary file modified
BIN
+6.06 KB
(100%)
frontend/__snapshots__/scenes-app-insights--user-paths-edit--light.png
Oops, something went wrong.
135 changes: 135 additions & 0 deletions
135
frontend/src/queries/nodes/InsightQuery/utils/cleanProperties.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
import { cleanEntityProperties, cleanGlobalProperties } from './cleanProperties' | ||
|
||
describe('cleanGlobalProperties', () => { | ||
it('handles empty properties', () => { | ||
const properties = {} | ||
|
||
const result = cleanGlobalProperties(properties) | ||
|
||
expect(result).toEqual(undefined) | ||
}) | ||
|
||
it('handles old style properties', () => { | ||
const properties = { utm_medium__icontains: 'email' } | ||
|
||
const result = cleanGlobalProperties(properties) | ||
|
||
expect(result).toEqual({ | ||
type: 'AND', | ||
values: [ | ||
{ | ||
type: 'AND', | ||
values: [ | ||
{ | ||
key: 'utm_medium', | ||
operator: 'icontains', | ||
type: 'event', | ||
value: 'email', | ||
}, | ||
], | ||
}, | ||
], | ||
}) | ||
}) | ||
|
||
it('handles property filter lists', () => { | ||
const properties = [{ key: 'id', type: 'cohort', value: 636, operator: null }] | ||
|
||
const result = cleanGlobalProperties(properties) | ||
|
||
expect(result).toEqual({ | ||
type: 'AND', | ||
values: [{ type: 'AND', values: [{ key: 'id', type: 'cohort', value: 636 }] }], | ||
}) | ||
}) | ||
|
||
it('handles property group filters', () => { | ||
const properties = { | ||
type: 'AND', | ||
values: [{ type: 'AND', values: [{ key: 'id', type: 'cohort', value: 850, operator: null }] }], | ||
} | ||
|
||
const result = cleanGlobalProperties(properties) | ||
|
||
expect(result).toEqual(properties) | ||
}) | ||
|
||
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({ | ||
type: 'AND', | ||
values: [ | ||
{ | ||
type: 'AND', | ||
values: [{ key: 'id', type: 'cohort', value: 850 }], | ||
}, | ||
], | ||
}) | ||
}) | ||
}) | ||
|
||
describe('cleanEntityProperties', () => { | ||
it('handles empty properties', () => { | ||
const properties = {} | ||
|
||
const result = cleanEntityProperties(properties) | ||
|
||
expect(result).toEqual(undefined) | ||
}) | ||
|
||
it('handles old style properties', () => { | ||
const properties = { utm_medium__icontains: 'email' } | ||
|
||
const result = cleanEntityProperties(properties) | ||
|
||
expect(result).toEqual([ | ||
{ | ||
key: 'utm_medium', | ||
operator: 'icontains', | ||
type: 'event', | ||
value: 'email', | ||
}, | ||
]) | ||
}) | ||
|
||
it('handles property filter lists', () => { | ||
const properties = [ | ||
{ key: '$current_url', type: 'event', value: 'https://hedgebox.net/signup/', operator: 'exact' }, | ||
] | ||
|
||
const result = cleanEntityProperties(properties) | ||
|
||
expect(result).toEqual(properties) | ||
}) | ||
|
||
it('handles property group values', () => { | ||
const properties = { | ||
type: 'AND', | ||
values: [ | ||
{ | ||
key: '$current_url', | ||
operator: 'exact', | ||
type: 'event', | ||
value: 'https://hedgebox.net/signup/', | ||
}, | ||
], | ||
} | ||
|
||
const result = cleanEntityProperties(properties) | ||
|
||
expect(result).toEqual([ | ||
{ | ||
key: '$current_url', | ||
operator: 'exact', | ||
type: 'event', | ||
value: 'https://hedgebox.net/signup/', | ||
}, | ||
]) | ||
}) | ||
}) |
180 changes: 180 additions & 0 deletions
180
frontend/src/queries/nodes/InsightQuery/utils/cleanProperties.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,180 @@ | ||
import { | ||
AnyPropertyFilter, | ||
EventPropertyFilter, | ||
PropertyFilterType, | ||
PropertyGroupFilter, | ||
PropertyGroupFilterValue, | ||
PropertyOperator, | ||
} from '~/types' | ||
|
||
/** Cleans properties of insights. These are either a simple list of property filters or a property group filter. The property group filter has | ||
* a type (AND, OR) and a list of values that are property group filter values, which are either property group filter values or a simple list of | ||
* property filters. | ||
*/ | ||
export const cleanGlobalProperties = ( | ||
properties: Record<string, any> | Record<string, any>[] | undefined | ||
): AnyPropertyFilter[] | PropertyGroupFilter | undefined => { | ||
if ( | ||
properties == undefined || | ||
(Array.isArray(properties) && properties.length == 0) || | ||
Object.keys(properties).length == 0 | ||
) { | ||
// empty properties | ||
return undefined | ||
} else if (isOldStyleProperties(properties)) { | ||
// old style properties | ||
properties = transformOldStyleProperties(properties) | ||
properties = { | ||
type: 'AND', | ||
values: [{ type: 'AND', values: properties }], | ||
} | ||
return cleanPropertyGroupFilter(properties) | ||
} else if (Array.isArray(properties)) { | ||
// list of property filters | ||
properties = { | ||
type: 'AND', | ||
values: [{ type: 'AND', values: properties }], | ||
} | ||
return cleanPropertyGroupFilter(properties) | ||
} else if ( | ||
(properties['type'] === 'AND' || properties['type'] === 'OR') && | ||
!properties['values'].some((property: any) => property['type'] === 'AND' || property['type'] === 'OR') | ||
) { | ||
// property group filter value | ||
properties = { | ||
type: 'AND', | ||
values: [properties], | ||
} | ||
return cleanPropertyGroupFilter(properties) | ||
} else { | ||
// property group filter | ||
return cleanPropertyGroupFilter(properties) | ||
} | ||
} | ||
|
||
/** Cleans properties of entities i.e. event and action nodes. These are a simple list of property filters. */ | ||
export const cleanEntityProperties = ( | ||
properties: Record<string, any> | Record<string, any>[] | undefined | ||
): AnyPropertyFilter[] | undefined => { | ||
if ( | ||
properties == undefined || | ||
(Array.isArray(properties) && properties.length == 0) || | ||
Object.keys(properties).length == 0 | ||
) { | ||
// empty properties | ||
return undefined | ||
} else if (isOldStyleProperties(properties)) { | ||
// old style properties | ||
return transformOldStyleProperties(properties) | ||
} else if (Array.isArray(properties)) { | ||
// list of property filters | ||
return properties.map(cleanProperty) | ||
} else if ( | ||
(properties['type'] === 'AND' || properties['type'] === 'OR') && | ||
!properties['values'].some((property: any) => property['type'] === 'AND' || property['type'] === 'OR') | ||
) { | ||
// property group filter value | ||
return properties.values.map(cleanProperty) | ||
} else { | ||
throw new Error('Unexpected format of entity properties.') | ||
} | ||
} | ||
|
||
const cleanPropertyGroupFilter = (properties: Record<string, any>): PropertyGroupFilter => { | ||
properties['values'] = cleanPropertyGroupFilterValues(properties.values) | ||
return properties as PropertyGroupFilter | ||
} | ||
|
||
const cleanPropertyGroupFilterValues = ( | ||
properties: (AnyPropertyFilter | PropertyGroupFilterValue)[] | ||
): (AnyPropertyFilter | PropertyGroupFilterValue)[] => { | ||
return properties.map(cleanPropertyGroupFilterValue) | ||
} | ||
|
||
const cleanPropertyGroupFilterValue = ( | ||
property: AnyPropertyFilter | PropertyGroupFilterValue | ||
): AnyPropertyFilter | PropertyGroupFilterValue => { | ||
if (property['type'] == 'AND' || property['type'] == 'OR') { | ||
// property group filter value | ||
property['values'] = cleanPropertyGroupFilterValues(property['values'] as PropertyGroupFilterValue[]) | ||
return property | ||
} else { | ||
// property filter | ||
return cleanProperty(property) | ||
} | ||
} | ||
|
||
const cleanProperty = (property: Record<string, any>): AnyPropertyFilter => { | ||
// fix type typo | ||
if (property['type'] === 'events') { | ||
property['type'] = 'event' | ||
} | ||
|
||
// fix value key typo | ||
if (property['values'] !== undefined && property['value'] === undefined) { | ||
property['value'] = property['values'] | ||
delete property['values'] | ||
} | ||
|
||
// convert precalculated and static cohorts to cohorts | ||
if (['precalculated-cohort', 'static-cohort'].includes(property['type'])) { | ||
property['type'] = 'cohort' | ||
} | ||
|
||
// fix invalid property key for cohorts | ||
if (property['type'] === 'cohort' && property['key'] !== 'id') { | ||
property['key'] = 'id' | ||
} | ||
|
||
// set a default operator for properties that support it, but don't have an operator set | ||
if (isPropertyWithOperator(property) && property['operator'] === undefined) { | ||
property['operator'] = 'exact' | ||
} | ||
|
||
// remove the operator for properties that don't support it, but have it set | ||
if (!isPropertyWithOperator(property) && property['operator'] !== undefined) { | ||
delete property['operator'] | ||
} | ||
|
||
// remove none from values | ||
if (Array.isArray(property['value'])) { | ||
property['value'] = property['value'].filter((x) => x !== null) | ||
} | ||
|
||
// remove keys without concrete value | ||
Object.keys(property).forEach((key) => { | ||
if (property[key] === undefined) { | ||
delete property[key] | ||
} | ||
}) | ||
|
||
return property | ||
} | ||
|
||
const isPropertyWithOperator = (property: Record<string, any>): boolean => { | ||
return !['cohort', 'hogql'].includes(property['type']) | ||
} | ||
|
||
// old style dict properties e.g. {"utm_medium__icontains": "email"} | ||
const isOldStyleProperties = (properties: Record<string, any> | Record<string, any>[]): boolean => { | ||
return ( | ||
!Array.isArray(properties) && Object.keys(properties).length === 1 && !['AND', 'OR'].includes(properties.type) | ||
) | ||
} | ||
|
||
const transformOldStyleProperties = ( | ||
properties: Record<string, any> | Record<string, any>[] | ||
): EventPropertyFilter[] => { | ||
const key = Object.keys(properties)[0] | ||
const value = Object.values(properties)[0] | ||
const keySplit = key.split('__') | ||
|
||
return [ | ||
{ | ||
key: keySplit[0], | ||
value: value, | ||
operator: keySplit.length > 1 ? (keySplit[1] as PropertyOperator) : PropertyOperator.Exact, | ||
type: PropertyFilterType.Event, | ||
}, | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.