From 32e7839cb8f040707066376b9c8b2e81f63ade62 Mon Sep 17 00:00:00 2001 From: "grafana-delivery-bot[bot]" <132647405+grafana-delivery-bot[bot]@users.noreply.github.com> Date: Mon, 11 Mar 2024 17:10:52 +0200 Subject: [PATCH] [v10.4.x] Dashboard: Fix issue where out-of-view shared query panels caused blank dependent panels (#84197) Dashboard: Fix issue where out-of-view shared query panels caused blank dependent panels (#83966) (cherry picked from commit d8b8a2c2b0c4e56739ae4d77f70b014d7e2fb690) Co-authored-by: kay delaney <45561153+kaydelaney@users.noreply.github.com> --- .../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 b4b5d3376ad..4e970f3d9d4 100644 --- a/public/app/features/dashboard/state/DashboardModel.ts +++ b/public/app/features/dashboard/state/DashboardModel.ts @@ -440,11 +440,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 fcf1307a284..73c802beac3 100644 --- a/public/app/features/dashboard/state/PanelModel.ts +++ b/public/app/features/dashboard/state/PanelModel.ts @@ -203,7 +203,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 };