From a246a26a2f8e22490681ba6a7e28b1fe8f680b07 Mon Sep 17 00:00:00 2001 From: kay delaney <45561153+kaydelaney@users.noreply.github.com> Date: Mon, 18 Jan 2021 13:34:45 +0000 Subject: [PATCH] Dashboards: Exit to dashboard when deleting panel from panel view / edit view (#29032) * Dashboards: Exit to dashboard when deleting panel from panel view / edit view Closes #11941 * Remove ability to delete panel when viewing/editing --- public/app/core/services/keybindingSrv.ts | 2 +- .../app/features/dashboard/utils/getPanelMenu.test.ts | 10 ---------- public/app/features/dashboard/utils/getPanelMenu.ts | 2 +- public/app/features/dashboard/utils/panel.ts | 1 + 4 files changed, 3 insertions(+), 12 deletions(-) diff --git a/public/app/core/services/keybindingSrv.ts b/public/app/core/services/keybindingSrv.ts index 87f0daa29fb..56086599104 100644 --- a/public/app/core/services/keybindingSrv.ts +++ b/public/app/core/services/keybindingSrv.ts @@ -272,7 +272,7 @@ export class KeybindingSrv { this.bind('p r', () => { const panelId = dashboard.meta.focusPanelId; - if (panelId && dashboard.canEditPanelById(panelId)) { + if (panelId && dashboard.canEditPanelById(panelId) && !(dashboard.panelInView || dashboard.panelInEdit)) { appEvents.emit(CoreEvents.removePanel, panelId); dashboard.meta.focusPanelId = 0; } diff --git a/public/app/features/dashboard/utils/getPanelMenu.test.ts b/public/app/features/dashboard/utils/getPanelMenu.test.ts index 7ff92deba02..be663ee3160 100644 --- a/public/app/features/dashboard/utils/getPanelMenu.test.ts +++ b/public/app/features/dashboard/utils/getPanelMenu.test.ts @@ -151,16 +151,6 @@ describe('getPanelMenu', () => { "text": "More...", "type": "submenu", }, - Object { - "text": "", - "type": "divider", - }, - Object { - "iconClassName": "trash-alt", - "onClick": [Function], - "shortcut": "p r", - "text": "Remove", - }, ] `); }); diff --git a/public/app/features/dashboard/utils/getPanelMenu.ts b/public/app/features/dashboard/utils/getPanelMenu.ts index 3c8a8282ebc..b1b0f9fe275 100644 --- a/public/app/features/dashboard/utils/getPanelMenu.ts +++ b/public/app/features/dashboard/utils/getPanelMenu.ts @@ -197,7 +197,7 @@ export function getPanelMenu( }); } - if (dashboard.canEditPanel(panel) && !panel.isEditing) { + if (dashboard.canEditPanel(panel) && !panel.isEditing && !panel.isViewing) { menu.push({ type: 'divider', text: '' }); menu.push({ diff --git a/public/app/features/dashboard/utils/panel.ts b/public/app/features/dashboard/utils/panel.ts index 82364981d03..89f74f48859 100644 --- a/public/app/features/dashboard/utils/panel.ts +++ b/public/app/features/dashboard/utils/panel.ts @@ -39,6 +39,7 @@ export const removePanel = (dashboard: DashboardModel, panel: PanelModel, ask: b }); return; } + dashboard.removePanel(panel); };