From 159c5cdb63445514f18ea7ab4fb3ce6757548ff9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Wed, 14 Nov 2018 17:57:37 +0100 Subject: [PATCH] wip: adding general tab for react panel edit mode --- .../dashboard/dashgrid/GeneralTab.tsx | 60 +++++++++++++++++++ .../dashboard/dashgrid/PanelEditor.tsx | 4 +- public/app/features/panel/GeneralTabCtrl.ts | 23 +++++++ public/app/features/panel/panel_ctrl.ts | 4 +- .../panel/partials/general_tab.html} | 0 5 files changed, 89 insertions(+), 2 deletions(-) create mode 100644 public/app/features/dashboard/dashgrid/GeneralTab.tsx create mode 100644 public/app/features/panel/GeneralTabCtrl.ts rename public/app/{partials/panelgeneral.html => features/panel/partials/general_tab.html} (100%) diff --git a/public/app/features/dashboard/dashgrid/GeneralTab.tsx b/public/app/features/dashboard/dashgrid/GeneralTab.tsx new file mode 100644 index 00000000000..2ffac98bfd7 --- /dev/null +++ b/public/app/features/dashboard/dashgrid/GeneralTab.tsx @@ -0,0 +1,60 @@ +import React, { PureComponent } from 'react'; + +import { getAngularLoader, AngularComponent } from 'app/core/services/AngularLoader'; +import { EditorTabBody } from './EditorTabBody'; + +import { PanelModel } from '../panel_model'; +import { DashboardModel } from '../dashboard_model'; + +interface Props { + panel: PanelModel; + dashboard: DashboardModel; +} + +export class GeneralTab extends PureComponent { + element: any; + component: AngularComponent; + + constructor(props) { + super(props); + } + + componentDidMount() { + if (!this.element) { + return; + } + + const { panel, dashboard } = this.props; + + const loader = getAngularLoader(); + const template = ''; + const scopeProps = { + ctrl: { + panel: panel, + dashboard: dashboard, + }, + }; + + this.component = loader.load(this.element, scopeProps, template); + } + + componentWillUnmount() { + if (this.component) { + this.component.destroy(); + } + } + + render() { + const currentDataSource = { + title: 'ProductionDB', + imgSrc: 'public/app/plugins/datasource/prometheus/img/prometheus_logo.svg', + render: () =>

hello

, + }; + + return ( + +
(this.element = element)} style={{ width: '100%' }} /> + + ); + } +} diff --git a/public/app/features/dashboard/dashgrid/PanelEditor.tsx b/public/app/features/dashboard/dashgrid/PanelEditor.tsx index 09a8c7052e3..6d9072048ae 100644 --- a/public/app/features/dashboard/dashgrid/PanelEditor.tsx +++ b/public/app/features/dashboard/dashgrid/PanelEditor.tsx @@ -3,6 +3,7 @@ import classNames from 'classnames'; import { QueriesTab } from './QueriesTab'; import { VisualizationTab } from './VisualizationTab'; +import { GeneralTab } from './GeneralTab'; import { store } from 'app/store/store'; import { updateLocation } from 'app/core/actions'; @@ -31,9 +32,9 @@ export class PanelEditor extends PureComponent { super(props); this.tabs = [ + { id: 'general', text: 'General', icon: 'gicon gicon-preferences' }, { id: 'queries', text: 'Queries', icon: 'fa fa-database' }, { id: 'visualization', text: 'Visualization', icon: 'fa fa-line-chart' }, - { id: 'alert', text: 'Alert', icon: 'gicon gicon-alert' }, ]; } @@ -81,6 +82,7 @@ export class PanelEditor extends PureComponent {
+ {activeTab === 'general' && } {activeTab === 'queries' && } {activeTab === 'visualization' && ( diff --git a/public/app/features/panel/GeneralTabCtrl.ts b/public/app/features/panel/GeneralTabCtrl.ts new file mode 100644 index 00000000000..46db29b2e9b --- /dev/null +++ b/public/app/features/panel/GeneralTabCtrl.ts @@ -0,0 +1,23 @@ +import coreModule from 'app/core/core_module'; +import { DashboardModel } from '../dashboard/dashboard_model'; + +export class GeneralTabCtrl { + panelCtrl: any; + + /** @ngInject */ + constructor($scope) { + this.panelCtrl = $scope.ctrl; + } +} + +/** @ngInject */ +export function generalTab() { + 'use strict'; + return { + restrict: 'E', + templateUrl: 'public/app/features/panel/partials/general_tab.html', + controller: GeneralTabCtrl, + }; +} + +coreModule.directive('panelGeneralTab', generalTab); diff --git a/public/app/features/panel/panel_ctrl.ts b/public/app/features/panel/panel_ctrl.ts index 420210be380..fe9fa7eb728 100644 --- a/public/app/features/panel/panel_ctrl.ts +++ b/public/app/features/panel/panel_ctrl.ts @@ -12,6 +12,8 @@ import { sharePanel as sharePanelUtil, } from 'app/features/dashboard/utils/panel'; +import { generalTab } from './GeneralTabCtrl'; + import { GRID_CELL_HEIGHT, GRID_CELL_VMARGIN, PANEL_HEADER_HEIGHT, PANEL_BORDER } from 'app/core/constants'; export class PanelCtrl { @@ -91,7 +93,7 @@ export class PanelCtrl { initEditMode() { this.editorTabs = []; - this.addEditorTab('General', 'public/app/partials/panelgeneral.html'); + this.addEditorTab('General', generalTab); this.editModeInitiated = true; this.events.emit('init-edit-mode', null); diff --git a/public/app/partials/panelgeneral.html b/public/app/features/panel/partials/general_tab.html similarity index 100% rename from public/app/partials/panelgeneral.html rename to public/app/features/panel/partials/general_tab.html