From beac7de4dfcb713690b00b6dd4b9d68ce55d7bfd Mon Sep 17 00:00:00 2001 From: Victor Marin <36818606+mdvictor@users.noreply.github.com> Date: Thu, 17 Oct 2024 17:22:04 +0300 Subject: [PATCH] DashboardScenes: Fix panel links to update on variable or timerange change (#94865) * Fix panel links to update on variable or timerange change * refactor --------- Co-authored-by: alexandra vargas --- .../dashboard-scene/scene/PanelLinks.tsx | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/public/app/features/dashboard-scene/scene/PanelLinks.tsx b/public/app/features/dashboard-scene/scene/PanelLinks.tsx index 3e46299dc83..df44a16f6a4 100644 --- a/public/app/features/dashboard-scene/scene/PanelLinks.tsx +++ b/public/app/features/dashboard-scene/scene/PanelLinks.tsx @@ -1,5 +1,12 @@ import { DataLink, LinkModel } from '@grafana/data'; -import { SceneComponentProps, SceneObjectBase, SceneObjectState, VizPanel } from '@grafana/scenes'; +import { + SceneComponentProps, + sceneGraph, + SceneObjectBase, + SceneObjectState, + VariableDependencyConfig, + VizPanel, +} from '@grafana/scenes'; import { Dropdown, Icon, Menu, PanelChrome, ToolbarButton } from '@grafana/ui'; import { getPanelLinks } from './PanelMenuBehavior'; @@ -11,11 +18,20 @@ interface VizPanelLinksState extends SceneObjectState { } export class VizPanelLinks extends SceneObjectBase { + protected _variableDependency = new VariableDependencyConfig(this, { + onAnyVariableChanged: () => { + if (this.state.rawLinks && this.state.rawLinks.length > 0) { + this.forceRender(); + } + }, + }); + static Component = VizPanelLinksRenderer; } function VizPanelLinksRenderer({ model }: SceneComponentProps) { const { menu, rawLinks } = model.useState(); + sceneGraph.getTimeRange(model).useState(); if (!(model.parent instanceof VizPanel)) { throw new Error('VizPanelLinks must be a child of VizPanel');