diff --git a/src/panel/graph_panel/controllers/analytic_controller.ts b/src/panel/graph_panel/controllers/analytic_controller.ts index 55be332..436c0bc 100644 --- a/src/panel/graph_panel/controllers/analytic_controller.ts +++ b/src/panel/graph_panel/controllers/analytic_controller.ts @@ -631,6 +631,10 @@ export class AnalyticController { get inspectedAnalyticUnit(): AnalyticUnit | null { for(let analyticUnit of this.analyticUnits) { + // TODO: inspect flag isn't persisted on the server, + // so it resets when closing panel editor in Grafana 7 + // (because AnalyticController is re-created) + // P.S. it works in Grafana 5 and 6 if(analyticUnit.inspect) { return analyticUnit; } diff --git a/src/panel/graph_panel/graph_ctrl.ts b/src/panel/graph_panel/graph_ctrl.ts index 8743310..cdf52e0 100644 --- a/src/panel/graph_panel/graph_ctrl.ts +++ b/src/panel/graph_panel/graph_ctrl.ts @@ -189,7 +189,9 @@ class GraphCtrl extends MetricsPanelCtrl { throw new Error('Cannot parse grafana url'); } - this._panelId = `${this.dashboard.uid}/${this.panel.id}`; + // editSourceId is a true panel ID in panel editor mode in Grafana 7.x + const panelId = this.panel.editSourceId || this.panel.id; + this._panelId = `${this.dashboard.uid}/${panelId}`; this._datasources = {}; this._dataTimerange = {}; } @@ -469,7 +471,7 @@ class GraphCtrl extends MetricsPanelCtrl { } for(let series of this.seriesList) { - if(series.unit) { + if(series.unit !== undefined && series.yaxis !== undefined) { this.panel.yaxes[series.yaxis - 1].format = series.unit; } } @@ -670,25 +672,28 @@ class GraphCtrl extends MetricsPanelCtrl { return `${this.panelPath}/partials`; } - get grafanaVersion() { + get grafanaVersion(): string | null { if(_.has(window, 'grafanaBootData.settings.buildInfo.version')) { return window.grafanaBootData.settings.buildInfo.version; } return null; } - getTemplatePath(filename: string) { + getTemplatePath(filename: string): string { const grafanaVersion = this.grafanaVersion; if(grafanaVersion === null) { throw new Error('Unknown Grafana version'); } - if(grafanaVersion[0] === '5') { - return `${this.partialsPath}/${filename}_5.x.html`; + switch(grafanaVersion[0]) { + case '5': + return `${this.partialsPath}/${filename}_5.x.html`; + case '6': + return `${this.partialsPath}/${filename}_6.x.html`; + case '7': + return `${this.partialsPath}/${filename}_7.x.html`; + default: + throw new Error(`Unsupported Grafana version: ${grafanaVersion}`); } - if(grafanaVersion[0] === '6') { - return `${this.partialsPath}/${filename}_6.x.html`; - } - throw new Error(`Unsupported Grafana version: ${grafanaVersion}`); } createNew() { diff --git a/src/panel/graph_panel/partials/analytic_unit.html b/src/panel/graph_panel/partials/analytic_unit_5.x_6.x.html similarity index 100% rename from src/panel/graph_panel/partials/analytic_unit.html rename to src/panel/graph_panel/partials/analytic_unit_5.x_6.x.html diff --git a/src/panel/graph_panel/partials/analytic_unit_7.x.html b/src/panel/graph_panel/partials/analytic_unit_7.x.html new file mode 100644 index 0000000..dd6f151 --- /dev/null +++ b/src/panel/graph_panel/partials/analytic_unit_7.x.html @@ -0,0 +1,148 @@ +