diff --git a/frontend/src/lib/utils.tsx b/frontend/src/lib/utils.tsx index cd8fc4265121b..5d39be45d6fea 100644 --- a/frontend/src/lib/utils.tsx +++ b/frontend/src/lib/utils.tsx @@ -432,31 +432,36 @@ export function objectClean> }) return response } -export function objectCleanWithEmpty>(obj: T): T { +export function objectCleanWithEmpty>( + obj: T, + ignoredKeys: string[] = [] +): T { const response = { ...obj } - Object.keys(response).forEach((key) => { - // remove undefined values - if (response[key] === undefined) { - delete response[key] - } - // remove empty arrays i.e. [] - if ( - typeof response[key] === 'object' && - Array.isArray(response[key]) && - (response[key] as unknown[]).length === 0 - ) { - delete response[key] - } - // remove empty objects i.e. {} - if ( - typeof response[key] === 'object' && - !Array.isArray(response[key]) && - response[key] !== null && - Object.keys(response[key] as Record).length === 0 - ) { - delete response[key] - } - }) + Object.keys(response) + .filter((key) => !ignoredKeys.includes(key)) + .forEach((key) => { + // remove undefined values + if (response[key] === undefined) { + delete response[key] + } + // remove empty arrays i.e. [] + if ( + typeof response[key] === 'object' && + Array.isArray(response[key]) && + (response[key] as unknown[]).length === 0 + ) { + delete response[key] + } + // remove empty objects i.e. {} + if ( + typeof response[key] === 'object' && + !Array.isArray(response[key]) && + response[key] !== null && + Object.keys(response[key] as Record).length === 0 + ) { + delete response[key] + } + }) return response } diff --git a/frontend/src/queries/nodes/InsightQuery/utils/filtersToQueryNode.test.ts b/frontend/src/queries/nodes/InsightQuery/utils/filtersToQueryNode.test.ts index 0cae5601db412..30af701ae91a1 100644 --- a/frontend/src/queries/nodes/InsightQuery/utils/filtersToQueryNode.test.ts +++ b/frontend/src/queries/nodes/InsightQuery/utils/filtersToQueryNode.test.ts @@ -281,9 +281,10 @@ describe('filtersToQueryNode', () => { const result = filtersToQueryNode(filters) - const query: Partial = { + const query: TrendsQuery = { kind: NodeKind.TrendsQuery, interval: 'day', + series: [], } expect(result).toEqual(query) }) @@ -308,7 +309,7 @@ describe('filtersToQueryNode', () => { const result = filtersToQueryNode(filters) - const query: Partial = { + const query: TrendsQuery = { kind: NodeKind.TrendsQuery, trendsFilter: { smoothing_intervals: 1, @@ -324,6 +325,7 @@ describe('filtersToQueryNode', () => { breakdown: { breakdown_histogram_bin_count: 1, }, + series: [], } expect(result).toEqual(query) }) @@ -362,7 +364,7 @@ describe('filtersToQueryNode', () => { const result = filtersToQueryNode(filters) - const query: Partial = { + const query: FunnelsQuery = { kind: NodeKind.FunnelsQuery, funnelsFilter: { funnel_viz_type: FunnelVizType.Steps, @@ -384,6 +386,7 @@ describe('filtersToQueryNode', () => { layout: FunnelLayout.horizontal, hidden_legend_breakdowns: ['Chrome', 'Safari'], }, + series: [], } expect(result).toEqual(query) }) @@ -403,7 +406,7 @@ describe('filtersToQueryNode', () => { const result = filtersToQueryNode(filters) - const query: Partial = { + const query: RetentionQuery = { kind: NodeKind.RetentionQuery, retentionFilter: { retention_type: 'retention_first_time', @@ -443,7 +446,7 @@ describe('filtersToQueryNode', () => { const result = filtersToQueryNode(filters) - const query: Partial = { + const query: PathsQuery = { kind: NodeKind.PathsQuery, pathsFilter: { path_type: PathType.Screen, @@ -479,7 +482,7 @@ describe('filtersToQueryNode', () => { const result = filtersToQueryNode(filters) - const query: Partial = { + const query: StickinessQuery = { kind: NodeKind.StickinessQuery, stickinessFilter: { compare: true, @@ -487,6 +490,7 @@ describe('filtersToQueryNode', () => { hidden_legend_indexes: [0, 10], display: ChartDisplayType.ActionsLineGraph, }, + series: [], } expect(result).toEqual(query) }) @@ -502,11 +506,12 @@ describe('filtersToQueryNode', () => { const result = filtersToQueryNode(filters) - const query: Partial = { + const query: LifecycleQuery = { kind: NodeKind.LifecycleQuery, lifecycleFilter: { toggledLifecycles: ['new', 'dormant'], }, + series: [], } expect(result).toEqual(query) }) diff --git a/frontend/src/queries/nodes/InsightQuery/utils/filtersToQueryNode.ts b/frontend/src/queries/nodes/InsightQuery/utils/filtersToQueryNode.ts index f0462618aae0e..93f5339cc929b 100644 --- a/frontend/src/queries/nodes/InsightQuery/utils/filtersToQueryNode.ts +++ b/frontend/src/queries/nodes/InsightQuery/utils/filtersToQueryNode.ts @@ -257,5 +257,5 @@ export const filtersToQueryNode = (filters: Partial): InsightQueryNo } // remove undefined and empty array/objects and return - return objectCleanWithEmpty(query as Record) as InsightQueryNode + return objectCleanWithEmpty(query as Record, ['series']) as InsightQueryNode }