Commit edceb204 by Johannes Schill

wip: panel-header: Add "Copy" functionality

parent b296d724
...@@ -3,7 +3,7 @@ import { DashboardModel } from 'app/features/dashboard/dashboard_model'; ...@@ -3,7 +3,7 @@ import { DashboardModel } from 'app/features/dashboard/dashboard_model';
import { PanelHeaderMenuItem, PanelHeaderMenuItemTypes } from './PanelHeaderMenuItem'; import { PanelHeaderMenuItem, PanelHeaderMenuItemTypes } from './PanelHeaderMenuItem';
import { store } from 'app/store/configureStore'; import { store } from 'app/store/configureStore';
import { updateLocation } from 'app/core/actions'; 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'; import appEvents from 'app/core/app_events';
export interface PanelHeaderMenuProps { export interface PanelHeaderMenuProps {
...@@ -69,6 +69,11 @@ export class PanelHeaderMenu extends PureComponent<PanelHeaderMenuProps, any> { ...@@ -69,6 +69,11 @@ export class PanelHeaderMenu extends PureComponent<PanelHeaderMenuProps, any> {
duplicatePanel(dashboard, panel); duplicatePanel(dashboard, panel);
}; };
onCopyPanel = () => {
const panel = this.getPanel();
copyPanel(panel);
};
render() { render() {
return ( return (
<div className="panel-menu-container dropdown"> <div className="panel-menu-container dropdown">
...@@ -98,7 +103,7 @@ export class PanelHeaderMenu extends PureComponent<PanelHeaderMenuProps, any> { ...@@ -98,7 +103,7 @@ export class PanelHeaderMenu extends PureComponent<PanelHeaderMenuProps, any> {
type={PanelHeaderMenuItemTypes.SubMenu} type={PanelHeaderMenuItemTypes.SubMenu}
text="More ..." text="More ..."
iconClassName="fa fa-fw fa-cube" iconClassName="fa fa-fw fa-cube"
handleClick={() => {}} handleClick={null}
> >
<ul className="dropdown-menu dropdown-menu--menu panel-menu"> <ul className="dropdown-menu dropdown-menu--menu panel-menu">
<PanelHeaderMenuItem <PanelHeaderMenuItem
...@@ -108,7 +113,7 @@ export class PanelHeaderMenu extends PureComponent<PanelHeaderMenuProps, any> { ...@@ -108,7 +113,7 @@ export class PanelHeaderMenu extends PureComponent<PanelHeaderMenuProps, any> {
handleClick={this.onDuplicatePanel} handleClick={this.onDuplicatePanel}
shortcut="p d" shortcut="p d"
/> />
<PanelHeaderMenuItem type={PanelHeaderMenuItemTypes.Link} text="Copy" handleClick={() => {}} /> <PanelHeaderMenuItem type={PanelHeaderMenuItemTypes.Link} text="Copy" handleClick={this.onCopyPanel} />
<PanelHeaderMenuItem type={PanelHeaderMenuItemTypes.Link} text="Panel JSON" handleClick={() => {}} /> <PanelHeaderMenuItem type={PanelHeaderMenuItemTypes.Link} text="Panel JSON" handleClick={() => {}} />
<PanelHeaderMenuItem type={PanelHeaderMenuItemTypes.Link} text="Export CSV" handleClick={() => {}} /> <PanelHeaderMenuItem type={PanelHeaderMenuItemTypes.Link} text="Export CSV" handleClick={() => {}} />
<PanelHeaderMenuItem <PanelHeaderMenuItem
......
import appEvents from 'app/core/app_events'; import appEvents from 'app/core/app_events';
import { DashboardModel } from 'app/features/dashboard/dashboard_model'; import { DashboardModel } from 'app/features/dashboard/dashboard_model';
import { PanelModel } from 'app/features/dashboard/panel_model'; import { PanelModel } from 'app/features/dashboard/panel_model';
import store from 'app/core/store';
import { LS_PANEL_COPY_KEY } from 'app/core/constants';
export const removePanel = (dashboard: DashboardModel, panel: PanelModel, ask: boolean) => { export const removePanel = (dashboard: DashboardModel, panel: PanelModel, ask: boolean) => {
// confirm deletion // confirm deletion
...@@ -26,7 +28,13 @@ export const duplicatePanel = (dashboard: DashboardModel, panel: PanelModel) => ...@@ -26,7 +28,13 @@ export const duplicatePanel = (dashboard: DashboardModel, panel: PanelModel) =>
dashboard.duplicatePanel(panel); 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 { export default {
removePanel, removePanel,
duplicatePanel, duplicatePanel,
copyPanel,
}; };
import config from 'app/core/config'; import config from 'app/core/config';
import _ from 'lodash'; import _ from 'lodash';
import $ from 'jquery'; 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 { 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 Remarkable from 'remarkable';
import { GRID_CELL_HEIGHT, GRID_CELL_VMARGIN, LS_PANEL_COPY_KEY } from 'app/core/constants'; import { GRID_CELL_HEIGHT, GRID_CELL_VMARGIN } from 'app/core/constants';
import store from 'app/core/store';
const TITLE_HEIGHT = 27; const TITLE_HEIGHT = 27;
const PANEL_BORDER = 2; const PANEL_BORDER = 2;
...@@ -264,8 +263,7 @@ export class PanelCtrl { ...@@ -264,8 +263,7 @@ export class PanelCtrl {
} }
copyPanel() { copyPanel() {
store.set(LS_PANEL_COPY_KEY, JSON.stringify(this.panel.getSaveModel())); copyPanel(this.panel);
appEvents.emit('alert-success', ['Panel copied. Open Add Panel to paste']);
} }
replacePanel(newPanel, oldPanel) { replacePanel(newPanel, oldPanel) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment