From 4034a269725e459286c8adc29d0c4291154b5f31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Wed, 1 May 2024 14:30:54 +0200 Subject: [PATCH] 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 --- .../scene/DashboardDatasourceBehaviour.tsx | 2 +- .../PanelModelCompatibilityWrapper.test.ts | 26 +++++++++++++++++++ .../utils/PanelModelCompatibilityWrapper.ts | 6 +---- 3 files changed, 28 insertions(+), 6 deletions(-) create mode 100644 public/app/features/dashboard-scene/utils/PanelModelCompatibilityWrapper.test.ts diff --git a/public/app/features/dashboard-scene/scene/DashboardDatasourceBehaviour.tsx b/public/app/features/dashboard-scene/scene/DashboardDatasourceBehaviour.tsx index 26fb6f0c8bc..f45d57f2742 100644 --- a/public/app/features/dashboard-scene/scene/DashboardDatasourceBehaviour.tsx +++ b/public/app/features/dashboard-scene/scene/DashboardDatasourceBehaviour.tsx @@ -53,7 +53,7 @@ export class DashboardDatasourceBehaviour extends SceneObjectBase { + 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); + }); +}); diff --git a/public/app/features/dashboard-scene/utils/PanelModelCompatibilityWrapper.ts b/public/app/features/dashboard-scene/utils/PanelModelCompatibilityWrapper.ts index a23b3081a51..820fc3b5134 100644 --- a/public/app/features/dashboard-scene/utils/PanelModelCompatibilityWrapper.ts +++ b/public/app/features/dashboard-scene/utils/PanelModelCompatibilityWrapper.ts @@ -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);