: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(dashboards): use a fixed automatic preview limit (#103484)
Paul D'Ambra84ef6f254001
diff --git a/.agents/skills/managing-dashboards/references/filter-editing-and-temporary-views.md b/.agents/skills/managing-dashboards/references/filter-editing-and-temporary-views.mdindex 24c4772d856b..75260d2525be 100644--- a/.agents/skills/managing-dashboards/references/filter-editing-and-temporary-views.md+++ b/.agents/skills/managing-dashboards/references/filter-editing-and-temporary-views.md@@ -185,8 +185,8 @@ Also check these separate boundaries:Use one local dashboard with at least two working insight tiles and three SQL variables.-1. Set `dashboard-auto-preview-limit` above the insight-tile count. Edit filters and variables. Confirm immediate preview and one draft.-2. Set the limit at or below the insight-tile count. Edit filters and variables. Confirm that the URL changes without an automatic preview.+1. Use a dashboard with fewer than 22 insight tiles. Edit filters and variables. Confirm immediate preview and one draft.+2. Use a dashboard with at least 22 insight tiles. Edit filters and variables. Confirm that the URL changes without an automatic preview.3. Reload the URL override view. Confirm that the dashboard data uses the overrides and the status shows Previewing.4. Select Preview. Confirm that Preview updates data without saving the draft.5. Save combined changes. Confirm both URL parameters clear. Reload and confirm the saved values.diff --git a/frontend/src/lib/constants.tsx b/frontend/src/lib/constants.tsxindex 3de12b6a7f71..eba3e7b0cf1a 100644--- a/frontend/src/lib/constants.tsx+++ b/frontend/src/lib/constants.tsx@@ -284,7 +284,6 @@ export const FEATURE_FLAGS = {CUSTOMER_ANALYTICS_FEATURE_REQUESTS: 'customer-analytics-feature-requests',CUSTOMER_ANALYTICS_JOURNEYS: 'customer-analytics-journeys', // owner: @arthurdedeus #team-customer-analyticsCUSTOMER_ANALYTICS_TRACK_RULES: 'customer-analytics-track-rules', // owner: @arthurdedeus #team-customer-analytics- DASHBOARD_AUTO_PREVIEW_LIMIT: 'dashboard-auto-preview-limit', // owner: @pauldambra #team-product-analyticsDASHBOARD_EXPORT_NUDGE: 'dashboard-export-nudge', // owner: #team-analytics-platform multivariate=control,test, nudges people who just exported a dashboard toward a recurring subscriptionDASHBOARD_LAYOUT_DISCARD_PROMPT: 'dashboard-layout-discard-prompt', // owner: @cory.s #team-analytics-platformDASHBOARD_TEMPLATE_CHOOSER_EXPERIMENT: 'dashboard-template-chooser-experiment', // owner: @mattp #team-analytics-platform multivariate=control,simple,newdiff --git a/frontend/src/scenes/dashboard/dashboardLogic.test.ts b/frontend/src/scenes/dashboard/dashboardLogic.test.tsindex c2d3d513df09..0e0581a615df 100644--- a/frontend/src/scenes/dashboard/dashboardLogic.test.ts+++ b/frontend/src/scenes/dashboard/dashboardLogic.test.ts@@ -12,7 +12,6 @@ import api from 'lib/api'import { ApiError } from 'lib/api-error'import { FEATURE_FLAGS } from 'lib/constants'import { dayjs, now } from 'lib/dayjs'-import * as featureFlagLib from 'lib/logic/featureFlagLogic'import { featureFlagLogic } from 'lib/logic/featureFlagLogic'import { DashboardEventSource, eventUsageLogic } from 'lib/utils/eventUsageLogic'import { addInsightToDashboardLogic } from 'scenes/dashboard/addInsightToDashboardModalLogic'@@ -858,7 +857,7 @@ describe('dashboardLogic', () => {})it('cancelling layout editing keeps unapplied filter changes', async () => {- const payloadSpy = jest.spyOn(featureFlagLib, 'getFeatureFlagPayload').mockReturnValue(1)+ const autoPreviewLimit = jest.replaceProperty(dashboardUtils, 'AUTO_PREVIEW_TILE_LIMIT', 1)await expectLogic(logic).toFinishAllListeners()expect(logic.values.canAutoPreview).toBe(false)@@ -884,7 +883,7 @@ describe('dashboardLogic', () => {expect(logic.values.dashboardSettingsDraft?.filters).toEqual(expect.objectContaining({ date_from: '-7d' }))expect(logic.values.filtersDirty).toBe(true)- payloadSpy.mockRestore()+ autoPreviewLimit.restore()})it('saving current filters does not refresh tiles again', async () => {@@ -901,23 +900,50 @@ describe('dashboardLogic', () => {.toFinishAllListeners()})- it('saving unapplied dashboard settings refreshes tiles above the auto-preview limit', async () => {- const payloadSpy = jest.spyOn(featureFlagLib, 'getFeatureFlagPayload').mockReturnValue(1)-+ it.each([+ [21, true],+ [22, false],+ ])('previews filter changes automatically with %i insights: %s', async (insightCount, autoPreview) => {await expectLogic(logic).toFinishAllListeners()- expect(logic.values.canAutoPreview).toBe(false)+ const dashboard = {+ ...dashboards[5],+ tiles: [+ ...Array.from({ length: insightCount }, (_, index) => ({+ ...dashboards[5].tiles[0],+ id: index + 100,+ layouts: {},+ })),+ TEXT_TILE,+ WIDGET_TILE,+ ],+ }+ logic.unmount()+ logic = dashboardLogic({ id: 5, dashboard })+ logic.mount()+ await expectLogic(logic).toFinishAllListeners()+ const refresh = jest+ .spyOn(dashboardUtils, 'getInsightWithRetry')+ .mockImplementation(async (_teamId, insight) => insight)- await expectLogic(logic, () => {- logic.actions.setDates('-7d', null)- }).toFinishAllListeners()+ try {+ await expectLogic(logic, () => {+ logic.actions.setDates('-7d', null)+ }).toFinishAllListeners()- await expectLogic(logic, () => {- logic.actions.saveDashboardChanges()- })- .toDispatchActions(['saveDashboardChanges', 'saveDashboardChangesSuccess', 'refreshDashboardItems'])- .toFinishAllListeners()+ expect(refresh.mock.calls.length > 0).toBe(autoPreview)+ expect(logic.values.showApplyFiltersBanner).toBe(!autoPreview)+ if (!autoPreview) {+ refresh.mockClear()++ await expectLogic(logic, () => {+ logic.actions.saveDashboardChanges()+ }).toFinishAllListeners()- payloadSpy.mockRestore()+ expect(refresh).toHaveBeenCalled()+ }+ } finally {+ refresh.mockRestore()+ }})it('keeps combined auto-preview filters after a page reload, then clears and saves them', async () => {@@ -1003,7 +1029,7 @@ describe('dashboardLogic', () => {})it('keeps unapplied filters separate from layout cancellation and layout saving', async () => {- const autoPreviewLimitSpy = jest.spyOn(featureFlagLib, 'getFeatureFlagPayload').mockReturnValue(8)+ const autoPreviewLimit = jest.replaceProperty(dashboardUtils, 'AUTO_PREVIEW_TILE_LIMIT', 8)const nineTileDashboard: DashboardType<QueryBasedInsightModel> = {...dashboards[5],tiles: Array.from({ length: 9 }, (_, index) => ({@@ -1158,7 +1184,7 @@ describe('dashboardLogic', () => {expect(logic.values.urlFilters).toEqual({})expect(logic.values.dashboardSettingsDraft).toBeNull()- autoPreviewLimitSpy.mockRestore()+ autoPreviewLimit.restore()})it('saving after breakdown color change calls api', async () => {@@ -3378,7 +3404,7 @@ describe('dashboardLogic', () => {})it('waits for Preview before refreshing SQL variable changes on a large dashboard', async () => {- const payloadSpy = jest.spyOn(featureFlagLib, 'getFeatureFlagPayload').mockReturnValue(0)+ const autoPreviewLimit = jest.replaceProperty(dashboardUtils, 'AUTO_PREVIEW_TILE_LIMIT', 0)await mountDashboardWithVariable({})const getInsightWithRetrySpy = jest.spyOn(dashboardUtils, 'getInsightWithRetry')@@ -3398,11 +3424,11 @@ describe('dashboardLogic', () => {expect(getInsightWithRetrySpy).toHaveBeenCalledTimes(1)getInsightWithRetrySpy.mockRestore()- payloadSpy.mockRestore()+ autoPreviewLimit.restore()})it('uses visible SQL variable values when refreshing one tile before Preview', async () => {- const payloadSpy = jest.spyOn(featureFlagLib, 'getFeatureFlagPayload').mockReturnValue(0)+ const autoPreviewLimit = jest.replaceProperty(dashboardUtils, 'AUTO_PREVIEW_TILE_LIMIT', 0)await mountDashboardWithVariable({})const getInsightWithRetrySpy = jest.spyOn(dashboardUtils, 'getInsightWithRetry')@@ -3421,12 +3447,12 @@ describe('dashboardLogic', () => {expect(getInsightWithRetrySpy.mock.calls[0][7]).toEqual({})} finally {getInsightWithRetrySpy.mockRestore()- payloadSpy.mockRestore()+ autoPreviewLimit.restore()}})it('makes Preview available when a SQL variable changes during an older preview', async () => {- const payloadSpy = jest.spyOn(featureFlagLib, 'getFeatureFlagPayload').mockReturnValue(0)+ const autoPreviewLimit = jest.replaceProperty(dashboardUtils, 'AUTO_PREVIEW_TILE_LIMIT', 0)await mountDashboardWithVariable({})let finishPreview: (insight: QueryBasedInsightModel) => void = () => {throw new Error('Preview resolver is unavailable')@@ -3449,7 +3475,7 @@ describe('dashboardLogic', () => {expect.objectContaining({ value: 'newer value' }))getInsightWithRetrySpy.mockRestore()- payloadSpy.mockRestore()+ autoPreviewLimit.restore()})it('applying a variable value refreshes every tile with the new value attached to the request', async () => {diff --git a/frontend/src/scenes/dashboard/dashboardLogic.tsx b/frontend/src/scenes/dashboard/dashboardLogic.tsxindex 98ee44eb98ae..6e2a84f6487b 100644--- a/frontend/src/scenes/dashboard/dashboardLogic.tsx+++ b/frontend/src/scenes/dashboard/dashboardLogic.tsx@@ -40,7 +40,7 @@ import { OrganizationMembershipLevel } from 'lib/constants'import { FEATURE_FLAGS } from 'lib/constants'import { Dayjs, dayjs, now } from 'lib/dayjs'import { Link } from 'lib/lemon-ui/Link'-import { featureFlagLogic, getFeatureFlagPayload } from 'lib/logic/featureFlagLogic'+import { featureFlagLogic } from 'lib/logic/featureFlagLogic'import { accessLevelSatisfied } from 'lib/utils/accessControlUtils'import { deleteInsightWithUndo } from 'lib/utils/deleteWithUndo'import { clearDOMTextSelection, getJSHeapMemory, uuid } from 'lib/utils/dom'@@ -138,7 +138,7 @@ import {BREAKPOINT_COLUMN_COUNTS,DASHBOARD_MIN_REFRESH_INTERVAL_MINUTES,IS_TEST_MODE,- DEFAULT_AUTO_PREVIEW_TILE_LIMIT,+ AUTO_PREVIEW_TILE_LIMIT,SEARCH_PARAM_FILTERS_KEY,SEARCH_PARAM_QUERY_VARIABLES_KEY,combineDashboardFilters,@@ -2680,13 +2680,7 @@ export const dashboardLogic = kea<dashboardLogicType>([insightTiles: DashboardTile<QueryBasedInsightModel<import('~/queries/schema/schema-general').Node<Record<string, any>>>>[]- ) => {- const payload = getFeatureFlagPayload(FEATURE_FLAGS.DASHBOARD_AUTO_PREVIEW_LIMIT)- const limit = typeof payload === 'number' ? payload : DEFAULT_AUTO_PREVIEW_TILE_LIMIT- // The limit is about the number of insights on a dashboard (per the flag's intent),- // so count insight tiles only — not text, button, or widget tiles.- return insightTiles.length < limit- },+ ): boolean => insightTiles.length < AUTO_PREVIEW_TILE_LIMIT,],savedDashboardSettings: [(s) => [s.dashboard],diff --git a/frontend/src/scenes/dashboard/dashboardUtils.ts b/frontend/src/scenes/dashboard/dashboardUtils.tsindex 66b65f7a204c..c27e830cf33d 100644--- a/frontend/src/scenes/dashboard/dashboardUtils.ts+++ b/frontend/src/scenes/dashboard/dashboardUtils.ts@@ -179,7 +179,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 DEFAULT_AUTO_PREVIEW_TILE_LIMIT = 10+export const AUTO_PREVIEW_TILE_LIMIT: number = 22const RATE_LIMIT_ERROR_MESSAGE = 'concurrency_limit_exceeded'diff --git a/products/dashboards/frontend/dashboardSettings/DashboardFilters.test.tsx b/products/dashboards/frontend/dashboardSettings/DashboardFilters.test.tsxindex 1e906d80b2c8..c439323007eb 100644--- a/products/dashboards/frontend/dashboardSettings/DashboardFilters.test.tsx+++ b/products/dashboards/frontend/dashboardSettings/DashboardFilters.test.tsx@@ -5,7 +5,6 @@ import { BindLogic } from 'kea'import { router } from 'kea-router'import { expectLogic } from 'kea-test-utils'-import * as featureFlagLib from 'lib/logic/featureFlagLogic'import { DashboardEventSource } from 'lib/utils/eventUsageLogic'import { DashboardFilterBar } from 'scenes/dashboard/DashboardFilters'import { dashboardLogic } from 'scenes/dashboard/dashboardLogic'@@ -118,7 +117,7 @@ describe('DashboardFilterBar', () => {})it('keeps Preview and Discard available, but hides Save filters, for viewers', async () => {- const payloadSpy = jest.spyOn(featureFlagLib, 'getFeatureFlagPayload').mockReturnValue(0)+ const autoPreviewLimit = jest.replaceProperty(dashboardUtils, 'AUTO_PREVIEW_TILE_LIMIT', 0)const viewerDashboard: DashboardType<QueryBasedInsightModel> = {...MOCK_DASHBOARD,user_access_level: AccessControlLevel.Viewer,@@ -142,13 +141,13 @@ describe('DashboardFilterBar', () => {expect(document.querySelector('[data-attr="dashboard-apply-filters"]')).toBeInTheDocument()expect(document.querySelector('[data-attr="dashboard-save-filters"]')).not.toBeInTheDocument()} finally {- payloadSpy.mockRestore()+ autoPreviewLimit.restore()logic.unmount()}})it('keeps Preview disabled until the dashboard settings change', async () => {- const payloadSpy = jest.spyOn(featureFlagLib, 'getFeatureFlagPayload').mockReturnValue(0)+ const autoPreviewLimit = jest.replaceProperty(dashboardUtils, 'AUTO_PREVIEW_TILE_LIMIT', 0)let finishPreview: (insight: QueryBasedInsightModel) => void = () => {throw new Error('Preview resolver is unavailable')}@@ -205,12 +204,12 @@ describe('DashboardFilterBar', () => {)getInsightSpy.mockRestore()- payloadSpy.mockRestore()+ autoPreviewLimit.restore()logic.unmount()})it('makes Preview available after a preview request fails', async () => {- const payloadSpy = jest.spyOn(featureFlagLib, 'getFeatureFlagPayload').mockReturnValue(0)+ const autoPreviewLimit = jest.replaceProperty(dashboardUtils, 'AUTO_PREVIEW_TILE_LIMIT', 0)const getInsightSpy = jest.spyOn(dashboardUtils, 'getInsightWithRetry').mockRejectedValue(new Error('Preview request failed'))@@ -242,7 +241,7 @@ describe('DashboardFilterBar', () => {)getInsightSpy.mockRestore()- payloadSpy.mockRestore()+ autoPreviewLimit.restore()logic.unmount()})