From 820e47b4c0519f5bf1b8b926bef288080f7c0400 Mon Sep 17 00:00:00 2001 From: Johannes Schill Date: Thu, 25 Oct 2018 13:58:26 +0200 Subject: [PATCH] wip: panel-header: Remove panel --- .../dashgrid/PanelHeader/PanelHeader.tsx | 3 +- .../dashgrid/PanelHeader/PanelHeaderMenu.tsx | 32 +++++++++++++++++-- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/public/app/features/dashboard/dashgrid/PanelHeader/PanelHeader.tsx b/public/app/features/dashboard/dashgrid/PanelHeader/PanelHeader.tsx index a5e30d9396e..ae04f0f0405 100644 --- a/public/app/features/dashboard/dashgrid/PanelHeader/PanelHeader.tsx +++ b/public/app/features/dashboard/dashgrid/PanelHeader/PanelHeader.tsx @@ -14,6 +14,7 @@ interface PanelHeaderProps { export class PanelHeader extends React.Component { render() { + const { dashboard } = this.props; const isFullscreen = false; const isLoading = false; const panelHeaderClass = classNames({ 'panel-header': true, 'grid-drag-handle': !isFullscreen }); @@ -38,7 +39,7 @@ export class PanelHeader extends React.Component { {this.props.panel.title} - + 4m diff --git a/public/app/features/dashboard/dashgrid/PanelHeader/PanelHeaderMenu.tsx b/public/app/features/dashboard/dashgrid/PanelHeader/PanelHeaderMenu.tsx index 6bc6bb54509..19fee872e4b 100644 --- a/public/app/features/dashboard/dashgrid/PanelHeader/PanelHeaderMenu.tsx +++ b/public/app/features/dashboard/dashgrid/PanelHeader/PanelHeaderMenu.tsx @@ -1,5 +1,7 @@ import React, { PureComponent } from 'react'; // import { store } from 'app/store/configureStore'; +import { DashboardModel } from 'app/features/dashboard/dashboard_model'; +import { PanelModel } from 'app/features/dashboard/panel_model'; import { PanelHeaderMenuItem, PanelHeaderMenuItemTypes } from './PanelHeaderMenuItem'; import appEvents from 'app/core/app_events'; import { store } from 'app/store/configureStore'; @@ -7,6 +9,7 @@ import { updateLocation } from 'app/core/actions'; export interface PanelHeaderMenuProps { panelId: number; + dashboard: DashboardModel; } export class PanelHeaderMenu extends PureComponent { @@ -35,9 +38,32 @@ export class PanelHeaderMenu extends PureComponent { }; onRemovePanel = () => { - appEvents.emit('panel-remove', { - panelId: this.props.panelId, - }); + const { panelId, dashboard } = this.props; + const panelInfo = dashboard.getPanelInfoById(panelId); + this.removePanel(panelInfo.panel, true); + }; + + removePanel = (panel: PanelModel, ask: boolean) => { + const { dashboard } = this.props; + + // confirm deletion + if (ask !== false) { + const text2 = panel.alert ? 'Panel includes an alert rule, removing panel will also remove alert rule' : null; + const confirmText = panel.alert ? 'YES' : null; + + appEvents.emit('confirm-modal', { + title: 'Remove Panel', + text: 'Are you sure you want to remove this panel?', + text2: text2, + icon: 'fa-trash', + confirmText: confirmText, + yesText: 'Remove', + onConfirm: () => this.removePanel(panel, false), + }); + return; + } + + dashboard.removePanel(panel); }; render() {