Skip to content

Commit

Permalink
feat(insights): sanitize retention query
Browse files Browse the repository at this point in the history
  • Loading branch information
mariusandra committed Jan 26, 2024
1 parent e84c0ce commit dcd2ab1
Showing 1 changed file with 15 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,18 @@ 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]
}
}
return record
}

const cleanProperties = (parentProperties: FilterType['properties']): InsightsQueryBase['properties'] => {
if (!parentProperties || !parentProperties.values) {
Expand Down Expand Up @@ -307,8 +320,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 dcd2ab1

Please sign in to comment.