From 2027c9dae34837f7fb11d4f1710d996f22c8c914 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Obermu=CC=88ller?= Date: Wed, 3 Jul 2024 22:45:09 +0200 Subject: [PATCH] use getInsightFilterOrQueryForPersistance in save actions --- frontend/src/scenes/insights/insightLogic.ts | 27 +++++++------------- 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/frontend/src/scenes/insights/insightLogic.ts b/frontend/src/scenes/insights/insightLogic.ts index bebc668710033..5856aa920c84a 100644 --- a/frontend/src/scenes/insights/insightLogic.ts +++ b/frontend/src/scenes/insights/insightLogic.ts @@ -22,10 +22,9 @@ import { dashboardsModel } from '~/models/dashboardsModel' import { groupsModel } from '~/models/groupsModel' import { insightsModel } from '~/models/insightsModel' import { tagsModel } from '~/models/tagsModel' -import { queryNodeToFilter } from '~/queries/nodes/InsightQuery/utils/queryNodeToFilter' +import { getInsightFilterOrQueryForPersistance } from '~/queries/nodes/InsightQuery/utils/queryNodeToFilter' import { getQueryBasedInsightModel } from '~/queries/nodes/InsightViz/utils' import { InsightVizNode } from '~/queries/schema' -import { isInsightVizNode } from '~/queries/utils' import { FilterType, InsightLogicProps, @@ -378,14 +377,10 @@ export const insightLogic = kea([ const { name, description, favorited, deleted, dashboards, tags } = values.legacyInsight let savedInsight: InsightModel - let filters - let query - - if (!values.queryBasedInsightSaving && isInsightVizNode(values.queryBasedInsight.query)) { - filters = queryNodeToFilter(values.queryBasedInsight.query.source) - } else { - query = values.queryBasedInsight.query - } + const { filters, query } = getInsightFilterOrQueryForPersistance( + values.queryBasedInsight, + values.queryBasedInsightSaving + ) try { // We don't want to send ALL the insight properties back to the API, so only grabbing fields that might have changed @@ -446,14 +441,10 @@ export const insightLogic = kea([ } }, saveAsNamingSuccess: async ({ name }) => { - let filters - let query - if (!values.queryBasedInsightSaving && isInsightVizNode(values.queryBasedInsight.query)) { - filters = queryNodeToFilter(values.queryBasedInsight.query.source) - } else { - query = values.queryBasedInsight.query - } - + const { filters, query } = getInsightFilterOrQueryForPersistance( + values.queryBasedInsight, + values.queryBasedInsightSaving + ) const insight: InsightModel = await api.create(`api/projects/${teamLogic.values.currentTeamId}/insights/`, { name, filters,