From dcd2ab1efbd2bc00eb0405031c02e713c1f331d5 Mon Sep 17 00:00:00 2001 From: Marius Andra Date: Fri, 26 Jan 2024 12:05:41 +0100 Subject: [PATCH] feat(insights): sanitize retention query --- .../InsightQuery/utils/filtersToQueryNode.ts | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/frontend/src/queries/nodes/InsightQuery/utils/filtersToQueryNode.ts b/frontend/src/queries/nodes/InsightQuery/utils/filtersToQueryNode.ts index 065c07c63a15b..20d65dd484055 100644 --- a/frontend/src/queries/nodes/InsightQuery/utils/filtersToQueryNode.ts +++ b/frontend/src/queries/nodes/InsightQuery/utils/filtersToQueryNode.ts @@ -37,6 +37,7 @@ import { PropertyFilterType, PropertyGroupFilterValue, PropertyOperator, + RetentionEntity, } from '~/types' const reverseInsightMap: Record, InsightNodeKind> = { @@ -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) { @@ -307,8 +320,8 @@ export const filtersToQueryNode = (filters: Partial): 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