Skip to content

Commit

Permalink
feat(insights): sanitize retention query (#19979)
Browse files Browse the repository at this point in the history
  • Loading branch information
mariusandra authored Jan 26, 2024
1 parent 021f990 commit f447507
Showing 1 changed file with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {
PropertyFilterType,
PropertyGroupFilterValue,
PropertyOperator,
RetentionEntity,
} from '~/types'

const reverseInsightMap: Record<Exclude<InsightType, InsightType.JSON | InsightType.SQL>, InsightNodeKind> = {
Expand Down Expand Up @@ -104,6 +105,21 @@ export const cleanHiddenLegendSeries = (
.map(([k]) => k)
: undefined
}
export const sanitizeRetentionEntity = (entity: RetentionEntity | undefined): RetentionEntity | undefined => {
if (!entity) {
return undefined
}
const record = { ...entity }
for (const key of Object.keys(record)) {
if (!['id', 'kind', 'name', 'type', 'order', 'uuid', 'custom_name'].includes(key)) {
delete record[key]
}
}
if ('id' in record && record.type === 'actions') {
record.id = Number(record.id)
}
return record
}

const cleanProperties = (parentProperties: FilterType['properties']): InsightsQueryBase['properties'] => {
if (!parentProperties || !parentProperties.values) {
Expand Down Expand Up @@ -307,8 +323,8 @@ export const filtersToQueryNode = (filters: Partial<FilterType>): InsightQueryNo
retentionType: filters.retention_type,
retentionReference: filters.retention_reference,
totalIntervals: filters.total_intervals,
returningEntity: filters.returning_entity,
targetEntity: filters.target_entity,
returningEntity: sanitizeRetentionEntity(filters.returning_entity),
targetEntity: sanitizeRetentionEntity(filters.target_entity),
period: filters.period,
})
// TODO: query.aggregation_group_type_index
Expand Down

0 comments on commit f447507

Please sign in to comment.