From abac53bd0a8df19626524e319e6ebf3091bb56c6 Mon Sep 17 00:00:00 2001 From: Ivan Ortega Alba Date: Tue, 28 Jan 2025 17:53:19 +0100 Subject: [PATCH] Revert "Revert "LibraryPanel: Fallback to panel title if library panel title is not set"" (#99678) 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. --- .../dashboard-scene/inspect/InspectJsonTab.test.tsx | 2 +- .../dashboard-scene/panel-edit/PanelEditor.test.ts | 4 +--- .../dashboard-scene/panel-edit/PanelOptions.test.tsx | 1 - .../scene/AddLibraryPanelDrawer.test.tsx | 2 +- .../scene/DashboardDatasourceBehaviour.test.tsx | 3 --- .../dashboard-scene/scene/DashboardScene.test.tsx | 10 +++++----- .../scene/LibraryPanelBehavior.test.tsx | 2 +- .../dashboard-scene/scene/LibraryPanelBehavior.tsx | 6 ++---- .../serialization/transformSceneToSaveModel.test.ts | 6 ++---- .../serialization/transformSceneToSaveModel.ts | 2 +- .../utils/PanelModelCompatibilityWrapper.test.ts | 1 - 11 files changed, 14 insertions(+), 25 deletions(-) diff --git a/public/app/features/dashboard-scene/inspect/InspectJsonTab.test.tsx b/public/app/features/dashboard-scene/inspect/InspectJsonTab.test.tsx index 7d93518167e..582e0855008 100644 --- a/public/app/features/dashboard-scene/inspect/InspectJsonTab.test.tsx +++ b/public/app/features/dashboard-scene/inspect/InspectJsonTab.test.tsx @@ -223,7 +223,7 @@ async function buildTestSceneWithLibraryPanel() { title: 'Panel A', pluginId: 'table', key: 'panel-12', - $behaviors: [new LibraryPanelBehavior({ title: 'LibraryPanel A title', name: 'LibraryPanel A', uid: '111' })], + $behaviors: [new LibraryPanelBehavior({ name: 'LibraryPanel A', uid: '111' })], titleItems: [new VizPanelLinks({ menu: new VizPanelLinksMenu({}) })], $data: new SceneDataTransformer({ transformations: [ diff --git a/public/app/features/dashboard-scene/panel-edit/PanelEditor.test.ts b/public/app/features/dashboard-scene/panel-edit/PanelEditor.test.ts index fa309c8bd21..f204eae7138 100644 --- a/public/app/features/dashboard-scene/panel-edit/PanelEditor.test.ts +++ b/public/app/features/dashboard-scene/panel-edit/PanelEditor.test.ts @@ -200,7 +200,6 @@ describe('PanelEditor', () => { const libPanelBehavior = new LibraryPanelBehavior({ isLoaded: true, - title: libraryPanelModel.title, uid: libraryPanelModel.uid, name: libraryPanelModel.name, _loadedPanel: libraryPanelModel, @@ -239,7 +238,7 @@ describe('PanelEditor', () => { // Wait for mock api to return and update the library panel expect(libPanelBehavior.state._loadedPanel?.version).toBe(2); expect(libPanelBehavior.state.name).toBe('changed name'); - expect(libPanelBehavior.state.title).toBe('changed title'); + expect(panel.state.title).toBe('changed title'); expect((gridItem.state.body as VizPanel).state.title).toBe('changed title'); }); @@ -258,7 +257,6 @@ describe('PanelEditor', () => { const libPanelBehavior = new LibraryPanelBehavior({ isLoaded: true, - title: libraryPanelModel.title, uid: libraryPanelModel.uid, name: libraryPanelModel.name, _loadedPanel: libraryPanelModel, diff --git a/public/app/features/dashboard-scene/panel-edit/PanelOptions.test.tsx b/public/app/features/dashboard-scene/panel-edit/PanelOptions.test.tsx index 264c053de17..3f54a519b70 100644 --- a/public/app/features/dashboard-scene/panel-edit/PanelOptions.test.tsx +++ b/public/app/features/dashboard-scene/panel-edit/PanelOptions.test.tsx @@ -177,7 +177,6 @@ describe('PanelOptions', () => { const libraryPanel = new LibraryPanelBehavior({ isLoaded: true, - title: libraryPanelModel.title, uid: libraryPanelModel.uid, name: libraryPanelModel.name, _loadedPanel: libraryPanelModel, diff --git a/public/app/features/dashboard-scene/scene/AddLibraryPanelDrawer.test.tsx b/public/app/features/dashboard-scene/scene/AddLibraryPanelDrawer.test.tsx index f298e7b19f9..e8a0054a731 100644 --- a/public/app/features/dashboard-scene/scene/AddLibraryPanelDrawer.test.tsx +++ b/public/app/features/dashboard-scene/scene/AddLibraryPanelDrawer.test.tsx @@ -96,7 +96,7 @@ describe('AddLibraryPanelWidget', () => { title: 'Panel Title', pluginId: 'table', key: 'panel-1', - $behaviors: [new LibraryPanelBehavior({ title: 'LibraryPanel A title', name: 'LibraryPanel A', uid: 'uid' })], + $behaviors: [new LibraryPanelBehavior({ name: 'LibraryPanel A', uid: 'uid' })], }); addLibPanelDrawer = new AddLibraryPanelDrawer({ panelToReplaceRef: libPanel.getRef() }); diff --git a/public/app/features/dashboard-scene/scene/DashboardDatasourceBehaviour.test.tsx b/public/app/features/dashboard-scene/scene/DashboardDatasourceBehaviour.test.tsx index 393f3cfaea7..1b183577b1f 100644 --- a/public/app/features/dashboard-scene/scene/DashboardDatasourceBehaviour.test.tsx +++ b/public/app/features/dashboard-scene/scene/DashboardDatasourceBehaviour.test.tsx @@ -408,7 +408,6 @@ describe('DashboardDatasourceBehaviour', () => { it('should re-run queries when library panel re-runs query', async () => { const libPanelBehavior = new LibraryPanelBehavior({ isLoaded: false, - title: 'Panel title', uid: 'fdcvggvfy2qdca', name: 'My Library Panel', _loadedPanel: undefined, @@ -469,7 +468,6 @@ describe('DashboardDatasourceBehaviour', () => { jest.spyOn(console, 'error').mockImplementation(); const libPanelBehavior = new LibraryPanelBehavior({ isLoaded: false, - title: 'Panel title', uid: 'fdcvggvfy2qdca', name: 'My Library Panel', _loadedPanel: undefined, @@ -519,7 +517,6 @@ describe('DashboardDatasourceBehaviour', () => { // Simulate library panel being loaded libPanelBehavior.setState({ isLoaded: true, - title: 'Panel title', uid: 'fdcvggvfy2qdca', name: 'My Library Panel', _loadedPanel: undefined, diff --git a/public/app/features/dashboard-scene/scene/DashboardScene.test.tsx b/public/app/features/dashboard-scene/scene/DashboardScene.test.tsx index 2c54e174bea..80d4b19fa3a 100644 --- a/public/app/features/dashboard-scene/scene/DashboardScene.test.tsx +++ b/public/app/features/dashboard-scene/scene/DashboardScene.test.tsx @@ -468,7 +468,7 @@ describe('DashboardScene', () => { title: 'Library Panel', pluginId: 'table', key: 'panel-4', - $behaviors: [new LibraryPanelBehavior({ title: 'Library Panel', name: 'libraryPanel', uid: 'uid' })], + $behaviors: [new LibraryPanelBehavior({ name: 'libraryPanel', uid: 'uid' })], }); scene.copyPanel(libVizPanel); @@ -523,7 +523,7 @@ describe('DashboardScene', () => { title: 'Library Panel', pluginId: 'table', key: 'panel-4', - $behaviors: [new LibraryPanelBehavior({ title: 'Library Panel', name: 'libraryPanel', uid: 'uid' })], + $behaviors: [new LibraryPanelBehavior({ name: 'libraryPanel', uid: 'uid' })], }), }) ); @@ -542,7 +542,7 @@ describe('DashboardScene', () => { const libPanel = new VizPanel({ title: 'Panel B', pluginId: 'table', - $behaviors: [new LibraryPanelBehavior({ title: 'title', name: 'lib panel', uid: 'abc', isLoaded: true })], + $behaviors: [new LibraryPanelBehavior({ name: 'lib panel', uid: 'abc', isLoaded: true })], }); const scene = buildTestScene({ @@ -907,7 +907,7 @@ function buildTestScene(overrides?: Partial) { title: 'Library Panel', pluginId: 'table', key: 'panel-5', - $behaviors: [new LibraryPanelBehavior({ title: 'Library Panel', name: 'libraryPanel', uid: 'uid' })], + $behaviors: [new LibraryPanelBehavior({ name: 'libraryPanel', uid: 'uid' })], }), }), ], @@ -925,7 +925,7 @@ function buildTestScene(overrides?: Partial) { title: 'Library Panel', pluginId: 'table', key: 'panel-6', - $behaviors: [new LibraryPanelBehavior({ title: 'Library Panel', name: 'libraryPanel', uid: 'uid' })], + $behaviors: [new LibraryPanelBehavior({ name: 'libraryPanel', uid: 'uid' })], }), }), ], diff --git a/public/app/features/dashboard-scene/scene/LibraryPanelBehavior.test.tsx b/public/app/features/dashboard-scene/scene/LibraryPanelBehavior.test.tsx index 02a363d5d3a..b6eb6872566 100644 --- a/public/app/features/dashboard-scene/scene/LibraryPanelBehavior.test.tsx +++ b/public/app/features/dashboard-scene/scene/LibraryPanelBehavior.test.tsx @@ -167,7 +167,7 @@ describe('LibraryPanelBehavior', () => { }); async function buildTestSceneWithLibraryPanel() { - const behavior = new LibraryPanelBehavior({ title: 'LibraryPanel A title', name: 'LibraryPanel A', uid: '111' }); + const behavior = new LibraryPanelBehavior({ name: 'LibraryPanel A', uid: '111' }); const vizPanel = new VizPanel({ title: 'Panel A', diff --git a/public/app/features/dashboard-scene/scene/LibraryPanelBehavior.tsx b/public/app/features/dashboard-scene/scene/LibraryPanelBehavior.tsx index 423cc2c34ee..44a1c0de5a8 100644 --- a/public/app/features/dashboard-scene/scene/LibraryPanelBehavior.tsx +++ b/public/app/features/dashboard-scene/scene/LibraryPanelBehavior.tsx @@ -17,8 +17,6 @@ import { AngularDeprecation } from './angular/AngularDeprecation'; import { DashboardGridItem } from './layout-default/DashboardGridItem'; export interface LibraryPanelBehaviorState extends SceneObjectState { - // Library panels use title from dashboard JSON's panel model, not from library panel definition, hence we pass it. - title?: string; uid: string; name: string; isLoaded?: boolean; @@ -66,7 +64,7 @@ export class LibraryPanelBehavior extends SceneObjectBase { $behaviors: [ new LibraryPanelBehavior({ name: 'Some lib panel panel', - title: 'A panel', uid: 'lib-panel-uid', }), ], @@ -399,7 +398,7 @@ describe('transformSceneToSaveModel', () => { x: 0, y: 0, }); - expect(result.title).toBe('A panel'); + expect(result.title).toBe('Panel blahh blah'); expect(result.transformations).toBeUndefined(); expect(result.fieldConfig).toBeUndefined(); expect(result.options).toBeUndefined(); @@ -851,7 +850,6 @@ describe('transformSceneToSaveModel', () => { $behaviors: [ new LibraryPanelBehavior({ name: 'Some lib panel panel', - title: 'A panel', uid: 'lib-panel-uid', }), ], @@ -865,7 +863,7 @@ describe('transformSceneToSaveModel', () => { expect(result[0]).toMatchObject({ id: 4, - title: 'A panel', + title: 'Panel blahh blah', libraryPanel: { name: 'Some lib panel panel', uid: 'lib-panel-uid', diff --git a/public/app/features/dashboard-scene/serialization/transformSceneToSaveModel.ts b/public/app/features/dashboard-scene/serialization/transformSceneToSaveModel.ts index 4c8368fc1fd..c1b6c96ec07 100644 --- a/public/app/features/dashboard-scene/serialization/transformSceneToSaveModel.ts +++ b/public/app/features/dashboard-scene/serialization/transformSceneToSaveModel.ts @@ -188,7 +188,7 @@ export function vizPanelToPanel( panel = { id: getPanelIdForVizPanel(vizPanel), - title: libPanel!.state.title, + title: vizPanel.state.title, gridPos: gridPos, libraryPanel: { name: libPanel!.state.name, diff --git a/public/app/features/dashboard-scene/utils/PanelModelCompatibilityWrapper.test.ts b/public/app/features/dashboard-scene/utils/PanelModelCompatibilityWrapper.test.ts index e6e44c7a583..02dcc897936 100644 --- a/public/app/features/dashboard-scene/utils/PanelModelCompatibilityWrapper.test.ts +++ b/public/app/features/dashboard-scene/utils/PanelModelCompatibilityWrapper.test.ts @@ -17,7 +17,6 @@ describe('PanelModelCompatibilityWrapper', () => { const libPanel = new LibraryPanelBehavior({ uid: 'a', name: 'aa', - title: 'a', }); panel.setState({