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.

fix(dashboards): raise preview limit and track filter results (#118066)

Matt Pua5fc0f8740d6c
diff --git a/frontend/src/scenes/dashboard/dashboardLogic.test.ts b/frontend/src/scenes/dashboard/dashboardLogic.test.ts
index 575f02579d19..3f79bd4bbe11 100644
--- a/frontend/src/scenes/dashboard/dashboardLogic.test.ts
+++ b/frontend/src/scenes/dashboard/dashboardLogic.test.ts
@@ -967,8 +967,8 @@ describe('dashboardLogic', () => {
})
it.each([
- [21, true],
- [22, false],
+ [34, true],
+ [35, false],
])('previews filter changes automatically with %i insights: %s', async (insightCount, autoPreview) => {
await expectLogic(logic).toFinishAllListeners()
const dashboard = {
@@ -990,6 +990,7 @@ describe('dashboardLogic', () => {
const refresh = jest
.spyOn(dashboardUtils, 'getInsightWithRetry')
.mockImplementation(async (_teamId, insight) => insight)
+ const capture = jest.spyOn(posthog, 'capture').mockClear()
try {
await expectLogic(logic, () => {
@@ -998,8 +999,22 @@ describe('dashboardLogic', () => {
expect(refresh.mock.calls.length > 0).toBe(autoPreview)
expect(logic.values.showApplyFiltersBanner).toBe(!autoPreview)
+ const change = capture.mock.calls.find(([event]) => event === 'dashboard filters changed')?.[1]
+ expect(change).toEqual(
+ expect.objectContaining({
+ filter_change_id: expect.any(String),
+ total_tile_count: insightCount,
+ can_auto_preview: autoPreview,
+ })
+ )
+ expect(capture.mock.calls.some(([event]) => event === 'dashboard refreshed')).toBe(autoPreview)
if (!autoPreview) {
refresh.mockClear()
+ jest.spyOn(api, 'update').mockResolvedValueOnce({
+ ...logic.values.dashboard!,
+ persisted_filters: { date_from: '-7d' },
+ persisted_variables: {},
+ })
await expectLogic(logic, () => {
logic.actions.saveDashboardChanges()
@@ -1007,6 +1022,14 @@ describe('dashboardLogic', () => {
expect(refresh).toHaveBeenCalled()
}
+ expect(capture).toHaveBeenCalledWith(
+ 'dashboard refreshed',
+ expect.objectContaining({
+ filter_change_id: change!.filter_change_id,
+ filter_change_duration_ms: expect.any(Number),
+ all_insights_succeeded: true,
+ })
+ )
} finally {
refresh.mockRestore()
}
@@ -3625,10 +3648,12 @@ describe('dashboardLogic', () => {
urlValue,
dashboardOverride,
insightOverride,
+ insightCount = 1,
}: {
urlValue?: string | null
dashboardOverride?: Partial<HogQLVariable>
insightOverride?: Partial<HogQLVariable>
+ insightCount?: number
}): Promise<void> => {
router.actions.push(
'/',
@@ -3661,7 +3686,16 @@ describe('dashboardLogic', () => {
}
const dashboardWithVariableOverride = {
- ...dashboardResult(12, [tileFromInsight(insightWithVariable)]),
+ ...dashboardResult(12, [
+ tileFromInsight(insightWithVariable),
+ ...Array.from({ length: insightCount - 1 }, (_, index) =>
+ tileFromInsight({
+ ...insightWithVariable,
+ id: 176 + index,
+ short_id: `retry-${index}` as InsightShortId,
+ })
+ ),
+ ]),
persisted_variables: dashboardOverride
? {
[variableId]: {
@@ -3926,29 +3960,92 @@ describe('dashboardLogic', () => {
)
})
- it('waits for Preview before refreshing SQL variable changes on a large dashboard', async () => {
- const autoPreviewLimit = jest.replaceProperty(dashboardUtils, 'AUTO_PREVIEW_TILE_LIMIT', 0)
- await mountDashboardWithVariable({})
- const getInsightWithRetrySpy = jest
- .spyOn(dashboardUtils, 'getInsightWithRetry')
- .mockImplementation(async (_teamId, insight) => insight)
+ it.each(['dashboard', 'individual tile'] as const)(
+ 'keeps the variable change ID and total wait through a failed refresh and %s retry',
+ async (retry) => {
+ const autoPreviewLimit = jest.replaceProperty(dashboardUtils, 'AUTO_PREVIEW_TILE_LIMIT', 0)
+ await mountDashboardWithVariable({ insightCount: 3 })
+ const capture = jest.spyOn(posthog, 'capture').mockClear()
+ const clock = jest.spyOn(performance, 'now').mockReturnValue(1000)
+ const refresh = jest
+ .spyOn(dashboardUtils, 'getInsightWithRetry')
+ .mockImplementation(async (_teamId, insight) => insight)
+ .mockRejectedValueOnce(new Error('First tile failed'))
+ .mockRejectedValueOnce(new Error('Second tile failed'))
- await expectLogic(logic, () => {
- logic.actions.overrideVariableValue(variableId, 'edited', false)
- }).toFinishAllListeners()
+ try {
+ await expectLogic(logic, () => {
+ logic.actions.overrideVariableValue(variableId, 'edited', false)
+ }).toFinishAllListeners()
- expect(logic.values.canAutoPreview).toBe(false)
- expect(getInsightWithRetrySpy).not.toHaveBeenCalled()
- expect(dashboardUtils.parseURLVariables(router.values.searchParams)).toEqual({ organization: 'edited' })
+ expect(logic.values.canAutoPreview).toBe(false)
+ expect(refresh).not.toHaveBeenCalled()
+ expect(dashboardUtils.parseURLVariables(router.values.searchParams)).toEqual({
+ organization: 'edited',
+ })
+ const change = capture.mock.calls.find(([event]) => event === 'dashboard filters changed')![1]!
+ expect(capture.mock.calls.some(([event]) => event === 'dashboard refreshed')).toBe(false)
- await expectLogic(logic, () => {
- logic.actions.previewDashboardChanges()
- }).toFinishAllListeners()
+ clock.mockReturnValue(6000)
+ await expectLogic(logic, () => {
+ if (retry === 'individual tile') {
+ jest.spyOn(api, 'update').mockResolvedValueOnce({
+ ...logic.values.dashboard!,
+ persisted_variables: logic.values.currentDashboardSettings.variables,
+ })
+ logic.actions.saveDashboardChanges()
+ } else {
+ logic.actions.previewDashboardChanges()
+ }
+ }).toFinishAllListeners()
+ expect(capture).toHaveBeenCalledWith(
+ 'dashboard refreshed',
+ expect.objectContaining({
+ filter_change_id: change.filter_change_id,
+ filter_change_duration_ms: 5000,
+ all_insights_succeeded: false,
+ tiles_errored_count: 2,
+ })
+ )
- expect(getInsightWithRetrySpy).toHaveBeenCalledTimes(1)
- getInsightWithRetrySpy.mockRestore()
- autoPreviewLimit.restore()
- })
+ clock.mockReturnValue(9000)
+ if (retry === 'individual tile') {
+ await expectLogic(logic, () => {
+ logic.actions.refreshDashboardItem({ tile: logic.values.insightTiles[0] })
+ }).toFinishAllListeners()
+ expect(capture).toHaveBeenCalledWith(
+ 'dashboard insight refreshed',
+ expect.objectContaining({
+ filter_change_id: change.filter_change_id,
+ filter_change_duration_ms: 8000,
+ all_insights_succeeded: false,
+ })
+ )
+ clock.mockReturnValue(10000)
+ await expectLogic(logic, () => {
+ logic.actions.refreshDashboardItem({ tile: logic.values.insightTiles[1] })
+ }).toFinishAllListeners()
+ } else {
+ await expectLogic(logic, () => logic.actions.previewDashboardChanges()).toFinishAllListeners()
+ }
+ const resultEvent =
+ retry === 'individual tile' ? 'dashboard insight refreshed' : 'dashboard refreshed'
+ const elapsed = retry === 'individual tile' ? 9000 : 8000
+ expect(capture).toHaveBeenCalledWith(
+ resultEvent,
+ expect.objectContaining({
+ filter_change_id: change.filter_change_id,
+ filter_change_duration_ms: elapsed,
+ all_insights_succeeded: true,
+ })
+ )
+ } finally {
+ refresh.mockRestore()
+ clock.mockRestore()
+ autoPreviewLimit.restore()
+ }
+ }
+ )
it.each(['manual', 'saved insight'])(
'uses dashboard context for a %s tile refresh before Preview',
@@ -3985,35 +4082,82 @@ describe('dashboardLogic', () => {
}
)
- it('makes Preview available when a SQL variable changes during an older preview', async () => {
- const autoPreviewLimit = jest.replaceProperty(dashboardUtils, 'AUTO_PREVIEW_TILE_LIMIT', 0)
- await mountDashboardWithVariable({})
- let finishPreview: (insight: InsightModel) => void = () => {
- throw new Error('Preview resolver is unavailable')
- }
- const preview = new Promise<InsightModel>((resolve) => {
- finishPreview = resolve
- })
- const getInsightWithRetrySpy = jest.spyOn(dashboardUtils, 'getInsightWithRetry').mockReturnValue(preview)
+ it.each(['edit', 'discard', 'unmount'] as const)(
+ 'keeps older Preview results separate after %s and tracks the next valid results',
+ async (transition) => {
+ const autoPreviewLimit = jest.replaceProperty(dashboardUtils, 'AUTO_PREVIEW_TILE_LIMIT', 0)
+ await mountDashboardWithVariable({})
+ const capture = jest.spyOn(posthog, 'capture').mockClear()
+ await expectLogic(logic, () => {
+ logic.actions.overrideVariableValue(variableId, 'first value', false)
+ }).toFinishAllListeners()
+ const change = capture.mock.calls.find(([event]) => event === 'dashboard filters changed')![1]!
+ let finishPreview!: (insight: InsightModel) => void
+ const preview = new Promise<InsightModel>((resolve) => {
+ finishPreview = resolve
+ })
+ const refresh = jest.spyOn(dashboardUtils, 'getInsightWithRetry').mockReturnValue(preview)
+ const insight = logic.values.insightTiles[0].insight!
- logic.actions.previewDashboardChanges()
- await expectLogic(logic).toMatchValues({ loadingPreview: true })
+ try {
+ await expectLogic(logic, () => logic.actions.previewDashboardChanges()).toDispatchActions([
+ 'setRefreshStatus',
+ ])
+ expect(logic.values.loadingPreview).toBe(true)
+
+ if (transition === 'edit') {
+ logic.actions.overrideVariableValue(variableId, 'newer value', false)
+ expect(logic.values.loadingPreview).toBe(false)
+ expect(capture).toHaveBeenCalledWith(
+ 'dashboard filters changed',
+ expect.objectContaining({ supersedes_filter_change_id: change.filter_change_id })
+ )
+ } else if (transition === 'discard') {
+ logic.actions.discardDashboardChanges()
+ } else {
+ logic.unmount()
+ }
- logic.actions.overrideVariableValue(variableId, 'newer value', false)
- await expectLogic(logic).toMatchValues({ loadingPreview: false })
+ finishPreview(insight)
+ await expectLogic(logic).toFinishAllListeners()
+ expect(capture).not.toHaveBeenCalledWith(
+ 'dashboard refreshed',
+ expect.objectContaining({ filter_change_id: change.filter_change_id })
+ )
+ if (transition === 'edit') {
+ expect(logic.values.previewedDashboardSettings?.variables[variableId].value).toBe('first value')
+ expect(logic.values.currentDashboardSettings.variables[variableId].value).toBe('newer value')
+ }
- finishPreview(logic.values.tiles[0].insight!)
- await expectLogic(logic).toFinishAllListeners()
- expect(logic.values.previewedDashboardSettings?.variables).toEqual({})
- expect(logic.values.currentDashboardSettings.variables[variableId]).toEqual(
- expect.objectContaining({ value: 'newer value' })
- )
- getInsightWithRetrySpy.mockRestore()
- autoPreviewLimit.restore()
- })
+ refresh.mockImplementation(async (_teamId, insight) => insight)
+ if (transition === 'unmount') {
+ await mountDashboardWithVariable({})
+ }
+ if (transition !== 'edit') {
+ logic.actions.overrideVariableValue(variableId, 'newer value', false)
+ }
+ await expectLogic(logic, () => logic.actions.previewDashboardChanges()).toFinishAllListeners()
+ const latestChange = capture.mock.calls
+ .filter(([event]) => event === 'dashboard filters changed')
+ .at(-1)![1]!
+ expect(latestChange.filter_change_id).not.toBe(change.filter_change_id)
+ expect(capture).toHaveBeenCalledWith(
+ 'dashboard refreshed',
+ expect.objectContaining({
+ filter_change_id: latestChange.filter_change_id,
+ all_insights_succeeded: true,
+ })
+ )
+ } finally {
+ refresh.mockRestore()
+ autoPreviewLimit.restore()
+ }
+ }
+ )
it('applying a variable value refreshes every tile with the new value attached to the request', async () => {
await mountDashboardWithVariable({})
+ const capture = jest.spyOn(posthog, 'capture').mockClear()
const getInsightWithRetrySpy = jest
.spyOn(dashboardUtils, 'getInsightWithRetry')
@@ -4032,6 +4176,14 @@ describe('dashboardLogic', () => {
expect(variablesOverride).toEqual({
[variableId]: expect.objectContaining({ code_name: 'organization', value: 'applied-value' }),
})
+ const change = capture.mock.calls.find(([event]) => event === 'dashboard filters changed')![1]!
+ expect(capture).toHaveBeenCalledWith(
+ 'dashboard refreshed',
+ expect.objectContaining({
+ filter_change_id: change.filter_change_id,
+ all_insights_succeeded: true,
+ })
+ )
} finally {
getInsightWithRetrySpy.mockRestore()
}
diff --git a/frontend/src/scenes/dashboard/dashboardLogic.tsx b/frontend/src/scenes/dashboard/dashboardLogic.tsx
index 23eafc6c5f70..00abf7eec685 100644
--- a/frontend/src/scenes/dashboard/dashboardLogic.tsx
+++ b/frontend/src/scenes/dashboard/dashboardLogic.tsx
@@ -48,6 +48,7 @@ import { deleteInsightWithUndo } from 'lib/utils/deleteWithUndo'
import { clearDOMTextSelection, getJSHeapMemory, uuid } from 'lib/utils/dom'
import {
DashboardEventSource,
+ DashboardFilterChangeType,
dashboardViewedProperties,
eventUsageLogic,
sanitizeDashboard,
@@ -170,13 +171,18 @@ import {
import { TileFiltersOverride } from './TileFiltersOverride'
import { tileLogic } from './tileLogic'
+function dashboardSettingsMatch(first: DashboardSettings, second: DashboardSettings): boolean {
+ return dashboardFiltersEqual(first.filters, second.filters) && equal(first.variables, second.variables)
+}
+
function reportDashboardTileRefreshed(
dashboardId: number,
tile: DashboardTile,
filters: Record<string, any>,
variables: Record<string, any>,
refreshDurationMs: number,
- individualRefresh: boolean
+ individualRefresh: boolean,
+ filterChange?: PendingFilterChange
): void {
const insight = tile.insight
const sanitizedQuery = insight?.query ? sanitizeQuery(insight.query) : {}
@@ -193,6 +199,13 @@ function reportDashboardTileRefreshed(
refresh_duration_ms: refreshDurationMs,
individual_refresh: individualRefresh,
...sanitizedQuery,
+ ...(filterChange
+ ? {
+ filter_change_id: filterChange.id,
+ filter_change_duration_ms: Math.floor(performance.now() - filterChange.startTime),
+ all_insights_succeeded: filterChange.remainingInsightIds.size === 0,
+ }
+ : {}),
})
}
@@ -202,6 +215,13 @@ export interface DashboardLogicProps {
placement?: DashboardPlacement
}
+interface PendingFilterChange {
+ id: string
+ startTime: number
+ settings: DashboardSettings
+ remainingInsightIds: Set<InsightShortId>
+}
+
export interface RefreshStatus {
/** Insight is about to be loaded */
queued?: boolean
@@ -759,6 +779,13 @@ export interface dashboardLogicActions {
tile: DashboardTile
}
}
+ reportDashboardFilterChange: (
+ changeType: DashboardFilterChangeType,
+ properties: Record<string, boolean | number | string | null | undefined>
+ ) => {
+ changeType: DashboardFilterChangeType
+ properties: Record<string, boolean | number | string | null | undefined>
+ }
reportDashboardViewed: () => {
value: true
}
@@ -1363,7 +1390,7 @@ export interface dashboardLogicMeta {
) => number | null
dataColorTheme: (
dataColorThemeId: number | null,
- getTheme: (themeId: number | string | null | undefined) => DataColorTheme | null // dataThemeLogic
+ getTheme: (themeId: number | string | null | undefined) => DataColorTheme | null
) => DataColorTheme | null
autoBreakdownColorsEnabled: (featureFlags: FeatureFlagsSet) => boolean
breakdownValuesIncomplete: (itemsLoading: boolean, insightTiles: DashboardTile[]) => boolean
@@ -1539,6 +1566,10 @@ export const dashboardLogic = kea<dashboardLogicType>([
setFilterTestAccounts: (filterTestAccounts: boolean | null) => ({ filterTestAccounts }),
setCompareFilter: (compareFilter: CompareFilter | null) => ({ compareFilter }),
setMetricFilters: (metricFilters: MetricsQueryFilter[] | null) => ({ metricFilters }),
+ reportDashboardFilterChange: (
+ changeType: DashboardFilterChangeType,
+ properties: Record<string, string | number | boolean | null | undefined>
+ ) => ({ changeType, properties }),
setExternalFilters: (filters: DashboardFilter) => ({ filters }),
setDashboardSettingsDraft: (settings: DashboardSettings | null) => ({ settings }),
setPreviewedDashboardSettings: (settings: DashboardSettings | null) => ({ settings }),
@@ -3692,6 +3723,7 @@ export const dashboardLogic = kea<dashboardLogicType>([
}
},
beforeUnmount: () => {
+ cache.pendingFilterChange = undefined
cache.widgetTileRefreshScheduler?.cancelAll()
actions.abortAnyRunningQuery()
},
@@ -4398,6 +4430,12 @@ export const dashboardLogic = kea<dashboardLogicType>([
// Cache values before the long-running await — the logic may unmount
const { currentTeamId, effectiveRefreshFilters, settingsForRefresh, urlFilters } = values
const urlVariables = settingsForRefresh.variables
+ const pendingFilterChange: PendingFilterChange | undefined = cache.pendingFilterChange
+ const filterChange =
+ pendingFilterChange && dashboardSettingsMatch(pendingFilterChange.settings, settingsForRefresh)
+ ? pendingFilterChange
+ : undefined
+ filterChange?.remainingInsightIds.add(insight.short_id)
actions.setRefreshStatus(insight.short_id, true, true)
@@ -4420,21 +4458,38 @@ export const dashboardLogic = kea<dashboardLogicType>([
tile.filters_overrides
)
+ const queryError = refreshedInsight ? getInsightQueryError(refreshedInsight) : null
+ const succeeded = !!refreshedInsight && !isRefreshRejectionStub(refreshedInsight) && !queryError
+ if (succeeded) {
+ dashboardsModel.actions.updateDashboardInsight(refreshedInsight, undefined, dashboardId)
+ actions.setRefreshStatus(insight.short_id)
+ } else {
+ actions.setRefreshError(insight.short_id, queryError?.code ? queryError : undefined)
+ }
+ const currentFilterChange =
+ filterChange &&
+ cache.pendingFilterChange?.id === filterChange.id &&
+ dashboardSettingsMatch(settingsForRefresh, values.currentDashboardSettings)
+ ? filterChange
+ : undefined
+ if (currentFilterChange) {
+ if (succeeded) {
+ currentFilterChange.remainingInsightIds.delete(insight.short_id)
+ } else {
+ currentFilterChange.remainingInsightIds.add(insight.short_id)
+ }
+ }
reportDashboardTileRefreshed(
dashboardId,
tile,
urlFilters,
urlVariables,
Math.floor(performance.now() - refreshStartTime),
- true
+ true,
+ currentFilterChange
)
-
- const queryError = refreshedInsight ? getInsightQueryError(refreshedInsight) : null
- if (refreshedInsight && !isRefreshRejectionStub(refreshedInsight) && !queryError) {
- dashboardsModel.actions.updateDashboardInsight(refreshedInsight, undefined, dashboardId)
- actions.setRefreshStatus(insight.short_id)
- } else {
- actions.setRefreshError(insight.short_id, queryError?.code ? queryError : undefined)
+ if (currentFilterChange?.remainingInsightIds.size === 0) {
+ cache.pendingFilterChange = undefined
}
} catch (e: any) {
actions.setRefreshError(insight.short_id, e)
@@ -4445,6 +4500,11 @@ export const dashboardLogic = kea<dashboardLogicType>([
const settingsToRefresh = previewUnsavedFilters
? values.currentDashboardSettings
: values.settingsForRefresh
+ const pendingFilterChange: PendingFilterChange | undefined = cache.pendingFilterChange
+ const filterChange =
+ pendingFilterChange && dashboardSettingsMatch(pendingFilterChange.settings, settingsToRefresh)
+ ? pendingFilterChange
+ : undefined
const isInitialLoad =
action === DashboardLoadAction.InitialLoad || action === DashboardLoadAction.InitialLoadWithVariables
const isInitialLoadOrUpdate = isInitialLoad || action === DashboardLoadAction.Update
@@ -4454,6 +4514,9 @@ export const dashboardLogic = kea<dashboardLogicType>([
const dashboardId: number = props.id
const allInsightTiles = values.insightTiles || []
const totalTileCount = allInsightTiles.length
+ if (filterChange) {
+ filterChange.remainingInsightIds = new Set(allInsightTiles.map((tile) => tile.insight!.short_id))
+ }
const sortedTilesToRefresh = allInsightTiles
// sort tiles so we poll them in the exact order they are computed on the backend
@@ -4527,6 +4590,7 @@ export const dashboardLogic = kea<dashboardLogicType>([
dashboardsModel.actions.updateDashboardInsight(refreshedInsight, undefined, dashboardId)
actions.setRefreshStatus(insight.short_id)
tilesRefreshedCount++
+ filterChange?.remainingInsightIds.delete(insight.short_id)
if (refreshedInsight.is_cached) {
tilesRefreshedCachedCount++
}
@@ -4540,9 +4604,11 @@ export const dashboardLogic = kea<dashboardLogicType>([
)
} else {
actions.setRefreshError(insight.short_id, queryError?.code ? queryError : undefined)
+ filterChange?.remainingInsightIds.add(insight.short_id)
tilesErroredCount++
}
} catch (e: any) {
+ filterChange?.remainingInsightIds.add(insight.short_id)
if (shouldCancelQuery(e)) {
console.warn(`Insight refresh cancelled for ${insight.short_id} due to abort signal:`, e)
actions.abortQuery({ queryId, queryStartTime, shortId: insight.short_id })
@@ -4585,6 +4651,13 @@ export const dashboardLogic = kea<dashboardLogicType>([
}
const refreshDurationMs = Math.floor(performance.now() - dashboardRefreshStartTime)
+ const filterChangeIsCurrent =
+ filterChange &&
+ cache.pendingFilterChange?.id === filterChange.id &&
+ dashboardSettingsMatch(settingsToRefresh, values.currentDashboardSettings)
+ const allInsightsSucceeded = filterChangeIsCurrent
+ ? filterChange.remainingInsightIds.size === 0
+ : tilesRefreshedCount === totalTileCount && tilesErroredCount === 0 && tilesAbortedCount === 0
posthog.capture(`dashboard refreshed`, {
dashboard_id: dashboardId,
filters: urlFilters,
@@ -4599,7 +4672,17 @@ export const dashboardLogic = kea<dashboardLogicType>([
tiles_refreshed_count: tilesRefreshedCount,
tiles_errored_count: tilesErroredCount,
tiles_aborted_count: tilesAbortedCount,
+ ...(filterChangeIsCurrent
+ ? {
+ filter_change_id: filterChange.id,
+ filter_change_duration_ms: Math.floor(performance.now() - filterChange.startTime),
+ all_insights_succeeded: allInsightsSucceeded,
+ }
+ : {}),
})
+ if (filterChangeIsCurrent && allInsightsSucceeded) {
+ cache.pendingFilterChange = undefined
+ }
if (
(previewUnsavedFilters || initialUrlOverridesArePreviewed) &&
@@ -4758,6 +4841,7 @@ export const dashboardLogic = kea<dashboardLogicType>([
}
},
discardDashboardChanges: () => {
+ cache.pendingFilterChange = undefined
actions.clearDashboardSettingsUrlOverrides()
actions.clearInitialDashboardSettingsOverride()
actions.setPreviewedDashboardSettings(null)
@@ -5076,12 +5160,29 @@ export const dashboardLogic = kea<dashboardLogicType>([
previewUnsavedFilters: true,
})
},
+ reportDashboardFilterChange: ({ changeType, properties }) => {
+ const previousChange: PendingFilterChange | undefined = cache.pendingFilterChange
+ const filterChange: PendingFilterChange = {
+ id: uuid(),
+ startTime: performance.now(),
+ settings: values.currentDashboardSettings,
+ remainingInsightIds: new Set(values.insightTiles.map((tile) => tile.insight!.short_id)),
+ }
+ cache.pendingFilterChange = filterChange
+ eventUsageLogic.actions.reportDashboardFiltersChanged(values.dashboard, changeType, {
+ ...properties,
+ filter_change_id: filterChange.id,
+ supersedes_filter_change_id: previousChange?.id,
+ total_tile_count: values.insightTiles.length,
+ can_auto_preview: values.canAutoPreview,
+ })
+ },
setProperties: ({ properties }) => {
actions.setDashboardSettingsDraft({
...values.currentDashboardSettings,
filters: { ...values.currentDashboardSettings.filters, properties },
})
- eventUsageLogic.actions.reportDashboardFiltersChanged(values.dashboard, 'properties', {
+ actions.reportDashboardFilterChange('properties', {
property_count: properties?.length ?? 0,
})
@@ -5103,7 +5204,7 @@ export const dashboardLogic = kea<dashboardLogicType>([
explicitDate,
},
})
- eventUsageLogic.actions.reportDashboardFiltersChanged(values.dashboard, 'date', {
+ actions.reportDashboardFilterChange('date', {
date_from: dateFrom,
date_to: dateTo ?? null,
})
@@ -5121,7 +5222,7 @@ export const dashboardLogic = kea<dashboardLogicType>([
...values.currentDashboardSettings,
filters: { ...values.currentDashboardSettings.filters, breakdown_filter },
})
- eventUsageLogic.actions.reportDashboardFiltersChanged(values.dashboard, 'breakdown', {
+ actions.reportDashboardFilterChange('breakdown', {
breakdown_type: breakdown_filter?.breakdown_type ?? null,
})
@@ -5138,7 +5239,7 @@ export const dashboardLogic = kea<dashboardLogicType>([
...values.currentDashboardSettings,
filters: { ...values.currentDashboardSettings.filters, interval },
})
- eventUsageLogic.actions.reportDashboardFiltersChanged(values.dashboard, 'interval', {
+ actions.reportDashboardFilterChange('interval', {
interval,
})
@@ -5155,7 +5256,7 @@ export const dashboardLogic = kea<dashboardLogicType>([
...values.currentDashboardSettings,
filters: { ...values.currentDashboardSettings.filters, filterTestAccounts },
})
- eventUsageLogic.actions.reportDashboardFiltersChanged(values.dashboard, 'test_accounts', {
+ actions.reportDashboardFilterChange('test_accounts', {
filter_test_accounts: filterTestAccounts,
})
@@ -5172,7 +5273,7 @@ export const dashboardLogic = kea<dashboardLogicType>([
...values.currentDashboardSettings,
filters: { ...values.currentDashboardSettings.filters, compareFilter },
})
- eventUsageLogic.actions.reportDashboardFiltersChanged(values.dashboard, 'compare', {
+ actions.reportDashboardFilterChange('compare', {
compare: compareFilter?.compare ?? null,
compare_to: compareFilter?.compare_to ?? null,
})
@@ -5190,7 +5291,7 @@ export const dashboardLogic = kea<dashboardLogicType>([
...values.currentDashboardSettings,
filters: { ...values.currentDashboardSettings.filters, metricFilters },
})
- eventUsageLogic.actions.reportDashboardFiltersChanged(values.dashboard, 'metric_labels', {
+ actions.reportDashboardFilterChange('metric_labels', {
metric_filter_count: metricFilters?.length ?? 0,
})
@@ -5211,10 +5312,6 @@ export const dashboardLogic = kea<dashboardLogicType>([
}
},
overrideVariableValue: ({ variableId, value, isNull }) => {
- eventUsageLogic.actions.reportDashboardFiltersChanged(values.dashboard, 'variable', {
- variable_id: variableId,
- })
-
const variableDefinition = values.variables.find((candidate) => candidate.id === variableId)
if (variableDefinition) {
const variable = { code_name: variableDefinition.code_name, variableId, value, isNull }
@@ -5235,6 +5332,10 @@ export const dashboardLogic = kea<dashboardLogicType>([
})
}
+ actions.reportDashboardFilterChange('variable', {
+ variable_id: variableId,
+ })
+
if (values.canAutoPreview) {
actions.refreshDashboardItems({
action: RefreshDashboardItemsAction.Preview,
diff --git a/frontend/src/scenes/dashboard/dashboardUtils.ts b/frontend/src/scenes/dashboard/dashboardUtils.ts
index d742dfbc7d35..117ebbed9f44 100644
--- a/frontend/src/scenes/dashboard/dashboardUtils.ts
+++ b/frontend/src/scenes/dashboard/dashboardUtils.ts
@@ -210,7 +210,7 @@ export const IS_TEST_MODE = process.env.NODE_ENV === 'test'
export const SEARCH_PARAM_QUERY_VARIABLES_KEY = 'query_variables'
export const SEARCH_PARAM_FILTERS_KEY = 'query_filters'
-export const AUTO_PREVIEW_TILE_LIMIT: number = 22
+export const AUTO_PREVIEW_TILE_LIMIT: number = 35
// A refresh that was rejected (concurrency limit, server-side calculation error) still resolves with an
// insight-shaped payload: no result, an errored query_status. Committing it to the dashboard would wipe