From d8b8a2c2b0c4e56739ae4d77f70b014d7e2fb690 Mon Sep 17 00:00:00 2001 From: kay delaney <45561153+kaydelaney@users.noreply.github.com> Date: Mon, 11 Mar 2024 14:53:59 +0000 Subject: [PATCH] Dashboard: Fix issue where out-of-view shared query panels caused blank dependent panels (#83966) --- .../dashgrid/PanelStateWrapper.test.tsx | 2 ++ .../features/dashboard/state/DashboardModel.ts | 17 ++++++++++++++--- .../app/features/dashboard/state/PanelModel.ts | 2 +- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/public/app/features/dashboard/dashgrid/PanelStateWrapper.test.tsx b/public/app/features/dashboard/dashgrid/PanelStateWrapper.test.tsx index 8b6be6c4b98..c46d74b3728 100644 --- a/public/app/features/dashboard/dashgrid/PanelStateWrapper.test.tsx +++ b/public/app/features/dashboard/dashgrid/PanelStateWrapper.test.tsx @@ -74,6 +74,8 @@ function setupTestContext(options: Partial) { ); + // Needed so mocks work + props.panel.refreshWhenInView = false; return { rerender, props, subject, store }; } diff --git a/public/app/features/dashboard/state/DashboardModel.ts b/public/app/features/dashboard/state/DashboardModel.ts index 35969d751c1..b1cbf4a502a 100644 --- a/public/app/features/dashboard/state/DashboardModel.ts +++ b/public/app/features/dashboard/state/DashboardModel.ts @@ -384,11 +384,22 @@ export class DashboardModel implements TimeModel { return; } - for (const panel of this.panels) { - if (!this.otherPanelInFullscreen(panel) && (event.refreshAll || event.panelIds.includes(panel.id))) { - panel.refresh(); + const panelsToRefresh = this.panels.filter( + (panel) => !this.otherPanelInFullscreen(panel) && (event.refreshAll || event.panelIds.includes(panel.id)) + ); + + // We have to mark every panel as refreshWhenInView /before/ we actually refresh any + // in case there is a shared query, as otherwise that might refresh before the source panel is + // marked for refresh, preventing the panel from updating + if (!this.isSnapshot()) { + for (const panel of panelsToRefresh) { + panel.refreshWhenInView = true; } } + + for (const panel of panelsToRefresh) { + panel.refresh(); + } } render() { diff --git a/public/app/features/dashboard/state/PanelModel.ts b/public/app/features/dashboard/state/PanelModel.ts index 1b3a6b2fbba..08d68628972 100644 --- a/public/app/features/dashboard/state/PanelModel.ts +++ b/public/app/features/dashboard/state/PanelModel.ts @@ -205,7 +205,7 @@ export class PanelModel implements DataConfigSource, IPanelModel { cacheTimeout?: string | null; queryCachingTTL?: number | null; isNew?: boolean; - refreshWhenInView = false; + refreshWhenInView = true; cachedPluginOptions: Record = {}; legend?: { show: boolean; sort?: string; sortDesc?: boolean };