mirror of
https://github.com/grafana/grafana.git
synced 2025-09-27 01:53:57 +08:00
QueryInspector: add common way to show the raw query (#25204)
This commit is contained in:
@ -10,6 +10,7 @@ import { TemplateSrv } from 'app/features/templating/template_srv';
|
||||
import { CoreEvents } from 'app/types';
|
||||
import { PanelEvents } from '@grafana/data';
|
||||
import { VariableWithMultiSupport } from 'app/features/templating/types';
|
||||
import { getLocationSrv } from '@grafana/runtime';
|
||||
|
||||
export interface QueryMeta {
|
||||
sql: string;
|
||||
@ -27,9 +28,7 @@ ORDER BY <time_column> ASC
|
||||
export class MysqlQueryCtrl extends QueryCtrl {
|
||||
static templateUrl = 'partials/query.editor.html';
|
||||
|
||||
showLastQuerySQL: boolean;
|
||||
formats: any[];
|
||||
lastQueryMeta: QueryMeta;
|
||||
lastQueryError: string;
|
||||
showHelp: boolean;
|
||||
|
||||
@ -110,6 +109,13 @@ export class MysqlQueryCtrl extends QueryCtrl {
|
||||
this.panelCtrl.events.on(PanelEvents.dataError, this.onDataError.bind(this), $scope);
|
||||
}
|
||||
|
||||
showQueryInspector() {
|
||||
getLocationSrv().update({
|
||||
query: { inspect: this.panel.id, inspectTab: 'query' },
|
||||
partial: true,
|
||||
});
|
||||
}
|
||||
|
||||
updateRawSqlAndRefresh() {
|
||||
if (!this.target.rawQuery) {
|
||||
this.target.rawSql = this.queryModel.buildQuery();
|
||||
@ -273,20 +279,13 @@ export class MysqlQueryCtrl extends QueryCtrl {
|
||||
}
|
||||
|
||||
onDataReceived(dataList: any) {
|
||||
this.lastQueryMeta = null;
|
||||
this.lastQueryError = null;
|
||||
|
||||
const anySeriesFromQuery: any = _.find(dataList, { refId: this.target.refId });
|
||||
if (anySeriesFromQuery) {
|
||||
this.lastQueryMeta = anySeriesFromQuery.meta;
|
||||
}
|
||||
}
|
||||
|
||||
onDataError(err: any) {
|
||||
if (err.data && err.data.results) {
|
||||
const queryRes = err.data.results[this.target.refId];
|
||||
if (queryRes) {
|
||||
this.lastQueryMeta = queryRes.meta;
|
||||
this.lastQueryError = queryRes.error;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user