From 1eecda48f84c65a97c578308527d7197fea10f36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Wed, 14 Nov 2018 14:40:03 +0100 Subject: [PATCH] Moved query manipulations from metrics controller to metrics tab so they are more easily shared between angular and react panels --- .../features/dashboard/dashgrid/DataPanel.tsx | 9 +++++ .../app/features/panel/metrics_panel_ctrl.ts | 20 ----------- public/app/features/panel/metrics_tab.ts | 35 ++++++++++++++++--- .../features/panel/partials/metrics_tab.html | 2 +- .../app/features/plugins/plugin_component.ts | 2 +- public/app/plugins/panel/table/module.ts | 5 --- public/sass/pages/_dashboard.scss | 14 ++++++++ 7 files changed, 55 insertions(+), 32 deletions(-) diff --git a/public/app/features/dashboard/dashgrid/DataPanel.tsx b/public/app/features/dashboard/dashgrid/DataPanel.tsx index 77523d9e242..0c14a1429a9 100644 --- a/public/app/features/dashboard/dashgrid/DataPanel.tsx +++ b/public/app/features/dashboard/dashgrid/DataPanel.tsx @@ -132,6 +132,7 @@ export class DataPanel extends Component { }; render() { + const { queries } = this.props; const { response, loading, isFirstLoad } = this.state; const timeSeries = response.data; @@ -139,6 +140,14 @@ export class DataPanel extends Component { return this.renderLoadingSpinner(); } + if (!queries.length) { + return ( +
+

Add a query to get some data!

+
+ ); + } + return ( <> {this.renderLoadingSpinner()} diff --git a/public/app/features/panel/metrics_panel_ctrl.ts b/public/app/features/panel/metrics_panel_ctrl.ts index e19a36294ce..9af4eb510a9 100644 --- a/public/app/features/panel/metrics_panel_ctrl.ts +++ b/public/app/features/panel/metrics_panel_ctrl.ts @@ -27,7 +27,6 @@ class MetricsPanelCtrl extends PanelCtrl { dataStream: any; dataSubscription: any; dataList: any; - nextRefId: string; constructor($scope, $injector) { super($scope, $injector); @@ -263,25 +262,6 @@ class MetricsPanelCtrl extends PanelCtrl { this.$timeout(() => this.$location.url(url)); } } - - addQuery(target) { - target.refId = this.dashboard.getNextQueryLetter(this.panel); - - this.panel.targets.push(target); - this.nextRefId = this.dashboard.getNextQueryLetter(this.panel); - } - - removeQuery(target) { - const index = _.indexOf(this.panel.targets, target); - this.panel.targets.splice(index, 1); - this.nextRefId = this.dashboard.getNextQueryLetter(this.panel); - this.refresh(); - } - - moveQuery(target, direction) { - const index = _.indexOf(this.panel.targets, target); - _.move(this.panel.targets, index, index + direction); - } } export { MetricsPanelCtrl }; diff --git a/public/app/features/panel/metrics_tab.ts b/public/app/features/panel/metrics_tab.ts index f520b5eefc0..4f198e2dd94 100644 --- a/public/app/features/panel/metrics_tab.ts +++ b/public/app/features/panel/metrics_tab.ts @@ -48,7 +48,7 @@ export class MetricsTabCtrl { this.addQueryDropdown = { text: 'Add Query', value: null, fake: true }; // update next ref id - this.panelCtrl.nextRefId = this.dashboard.getNextQueryLetter(this.panel); + this.nextRefId = this.dashboard.getNextQueryLetter(this.panel); this.updateDatasourceOptions(); } @@ -112,10 +112,6 @@ export class MetricsTabCtrl { this.addQueryDropdown = { text: 'Add Query', value: null, fake: true }; } - addQuery() { - this.panelCtrl.addQuery({ isNew: true }); - } - toggleHelp() { this.optionsOpen = false; this.queryTroubleshooterOpen = false; @@ -138,6 +134,35 @@ export class MetricsTabCtrl { this.optionsOpen = false; this.queryTroubleshooterOpen = !this.queryTroubleshooterOpen; } + + addQuery(query?) { + query = query || {}; + query.refId = this.dashboard.getNextQueryLetter(this.panel); + query.isNew = true; + + this.panel.targets.push(query); + this.nextRefId = this.dashboard.getNextQueryLetter(this.panel); + } + + refresh() { + this.panel.refresh(); + } + + render() { + this.panel.render(); + } + + removeQuery(target) { + const index = _.indexOf(this.panel.targets, target); + this.panel.targets.splice(index, 1); + this.nextRefId = this.dashboard.getNextQueryLetter(this.panel); + this.panel.refresh(); + } + + moveQuery(target, direction) { + const index = _.indexOf(this.panel.targets, target); + _.move(this.panel.targets, index, index + direction); + } } /** @ngInject */ diff --git a/public/app/features/panel/partials/metrics_tab.html b/public/app/features/panel/partials/metrics_tab.html index 815a99d6b74..7899312f5c3 100644 --- a/public/app/features/panel/partials/metrics_tab.html +++ b/public/app/features/panel/partials/metrics_tab.html @@ -83,7 +83,7 @@ - {{ctrl.panelCtrl.nextRefId}} + {{ctrl.nextRefId}}