Skip to content

Commit

Permalink
refactor(insights): use query based insight for setting metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
thmsobrmlr committed Jul 26, 2024
1 parent af9a03e commit b9aef14
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions frontend/src/scenes/insights/insightLogic.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { captureException } from '@sentry/react'
import { actions, connect, events, kea, key, listeners, path, props, reducers, selectors } from 'kea'
import { loaders } from 'kea-loaders'
import { router } from 'kea-router'
Expand Down Expand Up @@ -100,7 +99,11 @@ export const insightLogic = kea<insightLogicType>([
insightUpdate,
callback,
}),
setInsightMetadata: (metadata: Partial<InsightModel>) => ({ metadata }),
setInsightMetadata: (
metadata: Partial<Pick<QueryBasedInsightModel, 'name' | 'description' | 'tags' | 'favorited'>>
) => ({
metadata,
}),
highlightSeries: (seriesIndex: number | null) => ({ seriesIndex }),
}),
loaders(({ actions, values, props }) => ({
Expand Down Expand Up @@ -152,17 +155,12 @@ export const insightLogic = kea<insightLogicType>([
return { ...values.legacyInsight, ...metadata }
}

if (metadata.filters || metadata.query) {
const error = new Error(`Will not override filters or query in setInsightMetadata`)
captureException(error)
throw error
}

const beforeUpdates = {}
for (const key of Object.keys(metadata)) {
beforeUpdates[key] = values.savedInsight[key]
}

// TODO: insightsApi.update
const response = await api.update(
`api/projects/${teamLogic.values.currentTeamId}/insights/${values.legacyInsight.id}`,
metadata
Expand Down

0 comments on commit b9aef14

Please sign in to comment.