Skip to content

Commit

Permalink
use getInsightFilterOrQueryForPersistance in save actions
Browse files Browse the repository at this point in the history
  • Loading branch information
thmsobrmlr committed Jul 3, 2024
1 parent b6a7486 commit 2027c9d
Showing 1 changed file with 9 additions and 18 deletions.
27 changes: 9 additions & 18 deletions frontend/src/scenes/insights/insightLogic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -378,14 +377,10 @@ export const insightLogic = kea<insightLogicType>([
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
Expand Down Expand Up @@ -446,14 +441,10 @@ export const insightLogic = kea<insightLogicType>([
}
},
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,
Expand Down

0 comments on commit 2027c9d

Please sign in to comment.