From 92d5e82a334e046c3408c97a83fe668fd6d528dd Mon Sep 17 00:00:00 2001 From: Ivan Ortega Alba Date: Tue, 28 Jan 2025 18:19:33 +0100 Subject: [PATCH] LibraryPanels: Respect model title when adding a library panel (#99687) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Revert "Revert "LibraryPanel: Fallback to panel title if library panel title …" This reverts commit 6e705ee67c1286df82eb97d44f887f9d38258a74. * LibraryPanels: Respect model title when adding a library panel to a dashboard * remove debugger --------- Co-authored-by: Haris Rozajac --- .../scene/AddLibraryPanelDrawer.test.tsx | 29 ++++++++++++++++++- .../scene/AddLibraryPanelDrawer.tsx | 3 ++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/public/app/features/dashboard-scene/scene/AddLibraryPanelDrawer.test.tsx b/public/app/features/dashboard-scene/scene/AddLibraryPanelDrawer.test.tsx index e8a0054a731..cba0d0f9e01 100644 --- a/public/app/features/dashboard-scene/scene/AddLibraryPanelDrawer.test.tsx +++ b/public/app/features/dashboard-scene/scene/AddLibraryPanelDrawer.test.tsx @@ -32,6 +32,7 @@ describe('AddLibraryPanelWidget', () => { const panelInfo: LibraryPanel = { uid: 'uid', model: { + title: 'model title', type: 'timeseries', }, name: 'name', @@ -47,6 +48,8 @@ describe('AddLibraryPanelWidget', () => { expect(panels.length).toBe(1); expect(panel.state.$behaviors![0]).toBeInstanceOf(LibraryPanelBehavior); expect(panel.state.key).toBe('panel-1'); + expect(panel.state.title).toBe('model title'); + expect(panel.state.hoverHeader).toBe(false); }); it('should add library panel from menu and enter edit mode in a dashboard that is not already in edit mode', async () => { @@ -69,6 +72,7 @@ describe('AddLibraryPanelWidget', () => { const panelInfo: LibraryPanel = { uid: 'uid', model: { + title: 'model title', type: 'timeseries', }, name: 'name', @@ -88,12 +92,13 @@ describe('AddLibraryPanelWidget', () => { expect(panels.length).toBe(1); expect(panel.state.$behaviors![0]).toBeInstanceOf(LibraryPanelBehavior); expect(panel.state.key).toBe('panel-1'); + expect(panel.state.title).toBe('model title'); expect(dashboard.state.isEditing).toBe(true); }); it('should replace grid item when grid item state is passed', async () => { const libPanel = new VizPanel({ - title: 'Panel Title', + title: 'Some panel title', pluginId: 'table', key: 'panel-1', $behaviors: [new LibraryPanelBehavior({ name: 'LibraryPanel A', uid: 'uid' })], @@ -115,6 +120,7 @@ describe('AddLibraryPanelWidget', () => { const panelInfo: LibraryPanel = { uid: 'new_uid', model: { + title: 'model title', type: 'timeseries', }, name: 'new_name', @@ -132,6 +138,27 @@ describe('AddLibraryPanelWidget', () => { expect(behavior).toBeInstanceOf(LibraryPanelBehavior); expect(behavior.state.uid).toBe('new_uid'); expect(behavior.state.name).toBe('new_name'); + expect(panels[0].state.title).toBe('model title'); + }); + + it('should set hoverHeader to true if the library panel title is empty', () => { + const panelInfo: LibraryPanel = { + uid: 'uid', + model: { + title: '', + type: 'timeseries', + }, + name: 'name', + version: 1, + type: 'timeseries', + }; + + addLibPanelDrawer.onAddLibraryPanel(panelInfo); + + const panels = dashboard.state.body.getVizPanels(); + const panel = panels[0]; + expect(panel.state.title).toBe(''); + expect(panel.state.hoverHeader).toBe(true); }); }); diff --git a/public/app/features/dashboard-scene/scene/AddLibraryPanelDrawer.tsx b/public/app/features/dashboard-scene/scene/AddLibraryPanelDrawer.tsx index e8e462005eb..1d4c4b198a5 100644 --- a/public/app/features/dashboard-scene/scene/AddLibraryPanelDrawer.tsx +++ b/public/app/features/dashboard-scene/scene/AddLibraryPanelDrawer.tsx @@ -26,6 +26,9 @@ export class AddLibraryPanelDrawer extends SceneObjectBase