From 5605d2f4a5fad6c70e27d8f26e6bbdc7cfad7224 Mon Sep 17 00:00:00 2001 From: Marcus Andersson Date: Thu, 11 May 2023 12:58:19 +0200 Subject: [PATCH] PluginExtensions: Expose scopedVars via the context to plugins that extends the dashboard panel menu (#67917) * Exposes the scoped vars to UI extensions via context. * reverted the interpolation when running a query via the query runner. * adding scoped vars to test.# --- packages/grafana-data/src/types/pluginExtensions.ts | 2 ++ .../features/dashboard/utils/getPanelMenu.test.ts | 12 ++++++++++++ public/app/features/dashboard/utils/getPanelMenu.ts | 1 + 3 files changed, 15 insertions(+) diff --git a/packages/grafana-data/src/types/pluginExtensions.ts b/packages/grafana-data/src/types/pluginExtensions.ts index dcc312a9c9c..1bb6eedce20 100644 --- a/packages/grafana-data/src/types/pluginExtensions.ts +++ b/packages/grafana-data/src/types/pluginExtensions.ts @@ -1,5 +1,6 @@ import { DataQuery } from '@grafana/schema'; +import { ScopedVars } from './ScopedVars'; import { RawTimeRange, TimeZone } from './time'; // Plugin Extensions types @@ -76,6 +77,7 @@ export type PluginExtensionPanelContext = { timeZone: TimeZone; dashboard: Dashboard; targets: DataQuery[]; + scopedVars?: ScopedVars; }; type Dashboard = { diff --git a/public/app/features/dashboard/utils/getPanelMenu.test.ts b/public/app/features/dashboard/utils/getPanelMenu.test.ts index 391f4bf82c1..ab80ab55047 100644 --- a/public/app/features/dashboard/utils/getPanelMenu.test.ts +++ b/public/app/features/dashboard/utils/getPanelMenu.test.ts @@ -201,6 +201,12 @@ describe('getPanelMenu()', () => { }, }, ], + scopedVars: { + a: { + text: 'a', + value: 'a', + }, + }, }); const dashboard = createDashboardModelFixture({ @@ -238,6 +244,12 @@ describe('getPanelMenu()', () => { uid: '123', title: 'My dashboard', }, + scopedVars: { + a: { + text: 'a', + value: 'a', + }, + }, }; expect(getPluginExtensions).toBeCalledWith(expect.objectContaining({ context })); diff --git a/public/app/features/dashboard/utils/getPanelMenu.ts b/public/app/features/dashboard/utils/getPanelMenu.ts index 84ca6f1ae10..3a13722b51a 100644 --- a/public/app/features/dashboard/utils/getPanelMenu.ts +++ b/public/app/features/dashboard/utils/getPanelMenu.ts @@ -341,5 +341,6 @@ function createExtensionContext(panel: PanelModel, dashboard: DashboardModel): P tags: Array.from(dashboard.tags), }, targets: panel.targets, + scopedVars: panel.scopedVars, }; }