From 01f83015047d0026f3d7083430e930ad5d6e6c34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Mon, 29 Apr 2024 10:28:41 +0200 Subject: [PATCH] DashboardScene: Fixes issue with dashboard links and variables (#86910) * DashboardScene: Fixes issue with dashboard links and variables * Update --- .../dashboard-scene/scene/DashboardControls.tsx | 15 +++++++++++++++ .../SubMenu/DashboardLinksDashboard.tsx | 3 ++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/public/app/features/dashboard-scene/scene/DashboardControls.tsx b/public/app/features/dashboard-scene/scene/DashboardControls.tsx index 693e6b9ba46..e62cd864efe 100644 --- a/public/app/features/dashboard-scene/scene/DashboardControls.tsx +++ b/public/app/features/dashboard-scene/scene/DashboardControls.tsx @@ -10,6 +10,7 @@ import { SceneTimePicker, SceneRefreshPicker, SceneDebugger, + VariableDependencyConfig, } from '@grafana/scenes'; import { Box, Stack, useStyles2 } from '@grafana/ui'; @@ -27,6 +28,10 @@ interface DashboardControlsState extends SceneObjectState { export class DashboardControls extends SceneObjectBase { static Component = DashboardControlsRenderer; + protected _variableDependency = new VariableDependencyConfig(this, { + onAnyVariableChanged: this._onAnyVariableChanged.bind(this), + }); + public constructor(state: Partial) { super({ variableControls: [], @@ -35,6 +40,16 @@ export class DashboardControls extends SceneObjectBase { ...state, }); } + + /** + * Links can include all variables so we need to re-render when any change + */ + private _onAnyVariableChanged(): void { + const dashboard = getDashboardSceneFor(this); + if (dashboard.state.links?.length > 0) { + this.forceRender(); + } + } } function DashboardControlsRenderer({ model }: SceneComponentProps) { diff --git a/public/app/features/dashboard/components/SubMenu/DashboardLinksDashboard.tsx b/public/app/features/dashboard/components/SubMenu/DashboardLinksDashboard.tsx index fe77b4870e4..5d02274ad8f 100644 --- a/public/app/features/dashboard/components/SubMenu/DashboardLinksDashboard.tsx +++ b/public/app/features/dashboard/components/SubMenu/DashboardLinksDashboard.tsx @@ -2,7 +2,7 @@ import { css, cx } from '@emotion/css'; import React from 'react'; import { useAsync } from 'react-use'; -import { GrafanaTheme2 } from '@grafana/data'; +import { GrafanaTheme2, ScopedVars } from '@grafana/data'; import { sanitize, sanitizeUrl } from '@grafana/data/src/text/sanitize'; import { selectors } from '@grafana/e2e-selectors'; import { DashboardLink } from '@grafana/schema'; @@ -17,6 +17,7 @@ interface Props { link: DashboardLink; linkInfo: { title: string; href: string }; dashboardUID: string; + scopedVars?: ScopedVars; } interface DashboardLinksMenuProps {