SqlDataSources: Fixes the Show Generated SQL button in query editors (#31236)

* SqlDataSources: Fixes the Show Generated SQL button in query editors

* No need to protect against duplicate events now that the event emitter is isolated for each editor
This commit is contained in:
Torkel Ödegaard
2021-02-16 13:10:40 +01:00
committed by GitHub
parent 06e6bcf091
commit e4672906f0
7 changed files with 47 additions and 68 deletions

View File

@ -7,13 +7,9 @@ import PostgresQuery from './postgres_query';
import sqlPart from './sql_part';
import { auto } from 'angular';
import { CoreEvents } from 'app/types';
import { PanelEvents } from '@grafana/data';
import { PanelEvents, QueryResultMeta } from '@grafana/data';
import { VariableWithMultiSupport } from 'app/features/variables/types';
import { getLocationSrv, TemplateSrv } from '@grafana/runtime';
export interface QueryMeta {
sql: string;
}
import { TemplateSrv } from '@grafana/runtime';
const defaultQuery = `SELECT
$__time(time_column),
@ -30,7 +26,8 @@ export class PostgresQueryCtrl extends QueryCtrl {
formats: any[];
queryModel: PostgresQuery;
metaBuilder: PostgresMetaQuery;
lastQueryError: string | null;
lastQueryMeta?: QueryResultMeta;
lastQueryError?: string;
showHelp: boolean;
tableSegment: any;
whereAdd: any;
@ -106,13 +103,6 @@ export class PostgresQueryCtrl 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();
@ -311,7 +301,8 @@ export class PostgresQueryCtrl extends QueryCtrl {
}
onDataReceived(dataList: any) {
this.lastQueryError = null;
this.lastQueryError = undefined;
this.lastQueryMeta = dataList[0]?.meta;
}
onDataError(err: any) {