From e725f865dcd537cb44cf50603689732c576df9f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Wed, 2 Apr 2025 15:42:11 +0200 Subject: [PATCH] DashboardScene: Add library panel via canvas add panel action (#103254) * Update * It works now for auto grid as well --- .../edit-pane/VizPanelEditableElement.tsx | 2 +- .../scene/AddLibraryPanelDrawer.tsx | 10 ++-- .../scene/UnconfiguredPanel.tsx | 57 +++++++++++++++++-- .../layout-default/DashboardGridItem.tsx | 4 ++ .../ResponsiveGridItem.tsx | 4 ++ .../scene/types/DashboardLayoutItem.ts | 7 ++- public/locales/en-US/grafana.json | 4 +- 7 files changed, 74 insertions(+), 14 deletions(-) diff --git a/public/app/features/dashboard-scene/edit-pane/VizPanelEditableElement.tsx b/public/app/features/dashboard-scene/edit-pane/VizPanelEditableElement.tsx index 0f88658da85..f608297ed96 100644 --- a/public/app/features/dashboard-scene/edit-pane/VizPanelEditableElement.tsx +++ b/public/app/features/dashboard-scene/edit-pane/VizPanelEditableElement.tsx @@ -120,7 +120,7 @@ const OpenPanelEditViz = ({ panel }: OpenPanelEditVizProps) => { size="sm" tooltip={t('dashboard.viz-panel.options.configure-button-tooltip', 'Edit queries and visualization options')} > - Configure panel + Configure ); diff --git a/public/app/features/dashboard-scene/scene/AddLibraryPanelDrawer.tsx b/public/app/features/dashboard-scene/scene/AddLibraryPanelDrawer.tsx index 1d4c4b198a5..e92b570b7be 100644 --- a/public/app/features/dashboard-scene/scene/AddLibraryPanelDrawer.tsx +++ b/public/app/features/dashboard-scene/scene/AddLibraryPanelDrawer.tsx @@ -10,7 +10,7 @@ import { import { getDashboardSceneFor, getDefaultVizPanel } from '../utils/utils'; import { LibraryPanelBehavior } from './LibraryPanelBehavior'; -import { DashboardGridItem } from './layout-default/DashboardGridItem'; +import { isDashboardLayoutItem } from './types/DashboardLayoutItem'; export interface AddLibraryPanelDrawerState extends SceneObjectState { panelToReplaceRef?: SceneObjectRef; @@ -35,13 +35,11 @@ export class AddLibraryPanelDrawer extends SceneObjectBase { + setIsOpen(isOpen); + }, []); + const onConfigure = () => { locationService.partial({ editPanel: props.id }); }; + const onUseLibraryPanel = () => { + const dashboard = window.__grafanaSceneContext; + + if (!(dashboard instanceof DashboardScene)) { + throw new Error('DashboardScene not found'); + } + + const panel = findVizPanelByKey(dashboard, getVizPanelKeyForPanelId(props.id)); + if (!panel) { + throw new Error('Panel not found'); + } + + dashboard.onShowAddLibraryPanelDrawer(panel.getRef()); + }; + + const MenuActions = () => ( + + + + + ); + return ( - + + + +