Procházet zdrojové kódy

wip: panel-header: Refactor so "Share" use the same code in angular+react

Johannes Schill před 7 roky
rodič
revize
5375ce5ffd

+ 2 - 9
public/app/features/dashboard/dashgrid/PanelHeader/PanelHeaderMenu.tsx

@@ -3,8 +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, copyPanel, editPanelJson } from 'app/features/dashboard/utils/panel';
-import appEvents from 'app/core/app_events';
+import { removePanel, duplicatePanel, copyPanel, editPanelJson, sharePanel } from 'app/features/dashboard/utils/panel';
 
 export interface PanelHeaderMenuProps {
   panelId: number;
@@ -53,13 +52,7 @@ export class PanelHeaderMenu extends PureComponent<PanelHeaderMenuProps, any> {
     const { dashboard } = this.props;
     const panel = this.getPanel();
 
-    appEvents.emit('show-modal', {
-      src: 'public/app/features/dashboard/partials/shareModal.html',
-      model: {
-        panel: panel,
-        dashboard: dashboard,
-      },
-    });
+    sharePanel(dashboard, panel);
   };
 
   onDuplicatePanel = () => {

+ 2 - 0
public/app/features/dashboard/shareModalCtrl.ts

@@ -12,6 +12,8 @@ export function ShareModalCtrl($scope, $rootScope, $location, $timeout, timeSrv,
   $scope.editor = { index: $scope.tabIndex || 0 };
 
   $scope.init = () => {
+    $scope.panel = $scope.model.panel || $scope.panel; // React pass panel and dashboard in the "model" property
+    $scope.dashboard = $scope.model.dashboard || $scope.dashboard;
     $scope.modeSharePanel = $scope.panel ? true : false;
 
     $scope.tabs = [{ title: 'Link', src: 'shareLink.html' }];

+ 10 - 0
public/app/features/dashboard/utils/panel.ts

@@ -63,3 +63,13 @@ export const editPanelJson = (dashboard: DashboardModel, panel: PanelModel) => {
     model: model,
   });
 };
+
+export const sharePanel = (dashboard: DashboardModel, panel: PanelModel) => {
+  appEvents.emit('show-modal', {
+    src: 'public/app/features/dashboard/partials/shareModal.html',
+    model: {
+      dashboard: dashboard,
+      panel: panel,
+    },
+  });
+};

+ 2 - 8
public/app/features/panel/panel_ctrl.ts

@@ -6,6 +6,7 @@ import {
   duplicatePanel,
   copyPanel as copyPanelUtil,
   editPanelJson as editPanelJsonUtil,
+  sharePanel as sharePanelUtil,
 } from 'app/features/dashboard/utils/panel';
 import Remarkable from 'remarkable';
 import { GRID_CELL_HEIGHT, GRID_CELL_VMARGIN } from 'app/core/constants';
@@ -262,14 +263,7 @@ export class PanelCtrl {
   }
 
   sharePanel() {
-    const shareScope = this.$scope.$new();
-    shareScope.panel = this.panel;
-    shareScope.dashboard = this.dashboard;
-
-    this.publishAppEvent('show-modal', {
-      src: 'public/app/features/dashboard/partials/shareModal.html',
-      scope: shareScope,
-    });
+    sharePanelUtil(this.dashboard, this.panel);
   }
 
   getInfoMode() {