mirror of
https://github.com/grafana/grafana.git
synced 2025-09-21 17:43:23 +08:00
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:
@ -120,10 +120,11 @@
|
||||
<icon name="'angle-right'" ng-hide="ctrl.showHelp" style="margin-top: 3px;"></icon>
|
||||
</label>
|
||||
</div>
|
||||
<div class="gf-form">
|
||||
<label class="gf-form-label query-keyword pointer" ng-click="ctrl.showQueryInspector()">
|
||||
<div class="gf-form" ng-show="ctrl.lastQueryMeta">
|
||||
<label class="gf-form-label query-keyword pointer" ng-click="ctrl.showLastQuerySQL = !ctrl.showLastQuerySQL">
|
||||
Generated SQL
|
||||
<icon name="'angle-right'" style="margin-top: 3px;"></icon>
|
||||
<icon name="'angle-down'" ng-show="ctrl.showLastQuerySQL" style="margin-top: 3px;"></icon>
|
||||
<icon name="'angle-right'" ng-hide="ctrl.showLastQuerySQL" style="margin-top: 3px;"></icon>
|
||||
</label>
|
||||
</div>
|
||||
<div class="gf-form gf-form--grow">
|
||||
@ -179,6 +180,10 @@ Or build your own conditionals using these macros which just return the values:
|
||||
|
||||
</div>
|
||||
|
||||
<div class="gf-form" ng-show="ctrl.showLastQuerySQL">
|
||||
<pre class="gf-form-pre">{{ctrl.lastQueryMeta.executedQueryString}}</pre>
|
||||
</div>
|
||||
|
||||
<div class="gf-form" ng-show="ctrl.lastQueryError">
|
||||
<pre class="gf-form-pre alert alert-error">{{ctrl.lastQueryError}}</pre>
|
||||
</div>
|
||||
|
@ -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) {
|
||||
|
Reference in New Issue
Block a user