Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

chore(insights): stop converting legacy filters in the browser (#99785)

Thomas Obermüller4bdcb38c4809
diff --git a/frontend/src/exporter/ExportedInsight/ExportedInsight.tsx b/frontend/src/exporter/ExportedInsight/ExportedInsight.tsx
index d5972e4bf28c..af1676dc0857 100644
--- a/frontend/src/exporter/ExportedInsight/ExportedInsight.tsx
+++ b/frontend/src/exporter/ExportedInsight/ExportedInsight.tsx
@@ -34,7 +34,7 @@ export function ExportedInsight({
}): JSX.Element {
useMountedLogic(dataThemeLogic({ themes }))
- const insight = getQueryBasedInsightModel(legacyInsight, 'exported_insight')
+ const insight = getQueryBasedInsightModel(legacyInsight)
// getQueryBasedInsightModel returns the caller's query object by reference — clone it so the
// export-only tweaks below (legend settings, table editing controls) can't leak into a shared model.
insight.query = insight.query ? structuredClone(insight.query) : insight.query
diff --git a/frontend/src/exporter/scenes/ExporterDashboardScene.tsx b/frontend/src/exporter/scenes/ExporterDashboardScene.tsx
index b1e90a83a0d2..ae7a20ae6aa8 100644
--- a/frontend/src/exporter/scenes/ExporterDashboardScene.tsx
+++ b/frontend/src/exporter/scenes/ExporterDashboardScene.tsx
@@ -59,7 +59,7 @@ export default function ExporterDashboardScene({
type: ExportedData['type']
themes: ExportedData['themes']
}): JSX.Element {
- const queryBasedDashboard = useMemo(() => getQueryBasedDashboard(dashboard, 'exported_dashboard')!, [dashboard])
+ const queryBasedDashboard = useMemo(() => getQueryBasedDashboard(dashboard)!, [dashboard])
return (
<>
{type !== ExportType.Image && (
diff --git a/frontend/src/lib/components/AnnotationsOverlay/annotationsOverlayLogic.test.ts b/frontend/src/lib/components/AnnotationsOverlay/annotationsOverlayLogic.test.ts
index 19951e79f0a0..cd6b860c302f 100644
--- a/frontend/src/lib/components/AnnotationsOverlay/annotationsOverlayLogic.test.ts
+++ b/frontend/src/lib/components/AnnotationsOverlay/annotationsOverlayLogic.test.ts
@@ -6,6 +6,7 @@ import { insightLogic } from 'scenes/insights/insightLogic'
import { useMocks } from '~/mocks/jest'
import { annotationsModel, deserializeAnnotation } from '~/models/annotationsModel'
+import { NodeKind } from '~/queries/schema/schema-general'
import { initKeaTests } from '~/test/init'
import { AnnotationScope, AnnotationType, InsightShortId, IntervalType, RawAnnotationType } from '~/types'
@@ -178,7 +179,10 @@ function useInsightMocks(interval: string = 'day', timezone: string = 'UTC'): vo
result: {},
id: MOCK_INSIGHT_NUMERIC_ID,
short_id: MOCK_INSIGHT_SHORT_ID,
- filters: { insight: 'TRENDS', interval },
+ query: {
+ kind: NodeKind.InsightVizNode,
+ source: { kind: NodeKind.TrendsQuery, series: [], interval },
+ },
timezone,
}
useMocks({
diff --git a/frontend/src/models/dashboardsModel.tsx b/frontend/src/models/dashboardsModel.tsx
index 33ad735569dd..74bc7d7a48d4 100644
--- a/frontend/src/models/dashboardsModel.tsx
+++ b/frontend/src/models/dashboardsModel.tsx
@@ -430,9 +430,7 @@ export const dashboardsModel = kea<dashboardsModelType>([
count: 1,
next: null,
previous: null,
- results: [
- getQueryBasedDashboard(exportedDashboard, 'dashboards_model') as DashboardBasicType,
- ],
+ results: [getQueryBasedDashboard(exportedDashboard) as DashboardBasicType],
}
}
@@ -453,9 +451,7 @@ export const dashboardsModel = kea<dashboardsModelType>([
return {
...dashboards,
- results: dashboards.results?.map(
- (dashboard) => getQueryBasedDashboard(dashboard, 'dashboards_model')!
- ),
+ results: dashboards.results?.map((dashboard) => getQueryBasedDashboard(dashboard)!),
}
},
},
@@ -498,7 +494,7 @@ export const dashboardsModel = kea<dashboardsModelType>([
`api/environments/${teamLogic.values.currentTeamId}/dashboards/${id}`,
beforeChange
)
- actions.updateDashboardSuccess(getQueryBasedDashboard(reverted, 'dashboards_model'))
+ actions.updateDashboardSuccess(getQueryBasedDashboard(reverted))
lemonToast.success('Dashboard change reverted')
},
},
@@ -509,7 +505,7 @@ export const dashboardsModel = kea<dashboardsModelType>([
return null
}
- const mappedDashboard = getQueryBasedDashboard(response, 'dashboards_model')
+ const mappedDashboard = getQueryBasedDashboard(response)
if (!mappedDashboard) {
return mappedDashboard
}
@@ -521,8 +517,7 @@ export const dashboardsModel = kea<dashboardsModelType>([
await api.update(`api/environments/${teamLogic.values.currentTeamId}/dashboards/${id}`, {
deleted: true,
delete_insights: deleteInsights,
- }),
- 'dashboards_model'
+ })
) as DashboardType<QueryBasedInsightModel>
deleteFromTree('dashboard', String(id))
return deleted
@@ -531,8 +526,7 @@ export const dashboardsModel = kea<dashboardsModelType>([
const restored = getQueryBasedDashboard(
await api.update(`api/environments/${teamLogic.values.currentTeamId}/dashboards/${id}`, {
deleted: false,
- }),
- 'dashboards_model'
+ })
) as DashboardType<QueryBasedInsightModel>
refreshTreeItem('dashboard', String(id))
return restored
@@ -545,7 +539,7 @@ export const dashboardsModel = kea<dashboardsModelType>([
}
)
eventUsageLogic.actions.reportDashboardPinToggled(id, true, source)
- return getQueryBasedDashboard(response, 'dashboards_model')!
+ return getQueryBasedDashboard(response)!
},
unpinDashboard: async ({ id, source }) => {
const response = await api.update<DashboardType>(
@@ -555,7 +549,7 @@ export const dashboardsModel = kea<dashboardsModelType>([
}
)
eventUsageLogic.actions.reportDashboardPinToggled(id, false, source)
- return getQueryBasedDashboard(response, 'dashboards_model')!
+ return getQueryBasedDashboard(response)!
},
duplicateDashboard: async ({ id, name, show, duplicateTiles }) => {
const result = await api.create<DashboardType>(
@@ -569,7 +563,7 @@ export const dashboardsModel = kea<dashboardsModelType>([
if (show) {
router.actions.push(urls.dashboard(result.id))
}
- return getQueryBasedDashboard(result, 'dashboards_model')!
+ return getQueryBasedDashboard(result)!
},
},
})),
diff --git a/frontend/src/queries/nodes/InsightViz/utils.test.ts b/frontend/src/queries/nodes/InsightViz/utils.test.ts
index 9de3b4b88b57..5512431a20c5 100644
--- a/frontend/src/queries/nodes/InsightViz/utils.test.ts
+++ b/frontend/src/queries/nodes/InsightViz/utils.test.ts
@@ -1,4 +1,3 @@
-import { NodeKind } from '~/queries/schema/schema-general'
import { InsightModel, InsightType } from '~/types'
import { extractValidationErrorCode, getQueryBasedInsightModel } from './utils'
@@ -57,21 +56,14 @@ describe('getQueryBasedInsightModel', () => {
expect(result.dashboards).toEqual(expected)
})
- it.each([
- ['converts stored filters when the insight has no query', InsightType.TRENDS],
- ['reads a filter object with no insight type as trends', undefined],
- ])('%s', (_name, insightType) => {
- // Insights written before queries are served as `filters` with a null `query`, and this
- // conversion is the only thing that renders them. A stored object can omit the type, which
- // the server's converter also reads as trends.
+ it('drops stored filters rather than converting them', () => {
+ // A blank insight is the accepted outcome here, not a fault: saving one writes a query.
const result = getQueryBasedInsightModel({
query: null,
- filters: { insight: insightType, events: [{ id: '$pageview' }] },
+ filters: { insight: InsightType.TRENDS, events: [{ id: '$pageview' }] },
} as Partial<InsightModel>)
- expect(result.query).toMatchObject({
- kind: NodeKind.InsightVizNode,
- source: { kind: NodeKind.TrendsQuery },
- })
+ expect(result.query).toBeNull()
+ expect(result).not.toHaveProperty('filters')
})
})
diff --git a/frontend/src/queries/nodes/InsightViz/utils.ts b/frontend/src/queries/nodes/InsightViz/utils.ts
index 0bae6d09690a..b16c40d22462 100644
--- a/frontend/src/queries/nodes/InsightViz/utils.ts
+++ b/frontend/src/queries/nodes/InsightViz/utils.ts
@@ -14,18 +14,9 @@ import {
NodeKind,
} from '~/queries/schema/schema-general'
import { isInsightQueryWithSeries, setLatestVersionsOnQuery } from '~/queries/utils'
-import {
- ActionType,
- DashboardTile,
- DashboardType,
- FilterType,
- InsightModel,
- InsightType,
- QueryBasedInsightModel,
-} from '~/types'
+import { ActionType, DashboardTile, DashboardType, InsightModel, InsightType, QueryBasedInsightModel } from '~/types'
import { ProductAnalyticsInsightNodeKind, getNodeKindToDefaultQuery } from '../InsightQuery/defaults'
-import { filtersToQueryNode } from '../InsightQuery/utils/filtersToQueryNode'
export const getAllEventNames = (query: InsightQueryNode, allActions: ActionType[]): string[] => {
if (!isInsightQueryWithSeries(query)) {
@@ -87,16 +78,8 @@ type ReturnInsightModel<T> = T extends InsightModel
? Partial<QueryBasedInsightModel>
: never
-/** Get an insight with `query` only. Eventual `filters` will be converted.
- *
- * `source` names the surface for the conversion telemetry. Pass one: without it the call is
- * indistinguishable from every other caller, and the event cannot say which surfaces still rely on
- * converting legacy filters in the browser.
- */
-export function getQueryBasedInsightModel<T extends InputInsightModel>(
- insight: T,
- source?: string
-): ReturnInsightModel<T> {
+/** Get an insight with `query` only. */
+export function getQueryBasedInsightModel<T extends InputInsightModel>(insight: T): ReturnInsightModel<T> {
const { filters, ...baseInsight } = insight
// The API is phasing out the deprecated `dashboards` field (already omitted for token
// callers, eventually for all); derive it from `dashboard_tiles` so remaining readers
@@ -106,35 +89,10 @@ export function getQueryBasedInsightModel<T extends InputInsightModel>(
return {
...baseInsight,
...(dashboards ? { dashboards } : {}),
- query: getQueryFromInsightLike(insight, source),
+ query: insight.query ?? null,
} as unknown as ReturnInsightModel<T>
}
-/** Get a `query` from an object that potentially has `filters` instead of a `query`. */
-export function getQueryFromInsightLike(
- insight: {
- query?: Node<Record<string, any>> | null
- filters?: Partial<FilterType>
- },
- source?: string
-): Node<Record<string, any>> | null {
- let query
- if (insight.query) {
- query = insight.query
- } else if (insight.filters && Object.keys(insight.filters).filter((k) => k != 'filter_test_accounts').length > 0) {
- query = {
- kind: NodeKind.InsightVizNode,
- source: filtersToQueryNode(insight.filters, {
- source: source ?? 'insight_viz_get_query_from_insight_like',
- }),
- } as InsightVizNode
- } else {
- query = null
- }
-
- return query
-}
-
export const queryFromKind = (
kind: ProductAnalyticsInsightNodeKind,
filterTestAccountsDefault: boolean
@@ -186,10 +144,9 @@ export const getDefaultQuery = (
throw new Error('encountered unexpected type for view')
}
-/** Get a dashboard where eventual `filters` based tiles are converted to `query` based ones. */
+/** Get a dashboard whose tiles carry `query` only. */
export const getQueryBasedDashboard = (
- dashboard: DashboardType<InsightModel> | DashboardType<QueryBasedInsightModel> | null,
- source?: string
+ dashboard: DashboardType<InsightModel> | DashboardType<QueryBasedInsightModel> | null
): DashboardType<QueryBasedInsightModel> | null => {
if (dashboard == null) {
return null
@@ -201,7 +158,7 @@ export const getQueryBasedDashboard = (
(tile) =>
({
...tile,
- ...(tile.insight != null ? { insight: getQueryBasedInsightModel(tile.insight, source) } : {}),
+ ...(tile.insight != null ? { insight: getQueryBasedInsightModel(tile.insight) } : {}),
}) as DashboardTile<QueryBasedInsightModel>
),
}
diff --git a/frontend/src/scenes/dashboard/__mocks__/dashboard.json b/frontend/src/scenes/dashboard/__mocks__/dashboard.json
index 9c573338f94f..3b70b640d512 100644
--- a/frontend/src/scenes/dashboard/__mocks__/dashboard.json
+++ b/frontend/src/scenes/dashboard/__mocks__/dashboard.json
@@ -42,21 +42,24 @@
"short_id": "FEUllims",
"name": "donut",
"description": null,
- "filters": {
- "events": [
- {
- "id": "$pageview",
- "math": null,
- "name": "$pageview",
- "type": "events",
- "order": 0,
- "properties": [],
- "math_property": null
+ "query": {
+ "kind": "InsightVizNode",
+ "source": {
+ "kind": "TrendsQuery",
+ "series": [
+ {
+ "kind": "EventsNode",
+ "event": "$pageview",
+ "name": "$pageview",
+ "math": "total",
+ "math_property": null
+ }
+ ],
+ "interval": "day",
+ "trendsFilter": {
+ "display": "ActionsPie"
}
- ],
- "display": "ActionsPie",
- "insight": "TRENDS",
- "interval": "day"
+ }
},
"order": null,
"deleted": false,
@@ -176,21 +179,24 @@
"short_id": "ZLyv5MGc",
"name": "pageviews",
"description": null,
- "filters": {
- "events": [
- {
- "id": "$pageview",
- "math": null,
- "name": "$pageview",
- "type": "events",
- "order": 0,
- "properties": [],
- "math_property": null
+ "query": {
+ "kind": "InsightVizNode",
+ "source": {
+ "kind": "TrendsQuery",
+ "series": [
+ {
+ "kind": "EventsNode",
+ "event": "$pageview",
+ "name": "$pageview",
+ "math": "total",
+ "math_property": null
+ }
+ ],
+ "interval": "day",
+ "trendsFilter": {
+ "display": "ActionsLineGraph"
}
- ],
- "display": "ActionsLineGraph",
- "insight": "TRENDS",
- "interval": "day"
+ }
},
"order": null,
"deleted": false,
diff --git a/frontend/src/scenes/dashboard/__mocks__/dashboard1.json b/frontend/src/scenes/dashboard/__mocks__/dashboard1.json
index 6f700db94b67..47a11106dfd6 100644
--- a/frontend/src/scenes/dashboard/__mocks__/dashboard1.json
+++ b/frontend/src/scenes/dashboard/__mocks__/dashboard1.json
@@ -18,13 +18,25 @@
"short_id": "NqD3cS7N",
"name": "Weekly signups",
"derived_name": null,
- "filters": {
- "events": [{ "id": "signed_up", "type": "events", "order": 0 }],
- "actions": [],
- "display": "ActionsLineGraph",
- "insight": "TRENDS",
- "interval": "week",
- "date_from": "-8w"
+ "query": {
+ "kind": "InsightVizNode",
+ "source": {
+ "kind": "TrendsQuery",
+ "dateRange": {
+ "date_from": "-8w"
+ },
+ "series": [
+ {
+ "kind": "EventsNode",
+ "event": "signed_up",
+ "math": "total"
+ }
+ ],
+ "interval": "week",
+ "trendsFilter": {
+ "display": "ActionsLineGraph"
+ }
+ }
},
"filters_hash": "cache_e70019305379d96e7996f34fc0a3fc1f",
"order": null,
@@ -232,14 +244,28 @@
"short_id": "Mwbqlk39",
"name": "Last month's signups by country",
"derived_name": null,
- "filters": {
- "events": [{ "id": "signed_up", "type": "events", "order": 0 }],
- "actions": [],
- "display": "WorldMap",
- "insight": "TRENDS",
- "breakdown": "$geoip_country_code",
- "date_from": "-1m",
- "breakdown_type": "event"
+ "query": {
+ "kind": "InsightVizNode",
+ "source": {
+ "kind": "TrendsQuery",
+ "dateRange": {
+ "date_from": "-1m"
+ },
+ "series": [
+ {
+ "kind": "EventsNode",
+ "event": "signed_up",
+ "math": "total"
+ }
+ ],
+ "breakdownFilter": {
+ "breakdown_type": "event",
+ "breakdown": "$geoip_country_code"
+ },
+ "trendsFilter": {
+ "display": "WorldMap"
+ }
+ }
},
"filters_hash": "cache_ceb3f58b5afdd69bd25c42f87b0359c9",
"order": null,
@@ -804,26 +830,48 @@
"short_id": "H6Vw9ZiY",
"name": "New user retention",
"derived_name": null,
- "filters": {
- "period": "Week",
- "display": "ActionsTable",
- "insight": "RETENTION",
- "properties": {
- "type": "AND",
- "values": [
- {
- "type": "AND",
- "values": [
- { "key": "email", "type": "person", "value": "is_set", "operator": "is_set" }
- ]
- }
- ]
- },
- "target_entity": { "id": "signed_up", "name": "signed_up", "type": "events", "order": 0 },
- "retention_type": "retention_first_time",
- "total_intervals": 9,
- "returning_entity": { "id": 1, "name": "Interacted with file", "type": "actions", "order": 0 },
- "date_from": "-7d"
+ "query": {
+ "kind": "InsightVizNode",
+ "source": {
+ "kind": "RetentionQuery",
+ "properties": {
+ "type": "AND",
+ "values": [
+ {
+ "type": "AND",
+ "values": [
+ {
+ "key": "email",
+ "type": "person",
+ "value": "is_set",
+ "operator": "is_set"
+ }
+ ]
+ }
+ ]
+ },
+ "dateRange": {
+ "date_from": "-7d"
+ },
+ "retentionFilter": {
+ "retentionType": "retention_first_time",
+ "totalIntervals": 9,
+ "returningEntity": {
+ "id": 1,
+ "name": "Interacted with file",
+ "type": "actions",
+ "order": 0
+ },
+ "targetEntity": {
+ "id": "signed_up",
+ "name": "signed_up",
+ "type": "events",
+ "order": 0
+ },
+ "period": "Week",
+ "meanRetentionCalculation": "simple"
+ }
+ }
},
"filters_hash": "cache_6b4441baca5d5db6c136efe0e7e6b82b",
"order": null,
@@ -976,35 +1024,37 @@
"short_id": "XbzObpS2",
"name": "Weekly file volume",
"derived_name": null,
- "filters": {
- "events": [
- {
- "id": "uploaded_file",
- "math": "sum",
- "name": "uploaded_file",
- "type": "events",
- "order": 0,
- "custom_name": "Uploaded bytes",
- "math_property": "file_size_b"
+ "query": {
+ "kind": "InsightVizNode",
+ "source": {
+ "kind": "TrendsQuery",
+ "filterTestAccounts": true,
+ "dateRange": {
+ "date_from": "-8w"
},
- {
- "id": "deleted_file",
- "math": "sum",
- "name": "deleted_file",
- "type": "events",
- "order": 1,
- "custom_name": "Deleted bytes",
- "math_property": "file_size_b"
+ "series": [
+ {
+ "kind": "EventsNode",
+ "event": "uploaded_file",
+ "name": "uploaded_file",
+ "custom_name": "Uploaded bytes",
+ "math": "sum",
+ "math_property": "file_size_b"
+ },
+ {
+ "kind": "EventsNode",
+ "event": "deleted_file",
+ "name": "deleted_file",
+ "custom_name": "Deleted bytes",
+ "math": "sum",
+ "math_property": "file_size_b"
+ }
+ ],
+ "interval": "week",
+ "trendsFilter": {
+ "display": "ActionsLineGraph"
}
- ],
- "actions": [],
- "display": "ActionsLineGraph",
- "insight": "TRENDS",
- "interval": "week",
- "date_from": "-8w",
- "new_entity": [],
- "properties": [],
- "filter_test_accounts": true
+ }
},
"filters_hash": "cache_70ee46d0dc8508016c96227dca04de20",
"order": null,
@@ -1406,30 +1456,38 @@
"short_id": "g5Yz2ij1",
"name": "Activation",
"derived_name": null,
- "filters": {
- "events": [
- {
- "id": "signed_up",
- "name": "signed_up",
- "type": "events",
- "order": 2,
- "custom_name": "Signed up"
+ "query": {
+ "kind": "InsightVizNode",
+ "source": {
+ "kind": "FunnelsQuery",
+ "filterTestAccounts": true,
+ "dateRange": {
+ "date_from": "-1m"
},
- {
- "id": "upgraded_plan",
- "name": "upgraded_plan",
- "type": "events",
- "order": 4,
- "custom_name": "Upgraded plan"
+ "series": [
+ {
+ "kind": "EventsNode",
+ "event": "signed_up",
+ "name": "signed_up",
+ "custom_name": "Signed up"
+ },
+ {
+ "kind": "ActionsNode",
+ "id": 1,
+ "name": "Interacted with file"
+ },
+ {
+ "kind": "EventsNode",
+ "event": "upgraded_plan",
+ "name": "upgraded_plan",
+ "custom_name": "Upgraded plan"
+ }
+ ],
+ "interval": "day",
+ "funnelsFilter": {
+ "funnelVizType": "steps"
}
- ],
- "actions": [{ "id": 1, "name": "Interacted with file", "type": "actions", "order": 3 }],
- "display": "FunnelViz",
- "insight": "FUNNELS",
- "interval": "day",
- "date_from": "-1m",
- "funnel_viz_type": "steps",
- "filter_test_accounts": true
+ }
},
"filters_hash": "cache_f80465780a58a5a48c547fb5b3a5812b",
"order": null,
@@ -1515,20 +1573,23 @@
"short_id": "Qcvds2lB",
"name": "Active user lifecycle",
"derived_name": null,
- "filters": {
- "events": [],
- "actions": [
- { "id": 1, "math": "total", "name": "Interacted with file", "type": "actions", "order": 0 }
- ],
- "compare": false,
- "display": "ActionsLineGraph",
- "insight": "LIFECYCLE",
- "interval": "day",
- "shown_as": "Lifecycle",
- "date_from": "-8w",
- "new_entity": [],
- "properties": [],
- "filter_test_accounts": true
+ "query": {
+ "kind": "InsightVizNode",
+ "source": {
+ "kind": "LifecycleQuery",
+ "filterTestAccounts": true,
+ "dateRange": {
+ "date_from": "-8w"
+ },
+ "series": [
+ {
+ "kind": "ActionsNode",
+ "id": 1,
+ "name": "Interacted with file"
+ }
+ ],
+ "interval": "day"
+ }
},
"filters_hash": "cache_beb8babf8ebf9370338881a5c7945d77",
"order": null,
diff --git a/frontend/src/scenes/dashboard/dashboardLogic.tsx b/frontend/src/scenes/dashboard/dashboardLogic.tsx
index d84ddd950aa8..d32fa7a72761 100644
--- a/frontend/src/scenes/dashboard/dashboardLogic.tsx
+++ b/frontend/src/scenes/dashboard/dashboardLogic.tsx
@@ -237,26 +237,23 @@ function mergeUpdatedWidgetTileIntoDashboard(
dashboard: DashboardType<QueryBasedInsightModel>,
updatedTile: DashboardTile<QueryBasedInsightModel>
): DashboardType<QueryBasedInsightModel> | null {
- return getQueryBasedDashboard(
- {
- ...dashboard,
- tiles: dashboard.tiles.map((existingTile) => {
- if (existingTile.id !== updatedTile.id) {
- return existingTile
- }
+ return getQueryBasedDashboard({
+ ...dashboard,
+ tiles: dashboard.tiles.map((existingTile) => {
+ if (existingTile.id !== updatedTile.id) {
+ return existingTile
+ }
- return {
- ...existingTile,
- ...updatedTile,
- widget:
- existingTile.widget && updatedTile.widget
- ? { ...existingTile.widget, ...updatedTile.widget }
- : (updatedTile.widget ?? existingTile.widget),
- }
- }),
- } as DashboardType<InsightModel>,
- 'dashboard_scene'
- )
+ return {
+ ...existingTile,
+ ...updatedTile,
+ widget:
+ existingTile.widget && updatedTile.widget
+ ? { ...existingTile.widget, ...updatedTile.widget }
+ : (updatedTile.widget ?? existingTile.widget),
+ }
+ }),
+ } as DashboardType<InsightModel>)
}
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
@@ -1594,7 +1591,7 @@ export const dashboardLogic = kea<dashboardLogicType>([
throw new Error('Dashboard response was empty or invalid')
}
- return getQueryBasedDashboard(dashboard, 'dashboard_scene')
+ return getQueryBasedDashboard(dashboard)
} catch (error: any) {
if (error.status === 404) {
return null
@@ -1622,10 +1619,7 @@ export const dashboardLogic = kea<dashboardLogicType>([
if (data.type === 'metadata') {
metadataReceived = true
actions.loadDashboardMetadataSuccess(
- getQueryBasedDashboard(
- data.dashboard as DashboardType<InsightModel>,
- 'dashboard_scene'
- )
+ getQueryBasedDashboard(data.dashboard as DashboardType<InsightModel>)
)
} else if (data.type === 'tile') {
actions.receiveTileFromStream(data)
@@ -1736,7 +1730,7 @@ export const dashboardLogic = kea<dashboardLogicType>([
)
}
cache.dashboardChangesPersisted = true
- return getQueryBasedDashboard(updatedDashboard, 'dashboard_scene')
+ return getQueryBasedDashboard(updatedDashboard)
} catch (e) {
lemonToast.error('Could not update dashboard: ' + String(e))
return values.dashboard
@@ -1799,7 +1793,7 @@ export const dashboardLogic = kea<dashboardLogicType>([
tiles: tilesToUpdate.length > 0 ? tilesToUpdate : undefined,
}
)
- return getQueryBasedDashboard(dashboard, 'dashboard_scene')
+ return getQueryBasedDashboard(dashboard)
} catch (e) {
// Re-throw so duplicateTileFailure fires. Swallowing the error resolved it as a
// success, so the tile refreshed with no copy and the user kept clicking.
@@ -1822,7 +1816,7 @@ export const dashboardLogic = kea<dashboardLogicType>([
to_dashboard: toDashboard,
}
)
- return getQueryBasedDashboard(dashboard, 'dashboard_scene')
+ return getQueryBasedDashboard(dashboard)
},
copyToDashboard: async ({ tile, fromDashboard, toDashboard, toDashboardName }) => {
if (!tile?.insight && !tile?.text && !tile?.button_tile && !tile?.widget) {
@@ -2250,9 +2244,7 @@ export const dashboardLogic = kea<dashboardLogicType>([
const transformedTile = {
...tile,
- ...(tile.insight != null
- ? { insight: getQueryBasedInsightModel(tile.insight, 'dashboard_tile_stream') }
- : {}),
+ ...(tile.insight != null ? { insight: getQueryBasedInsightModel(tile.insight) } : {}),
}
let newTiles = [...state.tiles, transformedTile]
@@ -3951,7 +3943,7 @@ export const dashboardLogic = kea<dashboardLogicType>([
values.dashboard?.customization?.layout_compaction ?? DashboardGridCompaction.Vertical,
}
)
- dashboardsModel.actions.updateDashboardSuccess(getQueryBasedDashboard(dashboard, 'dashboard_scene'))
+ dashboardsModel.actions.updateDashboardSuccess(getQueryBasedDashboard(dashboard))
eventUsageLogic.actions.reportDashboardTileDensityConfigured(tileSpacing)
} catch {
if (!cache.pendingDashboardTileSpacing) {
@@ -3993,7 +3985,7 @@ export const dashboardLogic = kea<dashboardLogicType>([
grid_spacing: values.dashboard?.customization?.tile_spacing ?? 'standard',
}
)
- dashboardsModel.actions.updateDashboardSuccess(getQueryBasedDashboard(dashboard, 'dashboard_scene'))
+ dashboardsModel.actions.updateDashboardSuccess(getQueryBasedDashboard(dashboard))
} catch (error) {
posthog.captureException(error)
if (!cache.pendingDashboardGridCompaction) {
@@ -4373,13 +4365,10 @@ export const dashboardLogic = kea<dashboardLogicType>([
)
const createdTiles = findNewlyAddedWidgetTiles(previousWidgetTileIds, response.tiles)
if (createdTiles.length > 0 && values.dashboard?.id === dashboardId) {
- const dashboard = getQueryBasedDashboard(
- {
- ...values.dashboard,
- tiles: [...values.dashboard.tiles, ...createdTiles],
- } as DashboardType<InsightModel>,
- 'dashboard_scene'
- )
+ const dashboard = getQueryBasedDashboard({
+ ...values.dashboard,
+ tiles: [...values.dashboard.tiles, ...createdTiles],
+ } as DashboardType<InsightModel>)
if (dashboard) {
dashboardsModel.actions.updateDashboardSuccess(dashboard)
diff --git a/frontend/src/scenes/dashboard/dashboardUtils.ts b/frontend/src/scenes/dashboard/dashboardUtils.ts
index e1e61e65d7fa..66b65f7a204c 100644
--- a/frontend/src/scenes/dashboard/dashboardUtils.ts
+++ b/frontend/src/scenes/dashboard/dashboardUtils.ts
@@ -310,8 +310,7 @@ export async function getInsightWithRetry(
})}`
const insightResponse: Response = await api.getResponse(apiUrl, methodOptions)
const legacyInsight: InsightModel | null = await getJSONOrNull(insightResponse)
- const result =
- legacyInsight !== null ? getQueryBasedInsightModel(legacyInsight, 'dashboard_tile_refresh') : null
+ const result = legacyInsight !== null ? getQueryBasedInsightModel(legacyInsight) : null
if (result?.query_status?.error_message === RATE_LIMIT_ERROR_MESSAGE) {
attempt++
@@ -349,10 +348,7 @@ export async function getInsightWithRetry(
)
const legacyInsight: InsightModel | null = await getJSONOrNull(refreshedInsightResponse)
if (legacyInsight) {
- const queryBasedInsight = getQueryBasedInsightModel(
- legacyInsight,
- 'dashboard_tile_refresh_async'
- )
+ const queryBasedInsight = getQueryBasedInsightModel(legacyInsight)
return { ...queryBasedInsight, query_status: finalStatus }
}
}
diff --git a/frontend/src/scenes/dashboard/newDashboardLogic.ts b/frontend/src/scenes/dashboard/newDashboardLogic.ts
index daf21ab9af68..cc9f7506b28f 100644
--- a/frontend/src/scenes/dashboard/newDashboardLogic.ts
+++ b/frontend/src/scenes/dashboard/newDashboardLogic.ts
@@ -362,7 +362,7 @@ export const newDashboardLogic = kea<newDashboardLogicType>([
)
actions.hideNewDashboardModal()
actions.resetNewDashboard()
- const queryBasedDashboard = getQueryBasedDashboard(result, 'new_dashboard')
+ const queryBasedDashboard = getQueryBasedDashboard(result)
queryBasedDashboard && dashboardsModel.actions.addDashboardSuccess(queryBasedDashboard)
actions.submitNewDashboardSuccessWithResult(result)
tryShowMCPHint('dashboards.create', {
@@ -429,7 +429,7 @@ export const newDashboardLogic = kea<newDashboardLogicType>([
)
actions.resetNewDashboard()
- const queryBasedDashboard = getQueryBasedDashboard(result, 'new_dashboard')
+ const queryBasedDashboard = getQueryBasedDashboard(result)
queryBasedDashboard && dashboardsModel.actions.addDashboardSuccess(queryBasedDashboard)
actions.submitNewDashboardSuccessWithResult(result, variables)
diff --git a/frontend/src/scenes/dashboard/tileLayouts.ts b/frontend/src/scenes/dashboard/tileLayouts.ts
index 3969dcc7497a..ac934afc33c3 100644
--- a/frontend/src/scenes/dashboard/tileLayouts.ts
+++ b/frontend/src/scenes/dashboard/tileLayouts.ts
@@ -248,7 +248,7 @@ export const calculateLayouts = (
}
const layouts = (sortedDashboardTiles || []).map((tile) => {
- const query = tile.insight ? getQueryBasedInsightModel(tile.insight, 'dashboard_tile_layout') : null
+ const query = tile.insight ? getQueryBasedInsightModel(tile.insight) : null
// Base constraints
let defaultW = 6
let defaultH = 5
diff --git a/frontend/src/scenes/data-management/events/eventInsightsLogic.ts b/frontend/src/scenes/data-management/events/eventInsightsLogic.ts
index fe193686ec37..0a6e62013177 100644
--- a/frontend/src/scenes/data-management/events/eventInsightsLogic.ts
+++ b/frontend/src/scenes/data-management/events/eventInsightsLogic.ts
@@ -119,9 +119,7 @@ export const eventInsightsLogic = kea<eventInsightsLogicType>([
return {
...response,
filters,
- results: (response?.results ?? []).map((rawInsight: any) =>
- getQueryBasedInsightModel(rawInsight, 'event_insights_list')
- ),
+ results: (response?.results ?? []).map((rawInsight: any) => getQueryBasedInsightModel(rawInsight)),
} as InsightsResult
},
},
diff --git a/frontend/src/scenes/data-management/variables/insightsLoader.ts b/frontend/src/scenes/data-management/variables/insightsLoader.ts
index f7f83db9c752..820997aca1af 100644
--- a/frontend/src/scenes/data-management/variables/insightsLoader.ts
+++ b/frontend/src/scenes/data-management/variables/insightsLoader.ts
@@ -34,9 +34,7 @@ export async function fetchInsightsUsingVariable(
`api/environments/${teamId}/insights/?basic=true&limit=${limit}&offset=${offset}`
)
- const insights = legacyResponse.results.map((legacyInsight) =>
- getQueryBasedInsightModel(legacyInsight, 'variable_insights_list')
- )
+ const insights = legacyResponse.results.map((legacyInsight) => getQueryBasedInsightModel(legacyInsight))
// Filter insights that use this variable
const filtered = insights.filter((insight) => insightUsesVariable(insight, variableId))
diff --git a/frontend/src/scenes/feature-flags/featureFlagLogic.ts b/frontend/src/scenes/feature-flags/featureFlagLogic.ts
index 96e24fdb0127..9941ef1c5120 100644
--- a/frontend/src/scenes/feature-flags/featureFlagLogic.ts
+++ b/frontend/src/scenes/feature-flags/featureFlagLogic.ts
@@ -3252,9 +3252,7 @@ export const featureFlagLogic = kea<featureFlagLogicType>([
const response = await api.get<PaginatedResponse<InsightModel>>(
`api/environments/${values.currentProjectId}/insights/?feature_flag=${values.featureFlag.key}&order=-created_at`
)
- return response.results.map((legacyInsight) =>
- getQueryBasedInsightModel(legacyInsight, 'feature_flag_related_insights')
- )
+ return response.results.map((legacyInsight) => getQueryBasedInsightModel(legacyInsight))
}
return []
},
diff --git a/frontend/src/scenes/insights/EmptyStates/funnelOneStep.json b/frontend/src/scenes/insights/EmptyStates/funnelOneStep.json
index f830646c9641..584138725b08 100644
--- a/frontend/src/scenes/insights/EmptyStates/funnelOneStep.json
+++ b/frontend/src/scenes/insights/EmptyStates/funnelOneStep.json
@@ -3,25 +3,31 @@
"short_id": "bfuAVPN3",
"name": null,
"derived_name": "Pageview user conversion rate",
- "filters": {
- "events": [
- {
- "id": "$pageview",
- "name": "$pageview",
- "type": "events",
- "order": 0
+ "query": {
+ "kind": "InsightVizNode",
+ "source": {
+ "kind": "FunnelsQuery",
+ "properties": {
+ "type": "AND",
+ "values": [
+ {
+ "type": "AND",
+ "values": []
+ }
+ ]
+ },
+ "series": [
+ {
+ "kind": "EventsNode",
+ "event": "$pageview",
+ "name": "$pageview"
+ }
+ ],
+ "interval": "day",
+ "funnelsFilter": {
+ "funnelVizType": "steps"
}
- ],
- "actions": [],
- "display": "FunnelViz",
- "insight": "FUNNELS",
- "interval": "day",
- "exclusions": [],
- "properties": {
- "type": "AND",
- "values": []
- },
- "funnel_viz_type": "steps"
+ }
},
"filters_hash": "cache_862d873ccc37114b631227eb606bb2e2",
"order": null,
diff --git a/frontend/src/scenes/insights/utils/api.ts b/frontend/src/scenes/insights/utils/api.ts
index a4f529fa07a6..97b9b196fa25 100644
--- a/frontend/src/scenes/insights/utils/api.ts
+++ b/frontend/src/scenes/insights/utils/api.ts
@@ -12,7 +12,7 @@ async function _perform(
): Promise<QueryBasedInsightModel> {
const legacyInsight =
method === 'create' ? await api.insights[method](insight) : await api.insights[method](id!, insight, options)
- return getQueryBasedInsightModel(legacyInsight, 'insight_write')
+ return getQueryBasedInsightModel(legacyInsight)
}
export const insightsApi = {
@@ -37,14 +37,14 @@ export const insightsApi = {
return null
}
const legacyInsight = legacyInsights.results[0]
- return getQueryBasedInsightModel(legacyInsight, 'insight_scene_load') as QueryBasedInsightModel
+ return getQueryBasedInsightModel(legacyInsight) as QueryBasedInsightModel
},
async getByNumericId(numericId: number): Promise<QueryBasedInsightModel | null> {
const legacyInsight = await api.insights.get(numericId)
if (legacyInsight === null) {
return null
}
- return getQueryBasedInsightModel(legacyInsight, 'insight_load_by_numeric_id')
+ return getQueryBasedInsightModel(legacyInsight)
},
async create(insight: Partial<QueryBasedInsightModel>): Promise<QueryBasedInsightModel> {
return this._perform('create', insight)
diff --git a/frontend/src/scenes/project-homepage/projectHomepageLogic.tsx b/frontend/src/scenes/project-homepage/projectHomepageLogic.tsx
index d68d266aa408..8a12bb1e18d9 100644
--- a/frontend/src/scenes/project-homepage/projectHomepageLogic.tsx
+++ b/frontend/src/scenes/project-homepage/projectHomepageLogic.tsx
@@ -106,9 +106,7 @@ export const projectHomepageLogic = kea<projectHomepageLogicType>([
const insights = await api.get<InsightModel[]>(
`api/environments/${values.currentProjectId}/insights/my_last_viewed`
)
- return insights.map((legacyInsight) =>
- getQueryBasedInsightModel(legacyInsight, 'project_homepage_recent_insights')
- )
+ return insights.map((legacyInsight) => getQueryBasedInsightModel(legacyInsight))
},
},
],
diff --git a/frontend/src/scenes/saved-insights/addSavedInsightsModalLogic.ts b/frontend/src/scenes/saved-insights/addSavedInsightsModalLogic.ts
index fa527b5803f3..e5e166698aef 100644
--- a/frontend/src/scenes/saved-insights/addSavedInsightsModalLogic.ts
+++ b/frontend/src/scenes/saved-insights/addSavedInsightsModalLogic.ts
@@ -242,9 +242,7 @@ export const addSavedInsightsModalLogic = kea<addSavedInsightsModalLogicType>([
return {
...response,
- results: response.results.map((rawInsight: any) =>
- getQueryBasedInsightModel(rawInsight, 'add_saved_insights_modal')
- ),
+ results: response.results.map((rawInsight: any) => getQueryBasedInsightModel(rawInsight)),
}
},
},
diff --git a/frontend/src/scenes/saved-insights/savedInsightsLogic.ts b/frontend/src/scenes/saved-insights/savedInsightsLogic.ts
index 747ad8112f79..2f3defdcdebe 100644
--- a/frontend/src/scenes/saved-insights/savedInsightsLogic.ts
+++ b/frontend/src/scenes/saved-insights/savedInsightsLogic.ts
@@ -394,9 +394,7 @@ export const savedInsightsLogic = kea<savedInsightsLogicType>([
const response = {
...legacyResponse,
- results: legacyResponse.results.map((legacyInsight) =>
- getQueryBasedInsightModel(legacyInsight, 'saved_insights_list')
- ),
+ results: legacyResponse.results.map((legacyInsight) => getQueryBasedInsightModel(legacyInsight)),
}
if (filters.search && String(filters.search).match(/^[0-9]+$/)) {