Просмотр исходного кода

wip: panel-header: Add possibility to add custom actions to the menu by passing them in as props

Johannes Schill 7 лет назад
Родитель
Сommit
443d381dd9
1 измененных файлов с 13 добавлено и 1 удалено
  1. 13 1
      public/app/features/dashboard/utils/panel_menu.ts

+ 13 - 1
public/app/features/dashboard/utils/panel_menu.ts

@@ -5,7 +5,12 @@ import { PanelModel } from 'app/features/dashboard/panel_model';
 import { DashboardModel } from 'app/features/dashboard/dashboard_model';
 import { removePanel, duplicatePanel, copyPanel, editPanelJson, sharePanel } from 'app/features/dashboard/utils/panel';
 
-export const getPanelMenu = (dashboard: DashboardModel, panel: PanelModel) => {
+export const getPanelMenu = (
+  dashboard: DashboardModel,
+  panel: PanelModel,
+  extraMenuItems: PanelHeaderMenuItemProps[] = [],
+  extraSubMenuItems: PanelHeaderMenuItemProps[] = []
+) => {
   const onViewPanel = () => {
     store.dispatch(
       updateLocation({
@@ -77,6 +82,9 @@ export const getPanelMenu = (dashboard: DashboardModel, panel: PanelModel) => {
 
     // TODO: Handle this somehow
     // this.events.emit('init-panel-actions', menu);
+    extraSubMenuItems.forEach(item => {
+      menu.push(item);
+    });
     return menu;
   };
 
@@ -109,6 +117,10 @@ export const getPanelMenu = (dashboard: DashboardModel, panel: PanelModel) => {
     shortcut: 'p s',
   });
 
+  extraMenuItems.forEach(item => {
+    menu.push(item);
+  });
+
   const subMenu: PanelHeaderMenuItemProps[] = getSubMenu();
 
   menu.push({