: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): let external filters beat saved dashboard filters (#98806)
posthog[bot]07c905d79399
diff --git a/frontend/src/scenes/dashboard/dashboardLogic.test.ts b/frontend/src/scenes/dashboard/dashboardLogic.test.tsindex e9f308e95840..e58901b599a5 100644--- a/frontend/src/scenes/dashboard/dashboardLogic.test.ts+++ b/frontend/src/scenes/dashboard/dashboardLogic.test.ts@@ -183,6 +183,10 @@ describe('dashboardLogic', () => {13: {...dashboardResult(13, []),},+ 18: {+ ...dashboardResult(18, [tileFromInsight(uncached(insights['800']))]),+ persisted_filters: { date_from: '-24h' },+ },}useMocks({get: {@@ -209,6 +213,7 @@ describe('dashboardLogic', () => {'/api/environments/:team_id/dashboards/10/': { ...dashboards[10] },'/api/environments/:team_id/dashboards/11/': { ...dashboards[11] },'/api/environments/:team_id/dashboards/12/': { ...dashboards[12] },+ '/api/environments/:team_id/dashboards/18/': { ...dashboards[18] },'/api/environments/:team_id/dashboards/': {count: 6,next: null,@@ -1764,6 +1769,54 @@ describe('dashboardLogic', () => {})})+ describe('external filter overrides', () => {+ // Dashboards 12 and 18 persist `date_from: '-24h'`, like a dashboard that a scene embeds+ // and drives with its own date picker.+ const openWithExternalFilters = async (dashboardId: number): Promise<void> => {+ logic.unmount()+ router.actions.push(`/dashboard/${dashboardId}`)+ logic = dashboardLogic({ id: dashboardId, placement: DashboardPlacement.Builtin })+ logic.mount()+ await expectLogic(logic).toFinishAllListeners()+ }++ it('lets an external date beat the persisted dashboard filters', async () => {+ await openWithExternalFilters(12)++ await expectLogic(logic, () => {+ logic.actions.setExternalFilters({ date_from: '-30d', date_to: null })+ }).toFinishAllListeners()++ expect(logic.values.currentDashboardSettings.filters).toEqual(+ expect.objectContaining({ date_from: '-24h' })+ )+ expect(logic.values.filtersOverrideForLoad).toEqual(+ expect.objectContaining({ date_from: '-30d', date_to: null })+ )+ })++ it('refreshes the tiles with the external date, not the persisted one', async () => {+ await openWithExternalFilters(18)++ const getInsightWithRetrySpy = jest+ .spyOn(dashboardUtils, 'getInsightWithRetry')+ .mockImplementation(async (_teamId, insight) => insight)++ try {+ await expectLogic(logic, () => {+ logic.actions.setExternalFilters({ date_from: '-30d', date_to: null })+ }).toFinishAllListeners()++ expect(getInsightWithRetrySpy).toHaveBeenCalled()+ expect(getInsightWithRetrySpy.mock.calls[0][6]).toEqual(+ expect.objectContaining({ date_from: '-30d', date_to: null })+ )+ } finally {+ getInsightWithRetrySpy.mockRestore()+ }+ })+ })+describe('hasUnsavedLayoutChanges selector', () => {const moveFirstTile = (): void => {const firstTile = logic.values.dashboard!.tiles[0]diff --git a/frontend/src/scenes/dashboard/dashboardLogic.tsx b/frontend/src/scenes/dashboard/dashboardLogic.tsxindex 1ce8e26e0402..d84ddd950aa8 100644--- a/frontend/src/scenes/dashboard/dashboardLogic.tsx+++ b/frontend/src/scenes/dashboard/dashboardLogic.tsx@@ -2760,7 +2760,7 @@ export const dashboardLogic = kea<dashboardLogicType>([filtersOverrideForLoad: [(s) => [s.externalFilters, s.currentDashboardSettings],(externalFilters: DashboardFilter, settings: DashboardSettings) =>- combineDashboardFilters(externalFilters, settings.filters),+ combineDashboardFilters(settings.filters, externalFilters),],effectiveEditBarFilters: [(s) => [s.externalFilters, s.currentDashboardSettings],@@ -4169,7 +4169,7 @@ export const dashboardLogic = kea<dashboardLogicType>([// may be unmounted by the time the awaits complete (kea's no-arg breakpoint()// only cancels on newer invocations, not on unmount).const { currentTeamId, externalFilters, urlFilters, dashboardLoadData, lastDashboardRefresh } = values- const effectiveRefreshFilters = combineDashboardFilters(externalFilters, settingsToRefresh.filters)+ const effectiveRefreshFilters = combineDashboardFilters(settingsToRefresh.filters, externalFilters)const urlVariables = settingsToRefresh.variablesconst fetchSyncInsightFunctions = sortedTilesToRefresh.map((tile) => async () => {