diff --git a/packages/grafana-data/src/types/pluginExtensions.ts b/packages/grafana-data/src/types/pluginExtensions.ts index 1bb6eedce20..1ed7cb1d866 100644 --- a/packages/grafana-data/src/types/pluginExtensions.ts +++ b/packages/grafana-data/src/types/pluginExtensions.ts @@ -1,6 +1,7 @@ import { DataQuery } from '@grafana/schema'; import { ScopedVars } from './ScopedVars'; +import { PanelData } from './panel'; import { RawTimeRange, TimeZone } from './time'; // Plugin Extensions types @@ -78,6 +79,7 @@ export type PluginExtensionPanelContext = { dashboard: Dashboard; targets: DataQuery[]; scopedVars?: ScopedVars; + data?: PanelData; }; type Dashboard = { diff --git a/public/app/features/dashboard/utils/getPanelMenu.test.ts b/public/app/features/dashboard/utils/getPanelMenu.test.ts index ab80ab55047..d4a16dcbfe2 100644 --- a/public/app/features/dashboard/utils/getPanelMenu.test.ts +++ b/public/app/features/dashboard/utils/getPanelMenu.test.ts @@ -1,4 +1,13 @@ -import { PanelMenuItem, PluginExtensionPanelContext, PluginExtensionTypes } from '@grafana/data'; +import { + dateTime, + FieldType, + LoadingState, + PanelData, + PanelMenuItem, + PluginExtensionPanelContext, + PluginExtensionTypes, + toDataFrame, +} from '@grafana/data'; import { getPluginExtensions } from '@grafana/runtime'; import config from 'app/core/config'; import * as actions from 'app/features/explore/state/main'; @@ -189,6 +198,26 @@ describe('getPanelMenu()', () => { }); it('should pass context with correct values when configuring extension', () => { + const data: PanelData = { + series: [ + toDataFrame({ + fields: [ + { name: 'time', type: FieldType.time }, + { name: 'score', type: FieldType.number }, + ], + }), + ], + timeRange: { + from: dateTime(), + to: dateTime(), + raw: { + from: 'now', + to: 'now-1h', + }, + }, + state: LoadingState.Done, + }; + const panel = new PanelModel({ type: 'timeseries', id: 1, @@ -207,6 +236,9 @@ describe('getPanelMenu()', () => { value: 'a', }, }, + queryRunner: { + getLastResult: jest.fn(() => data), + }, }); const dashboard = createDashboardModelFixture({ @@ -250,6 +282,7 @@ describe('getPanelMenu()', () => { value: 'a', }, }, + data, }; 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 3a13722b51a..20a3d20bd0d 100644 --- a/public/app/features/dashboard/utils/getPanelMenu.ts +++ b/public/app/features/dashboard/utils/getPanelMenu.ts @@ -342,5 +342,6 @@ function createExtensionContext(panel: PanelModel, dashboard: DashboardModel): P }, targets: panel.targets, scopedVars: panel.scopedVars, + data: panel.getQueryRunner().getLastResult(), }; }