From b296d724e5179e9b92a67c0b4d377a35b3235997 Mon Sep 17 00:00:00 2001 From: Johannes Schill Date: Tue, 30 Oct 2018 14:38:18 +0100 Subject: [PATCH] wip: panel-header: Add "Duplicate" --- .../dashgrid/PanelHeader/PanelHeaderMenu.tsx | 11 +++++++++-- public/app/features/dashboard/utils/panel.ts | 5 +++++ public/app/features/panel/panel_ctrl.ts | 3 ++- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/public/app/features/dashboard/dashgrid/PanelHeader/PanelHeaderMenu.tsx b/public/app/features/dashboard/dashgrid/PanelHeader/PanelHeaderMenu.tsx index 5e6f5a5d28c..49adfbb703a 100644 --- a/public/app/features/dashboard/dashgrid/PanelHeader/PanelHeaderMenu.tsx +++ b/public/app/features/dashboard/dashgrid/PanelHeader/PanelHeaderMenu.tsx @@ -3,7 +3,7 @@ import { DashboardModel } from 'app/features/dashboard/dashboard_model'; import { PanelHeaderMenuItem, PanelHeaderMenuItemTypes } from './PanelHeaderMenuItem'; import { store } from 'app/store/configureStore'; import { updateLocation } from 'app/core/actions'; -import { removePanel } from 'app/features/dashboard/utils/panel'; +import { removePanel, duplicatePanel } from 'app/features/dashboard/utils/panel'; import appEvents from 'app/core/app_events'; export interface PanelHeaderMenuProps { @@ -62,6 +62,13 @@ export class PanelHeaderMenu extends PureComponent { }); }; + onDuplicatePanel = () => { + const { dashboard } = this.props; + const panel = this.getPanel(); + + duplicatePanel(dashboard, panel); + }; + render() { return (
@@ -98,7 +105,7 @@ export class PanelHeaderMenu extends PureComponent { type={PanelHeaderMenuItemTypes.Link} text="Duplicate" iconClassName="" - handleClick={() => {}} + handleClick={this.onDuplicatePanel} shortcut="p d" /> {}} /> diff --git a/public/app/features/dashboard/utils/panel.ts b/public/app/features/dashboard/utils/panel.ts index 6257aae232e..35ccfdf3b3f 100644 --- a/public/app/features/dashboard/utils/panel.ts +++ b/public/app/features/dashboard/utils/panel.ts @@ -22,6 +22,11 @@ export const removePanel = (dashboard: DashboardModel, panel: PanelModel, ask: b dashboard.removePanel(panel); }; +export const duplicatePanel = (dashboard: DashboardModel, panel: PanelModel) => { + dashboard.duplicatePanel(panel); +}; + export default { removePanel, + duplicatePanel, }; diff --git a/public/app/features/panel/panel_ctrl.ts b/public/app/features/panel/panel_ctrl.ts index 08605132e82..d1e2dcc20cf 100644 --- a/public/app/features/panel/panel_ctrl.ts +++ b/public/app/features/panel/panel_ctrl.ts @@ -3,6 +3,7 @@ import _ from 'lodash'; import $ from 'jquery'; import { appEvents, profiler } from 'app/core/core'; import { PanelModel } from 'app/features/dashboard/panel_model'; +import { duplicatePanel } from 'app/features/dashboard/utils/panel'; import Remarkable from 'remarkable'; import { GRID_CELL_HEIGHT, GRID_CELL_VMARGIN, LS_PANEL_COPY_KEY } from 'app/core/constants'; import store from 'app/core/store'; @@ -241,7 +242,7 @@ export class PanelCtrl { } duplicate() { - this.dashboard.duplicatePanel(this.panel); + duplicatePanel(this.dashboard, this.panel); } removePanel() {