From edceb204e7a552b1ebd82149b76b78de96474cec Mon Sep 17 00:00:00 2001 From: Johannes Schill Date: Tue, 30 Oct 2018 14:53:04 +0100 Subject: [PATCH] wip: panel-header: Add "Copy" functionality --- .../dashgrid/PanelHeader/PanelHeaderMenu.tsx | 11 ++++++++--- public/app/features/dashboard/utils/panel.ts | 8 ++++++++ public/app/features/panel/panel_ctrl.ts | 10 ++++------ 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/public/app/features/dashboard/dashgrid/PanelHeader/PanelHeaderMenu.tsx b/public/app/features/dashboard/dashgrid/PanelHeader/PanelHeaderMenu.tsx index 49adfbb703a..190c13ead9d 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, duplicatePanel } from 'app/features/dashboard/utils/panel'; +import { removePanel, duplicatePanel, copyPanel } from 'app/features/dashboard/utils/panel'; import appEvents from 'app/core/app_events'; export interface PanelHeaderMenuProps { @@ -69,6 +69,11 @@ export class PanelHeaderMenu extends PureComponent { duplicatePanel(dashboard, panel); }; + onCopyPanel = () => { + const panel = this.getPanel(); + copyPanel(panel); + }; + render() { return (
@@ -98,7 +103,7 @@ export class PanelHeaderMenu extends PureComponent { type={PanelHeaderMenuItemTypes.SubMenu} text="More ..." iconClassName="fa fa-fw fa-cube" - handleClick={() => {}} + handleClick={null} >
    { handleClick={this.onDuplicatePanel} shortcut="p d" /> - {}} /> + {}} /> {}} /> { // confirm deletion @@ -26,7 +28,13 @@ export const duplicatePanel = (dashboard: DashboardModel, panel: PanelModel) => dashboard.duplicatePanel(panel); }; +export const copyPanel = (panel: PanelModel) => { + store.set(LS_PANEL_COPY_KEY, JSON.stringify(panel.getSaveModel())); + appEvents.emit('alert-success', ['Panel copied. Open Add Panel to paste']); +}; + export default { removePanel, duplicatePanel, + copyPanel, }; diff --git a/public/app/features/panel/panel_ctrl.ts b/public/app/features/panel/panel_ctrl.ts index d1e2dcc20cf..cb35b5ef470 100644 --- a/public/app/features/panel/panel_ctrl.ts +++ b/public/app/features/panel/panel_ctrl.ts @@ -1,12 +1,11 @@ import config from 'app/core/config'; import _ from 'lodash'; import $ from 'jquery'; -import { appEvents, profiler } from 'app/core/core'; +import { profiler } from 'app/core/core'; import { PanelModel } from 'app/features/dashboard/panel_model'; -import { duplicatePanel } from 'app/features/dashboard/utils/panel'; +import { duplicatePanel, copyPanel } 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'; +import { GRID_CELL_HEIGHT, GRID_CELL_VMARGIN } from 'app/core/constants'; const TITLE_HEIGHT = 27; const PANEL_BORDER = 2; @@ -264,8 +263,7 @@ export class PanelCtrl { } copyPanel() { - store.set(LS_PANEL_COPY_KEY, JSON.stringify(this.panel.getSaveModel())); - appEvents.emit('alert-success', ['Panel copied. Open Add Panel to paste']); + copyPanel(this.panel); } replacePanel(newPanel, oldPanel) {