mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
DashboardScene: Fixes issue referring to library panel in dashboard data source (#87125)
* DashboardScene: Fixes issue using a library panel as source for dashboard data source * Added test
This commit is contained in:
parent
f806b9749d
commit
4034a26972
@ -53,7 +53,7 @@ export class DashboardDatasourceBehaviour extends SceneObjectBase<DashboardDatas
|
||||
|
||||
const sourcePanelQueryRunner = getQueryRunnerFor(panel);
|
||||
|
||||
if (!(sourcePanelQueryRunner instanceof SceneQueryRunner)) {
|
||||
if (!sourcePanelQueryRunner) {
|
||||
if (!(panel.parent instanceof LibraryVizPanel)) {
|
||||
throw new Error('Could not find SceneQueryRunner for panel');
|
||||
} else {
|
||||
|
@ -0,0 +1,26 @@
|
||||
import { VizPanel } from '@grafana/scenes';
|
||||
|
||||
import { LibraryVizPanel } from '../scene/LibraryVizPanel';
|
||||
|
||||
import { PanelModelCompatibilityWrapper } from './PanelModelCompatibilityWrapper';
|
||||
|
||||
describe('PanelModelCompatibilityWrapper', () => {
|
||||
it('Can get legacy id', () => {
|
||||
const vizPanel = new VizPanel({ pluginId: 'test', title: 'test', description: 'test', key: 'panel-24' });
|
||||
const panelModel = new PanelModelCompatibilityWrapper(vizPanel);
|
||||
expect(panelModel.id).toBe(24);
|
||||
});
|
||||
|
||||
it('Can get legacy id for lib panel', () => {
|
||||
const libPanel = new LibraryVizPanel({
|
||||
uid: 'a',
|
||||
name: 'aa',
|
||||
title: 'a',
|
||||
panelKey: 'panel-24',
|
||||
panel: new VizPanel({ pluginId: 'test', title: 'test', description: 'test', key: 'panel-24' }),
|
||||
});
|
||||
|
||||
const panelModel = new PanelModelCompatibilityWrapper(libPanel.state.panel!);
|
||||
expect(panelModel.id).toBe(24);
|
||||
});
|
||||
});
|
@ -2,17 +2,13 @@ import { PanelModel } from '@grafana/data';
|
||||
import { SceneDataTransformer, VizPanel } from '@grafana/scenes';
|
||||
import { DataSourceRef, DataTransformerConfig } from '@grafana/schema';
|
||||
|
||||
import { LibraryVizPanel } from '../scene/LibraryVizPanel';
|
||||
|
||||
import { getPanelIdForVizPanel, getQueryRunnerFor } from './utils';
|
||||
|
||||
export class PanelModelCompatibilityWrapper implements PanelModel {
|
||||
constructor(private _vizPanel: VizPanel) {}
|
||||
|
||||
public get id() {
|
||||
const id = getPanelIdForVizPanel(
|
||||
this._vizPanel.parent instanceof LibraryVizPanel ? this._vizPanel.parent : this._vizPanel
|
||||
);
|
||||
const id = getPanelIdForVizPanel(this._vizPanel);
|
||||
|
||||
if (isNaN(id)) {
|
||||
console.error('VizPanel key could not be translated to a legacy numeric panel id', this._vizPanel);
|
||||
|
Loading…
Reference in New Issue
Block a user