Przeglądaj źródła

wip: panel-header: Add "Duplicate"

Johannes Schill 7 lat temu
rodzic
commit
b296d724e5

+ 9 - 2
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<PanelHeaderMenuProps, any> {
     });
   };
 
+  onDuplicatePanel = () => {
+    const { dashboard } = this.props;
+    const panel = this.getPanel();
+
+    duplicatePanel(dashboard, panel);
+  };
+
   render() {
     return (
       <div className="panel-menu-container dropdown">
@@ -98,7 +105,7 @@ export class PanelHeaderMenu extends PureComponent<PanelHeaderMenuProps, any> {
                 type={PanelHeaderMenuItemTypes.Link}
                 text="Duplicate"
                 iconClassName=""
-                handleClick={() => {}}
+                handleClick={this.onDuplicatePanel}
                 shortcut="p d"
               />
               <PanelHeaderMenuItem type={PanelHeaderMenuItemTypes.Link} text="Copy" handleClick={() => {}} />

+ 5 - 0
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,
 };

+ 2 - 1
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() {