From 4671b7d5ae97e8897935b5305ee6b7deb54cd4b3 Mon Sep 17 00:00:00 2001 From: kay delaney <45561153+kaydelaney@users.noreply.github.com> Date: Thu, 4 Jul 2024 11:07:15 +0100 Subject: [PATCH] Scenes: Fix issue where "get help" drawer was empty in panel edit mode (#89431) * Scenes: Fix issue where "get help" drawer was empty in panel edit mode --- .betterer.results | 3 ++- .../dashboard-scene/inspect/HelpWizard/utils.ts | 16 +++++++++++++++- public/app/features/library-panels/state/api.ts | 1 - 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/.betterer.results b/.betterer.results index f3a96284f7f..ff67f56f90c 100644 --- a/.betterer.results +++ b/.betterer.results @@ -2760,7 +2760,8 @@ exports[`better eslint`] = { [0, 0, 0, "No untranslated strings. Wrap text with ", "10"] ], "public/app/features/dashboard-scene/inspect/HelpWizard/utils.ts:5381": [ - [0, 0, 0, "Do not use any type assertions.", "0"] + [0, 0, 0, "Do not use any type assertions.", "0"], + [0, 0, 0, "Do not use any type assertions.", "1"] ], "public/app/features/dashboard-scene/inspect/InspectDataTab.tsx:5381": [ [0, 0, 0, "No untranslated strings. Wrap text with ", "0"] diff --git a/public/app/features/dashboard-scene/inspect/HelpWizard/utils.ts b/public/app/features/dashboard-scene/inspect/HelpWizard/utils.ts index b49c7663770..b4ad0c41b37 100644 --- a/public/app/features/dashboard-scene/inspect/HelpWizard/utils.ts +++ b/public/app/features/dashboard-scene/inspect/HelpWizard/utils.ts @@ -15,6 +15,7 @@ import { VizPanel } from '@grafana/scenes'; import { GrafanaQueryType } from 'app/plugins/datasource/grafana/types'; import { DashboardGridItem } from '../../scene/DashboardGridItem'; +import { DashboardScene } from '../../scene/DashboardScene'; import { LibraryVizPanel } from '../../scene/LibraryVizPanel'; import { gridItemToPanel, vizPanelToPanel } from '../../serialization/transformSceneToSaveModel'; import { getQueryRunnerFor } from '../../utils/utils'; @@ -62,15 +63,28 @@ export function getGithubMarkdown(panel: VizPanel, snapshot: string): string { } export async function getDebugDashboard(panel: VizPanel, rand: Randomize, timeRange: TimeRange) { - let saveModel; + let saveModel: ReturnType = { type: '' }; const isLibraryPanel = panel.parent instanceof LibraryVizPanel; const gridItem = (isLibraryPanel ? panel.parent.parent : panel.parent) as DashboardGridItem; + const scene = panel.getRoot() as DashboardScene; if (isLibraryPanel) { saveModel = { ...gridItemToPanel(gridItem), ...vizPanelToPanel(panel), }; + } else if (scene.state.editPanel) { + // If panel edit mode is open when the user chooses the "get help" panel menu option + // we want the debug dashboard to include the panel with any changes that were made while + // in panel edit mode. + const sourcePanel = scene.state.editPanel.state.vizManager.state.sourcePanel.resolve(); + const dashGridItem = sourcePanel.parent instanceof LibraryVizPanel ? sourcePanel.parent.parent : sourcePanel.parent; + if (dashGridItem instanceof DashboardGridItem) { + saveModel = { + ...gridItemToPanel(dashGridItem), + ...vizPanelToPanel(scene.state.editPanel.state.vizManager.state.panel.clone()), + }; + } } else { saveModel = gridItemToPanel(gridItem); } diff --git a/public/app/features/library-panels/state/api.ts b/public/app/features/library-panels/state/api.ts index d5611d98307..ce5faba1f2c 100644 --- a/public/app/features/library-panels/state/api.ts +++ b/public/app/features/library-panels/state/api.ts @@ -170,7 +170,6 @@ export function libraryVizPanelToSaveModel(libraryPanel: LibraryVizPanel) { export async function updateLibraryVizPanel(libraryPanel: LibraryVizPanel): Promise { const { uid, folderUID, name, model, version, kind } = libraryVizPanelToSaveModel(libraryPanel); - console.log('updateLibraryVizPanel', model); const { result } = await getBackendSrv().patch(`/api/library-elements/${uid}`, { folderUID, name,