From dcd2ab1efbd2bc00eb0405031c02e713c1f331d5 Mon Sep 17 00:00:00 2001 From: Marius Andra Date: Fri, 26 Jan 2024 12:05:41 +0100 Subject: [PATCH 1/3] 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 From b04e4b950901acd155a4a4f6d85b1d4db612da24 Mon Sep 17 00:00:00 2001 From: Marius Andra Date: Fri, 26 Jan 2024 12:06:51 +0100 Subject: [PATCH 2/3] to number --- .../src/queries/nodes/InsightQuery/utils/filtersToQueryNode.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/frontend/src/queries/nodes/InsightQuery/utils/filtersToQueryNode.ts b/frontend/src/queries/nodes/InsightQuery/utils/filtersToQueryNode.ts index 20d65dd484055..0102c42fee678 100644 --- a/frontend/src/queries/nodes/InsightQuery/utils/filtersToQueryNode.ts +++ b/frontend/src/queries/nodes/InsightQuery/utils/filtersToQueryNode.ts @@ -115,6 +115,9 @@ export const sanitizeRetentionEntity = (entity: RetentionEntity | undefined): Re delete record[key] } } + if ('id' in record) { + record.id = Number(record.id) + } return record } From ed7d8016551fb8625475f598e208bfb69ee1c7de Mon Sep 17 00:00:00 2001 From: Marius Andra Date: Fri, 26 Jan 2024 12:09:01 +0100 Subject: [PATCH 3/3] only for actions --- .../src/queries/nodes/InsightQuery/utils/filtersToQueryNode.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/queries/nodes/InsightQuery/utils/filtersToQueryNode.ts b/frontend/src/queries/nodes/InsightQuery/utils/filtersToQueryNode.ts index 0102c42fee678..2dc816383a2ca 100644 --- a/frontend/src/queries/nodes/InsightQuery/utils/filtersToQueryNode.ts +++ b/frontend/src/queries/nodes/InsightQuery/utils/filtersToQueryNode.ts @@ -115,7 +115,7 @@ export const sanitizeRetentionEntity = (entity: RetentionEntity | undefined): Re delete record[key] } } - if ('id' in record) { + if ('id' in record && record.type === 'actions') { record.id = Number(record.id) } return record