From c11cf188794ee96b40078cb1ec1adb0ab27a2da0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Tue, 26 Dec 2017 13:20:45 +0100 Subject: [PATCH] refactor: tried to simplify and also minimize scope a bit for #10323 --- public/app/core/constants.ts | 2 + public/app/features/dashboard/all.ts | 1 - .../app/features/dashboard/dashboard_ctrl.ts | 7 +- .../dashboard/dashgrid/AddPanelPanel.tsx | 69 ++++++++----------- .../dashboard/dashgrid/PanelContainer.ts | 1 - .../features/dashboard/panel_clipboard_srv.ts | 21 ------ public/app/features/panel/panel_ctrl.ts | 29 ++++---- public/app/features/panel/panel_header.ts | 6 -- 8 files changed, 44 insertions(+), 92 deletions(-) delete mode 100644 public/app/features/dashboard/panel_clipboard_srv.ts diff --git a/public/app/core/constants.ts b/public/app/core/constants.ts index a45a14f1ea2..2642c5e400a 100644 --- a/public/app/core/constants.ts +++ b/public/app/core/constants.ts @@ -6,3 +6,5 @@ export const REPEAT_DIR_VERTICAL = 'v'; export const DEFAULT_PANEL_SPAN = 4; export const DEFAULT_ROW_HEIGHT = 250; export const MIN_PANEL_HEIGHT = GRID_CELL_HEIGHT * 3; + +export const LS_PANEL_COPY_KEY = 'panel-copy'; diff --git a/public/app/features/dashboard/all.ts b/public/app/features/dashboard/all.ts index 72d1a696651..fd79b7b1f03 100644 --- a/public/app/features/dashboard/all.ts +++ b/public/app/features/dashboard/all.ts @@ -27,7 +27,6 @@ import './acl/acl'; import './folder_picker/folder_picker'; import './move_to_folder_modal/move_to_folder'; import './settings/settings'; -import './panel_clipboard_srv'; import coreModule from 'app/core/core_module'; import { DashboardListCtrl } from './dashboard_list_ctrl'; diff --git a/public/app/features/dashboard/dashboard_ctrl.ts b/public/app/features/dashboard/dashboard_ctrl.ts index 3012f86fe31..8b1c69ef7fe 100644 --- a/public/app/features/dashboard/dashboard_ctrl.ts +++ b/public/app/features/dashboard/dashboard_ctrl.ts @@ -22,8 +22,7 @@ export class DashboardCtrl implements PanelContainer { private unsavedChangesSrv, private dashboardViewStateSrv, public playlistSrv, - private panelLoader, - private panelClipboardSrv + private panelLoader ) { // temp hack due to way dashboards are loaded // can't use controllerAs on route yet @@ -123,10 +122,6 @@ export class DashboardCtrl implements PanelContainer { return this.panelLoader; } - getClipboardPanel() { - return this.panelClipboardSrv.getPanel(); - } - timezoneChanged() { this.$rootScope.$broadcast('refresh'); } diff --git a/public/app/features/dashboard/dashgrid/AddPanelPanel.tsx b/public/app/features/dashboard/dashgrid/AddPanelPanel.tsx index 78def4d47bc..1f143f3d7f7 100644 --- a/public/app/features/dashboard/dashgrid/AddPanelPanel.tsx +++ b/public/app/features/dashboard/dashgrid/AddPanelPanel.tsx @@ -5,6 +5,8 @@ import config from 'app/core/config'; import { PanelModel } from '../panel_model'; import { PanelContainer } from './PanelContainer'; import ScrollBar from 'app/core/components/ScrollBar/ScrollBar'; +import store from 'app/core/store'; +import { LS_PANEL_COPY_KEY } from 'app/core/constants'; export interface AddPanelPanelProps { panel: PanelModel; @@ -14,7 +16,6 @@ export interface AddPanelPanelProps { export interface AddPanelPanelState { filter: string; panelPlugins: any[]; - clipboardPanel: any; } export class AddPanelPanel extends React.Component { @@ -23,12 +24,8 @@ export class AddPanelPanel extends React.Component { const panelContainer = this.props.getPanelContainer(); const dashboard = panelContainer.getDashboard(); const { gridPos } = this.props.panel; @@ -64,39 +70,23 @@ export class AddPanelPanel extends React.Component this.onClipboardPanelSelected(panel)} title={title}> -
- -
-
Paste copied panel
- - ); - } - - renderPanelItem(panel) { - return ( -
this.onPanelSelected(panel)} title={panel.name}> +
this.onAddPanel(panel)} title={panel.name}>
{panel.name}
@@ -113,7 +103,6 @@ export class AddPanelPanel extends React.ComponentSelect a visualization
- {this.state.clipboardPanel && this.renderClipboardPanel(this.state.clipboardPanel)} {this.state.panelPlugins.map(this.renderPanelItem.bind(this))} diff --git a/public/app/features/dashboard/dashgrid/PanelContainer.ts b/public/app/features/dashboard/dashgrid/PanelContainer.ts index f56fab6ef4f..87f3235a176 100644 --- a/public/app/features/dashboard/dashgrid/PanelContainer.ts +++ b/public/app/features/dashboard/dashgrid/PanelContainer.ts @@ -4,5 +4,4 @@ import { PanelLoader } from './PanelLoader'; export interface PanelContainer { getPanelLoader(): PanelLoader; getDashboard(): DashboardModel; - getClipboardPanel(): any; } diff --git a/public/app/features/dashboard/panel_clipboard_srv.ts b/public/app/features/dashboard/panel_clipboard_srv.ts deleted file mode 100644 index 78411562097..00000000000 --- a/public/app/features/dashboard/panel_clipboard_srv.ts +++ /dev/null @@ -1,21 +0,0 @@ -import coreModule from 'app/core/core_module'; -import { appEvents } from 'app/core/core'; - -class PanelClipboardSrv { - key = 'GrafanaDashboardClipboardPanel'; - - /** @ngInject **/ - constructor(private $window) { - appEvents.on('copy-dashboard-panel', this.copyDashboardPanel.bind(this)); - } - - getPanel() { - return this.$window[this.key]; - } - - private copyDashboardPanel(payload) { - this.$window[this.key] = payload; - } -} - -coreModule.service('panelClipboardSrv', PanelClipboardSrv); diff --git a/public/app/features/panel/panel_ctrl.ts b/public/app/features/panel/panel_ctrl.ts index 1cf4681515c..17eae2cbf19 100644 --- a/public/app/features/panel/panel_ctrl.ts +++ b/public/app/features/panel/panel_ctrl.ts @@ -4,7 +4,8 @@ import $ from 'jquery'; import { appEvents, profiler } from 'app/core/core'; import { PanelModel } from 'app/features/dashboard/panel_model'; import Remarkable from 'remarkable'; -import { GRID_CELL_HEIGHT, GRID_CELL_VMARGIN } from 'app/core/constants'; +import { GRID_CELL_HEIGHT, GRID_CELL_VMARGIN, LS_PANEL_COPY_KEY } from 'app/core/constants'; +import store from 'app/core/store'; const TITLE_HEIGHT = 27; const PANEL_BORDER = 2; @@ -190,19 +191,19 @@ export class PanelCtrl { click: 'ctrl.duplicate()', role: 'Editor', }); + + menu.push({ + text: 'Add to Panel List', + click: 'ctrl.addToPanelList()', + role: 'Editor', + }); } + menu.push({ text: 'Panel JSON', click: 'ctrl.editPanelJson(); dismiss();', }); - menu.push({ - text: 'Copy to Clipboard', - click: 'ctrl.copyPanelToClipboard()', - role: 'Editor', - directives: ['clipboard-button="ctrl.getPanelJson()"'], - }); - this.events.emit('init-panel-actions', menu); return menu; } @@ -278,15 +279,9 @@ export class PanelCtrl { }); } - copyPanelToClipboard() { - appEvents.emit('copy-dashboard-panel', { - dashboard: this.dashboard.title, - panel: this.panel.getSaveModel(), - }); - } - - getPanelJson() { - return JSON.stringify(this.panel.getSaveModel(), null, 2); + addToPanelList() { + store.set(LS_PANEL_COPY_KEY, JSON.stringify(this.panel.getSaveModel())); + appEvents.emit('alert-success', ['Panel temporarily added to panel list']); } replacePanel(newPanel, oldPanel) { diff --git a/public/app/features/panel/panel_header.ts b/public/app/features/panel/panel_header.ts index de8c93d5038..ca6ed68b648 100644 --- a/public/app/features/panel/panel_header.ts +++ b/public/app/features/panel/panel_header.ts @@ -51,12 +51,6 @@ function renderMenuItem(item, ctrl) { html += ` href="${item.href}"`; } - if (item.directives) { - for (let directive of item.directives) { - html += ` ${directive}`; - } - } - html += `>`; html += `${item.text}`;