Skip to content

Commit

Permalink
[v11.0.x] DashboardScene: Fixes issue referring to library panel in d…
Browse files Browse the repository at this point in the history
…ashboard data source (#87173)

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

(cherry picked from commit 4034a26)

Co-authored-by: Torkel Ödegaard <torkel@grafana.com>
  • Loading branch information
grafana-delivery-bot[bot] and torkelo committed May 1, 2024
1 parent a8cd6d9 commit 7c1cc61
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 7c1cc61

Please sign in to comment.