Commit 5bc936d2 by Ryan McKinley Committed by GitHub

DataSourceApi: add getCollapsedText(query) to DataSourceApi (#16482)

Add getQueryDisplayText() to DataSourceApi
parent 23d461af
...@@ -107,6 +107,11 @@ export interface DataSourceApi<TQuery extends DataQuery = DataQuery> { ...@@ -107,6 +107,11 @@ export interface DataSourceApi<TQuery extends DataQuery = DataQuery> {
getQueryHints?(query: TQuery, results: any[], ...rest: any): QueryHint[]; getQueryHints?(query: TQuery, results: any[], ...rest: any): QueryHint[];
/** /**
* Convert a query to a simple text string
*/
getQueryDisplayText?(query: TQuery): string;
/**
* Set after constructor is called by Grafana * Set after constructor is called by Grafana
*/ */
name?: string; name?: string;
......
...@@ -225,10 +225,14 @@ export class QueryEditorRow extends PureComponent<Props, State> { ...@@ -225,10 +225,14 @@ export class QueryEditorRow extends PureComponent<Props, State> {
}; };
renderCollapsedText(): string | null { renderCollapsedText(): string | null {
const { datasource } = this.state;
if (datasource.getQueryDisplayText) {
return datasource.getQueryDisplayText(this.props.query);
}
if (this.angularScope && this.angularScope.getCollapsedText) { if (this.angularScope && this.angularScope.getCollapsedText) {
return this.angularScope.getCollapsedText(); return this.angularScope.getCollapsedText();
} }
return null; return null;
} }
......
...@@ -55,6 +55,10 @@ export class PrometheusDatasource implements DataSourceApi<PromQuery> { ...@@ -55,6 +55,10 @@ export class PrometheusDatasource implements DataSourceApi<PromQuery> {
this.loadRules(); this.loadRules();
} }
getQueryDisplayText(query: PromQuery) {
return query.expr;
}
_request(url, data?, options?: any) { _request(url, data?, options?: any) {
options = _.defaults(options || {}, { options = _.defaults(options || {}, {
url: this.url + url, url: this.url + url,
......
...@@ -89,10 +89,6 @@ class PrometheusQueryCtrl extends QueryCtrl { ...@@ -89,10 +89,6 @@ class PrometheusQueryCtrl extends QueryCtrl {
}).join('&'); }).join('&');
this.linkToPrometheus = this.datasource.directUrl + '/graph?' + args; this.linkToPrometheus = this.datasource.directUrl + '/graph?' + args;
} }
getCollapsedText() {
return this.target.expr;
}
} }
export { PrometheusQueryCtrl }; export { PrometheusQueryCtrl };
...@@ -90,6 +90,13 @@ export class TestDataDatasource implements DataSourceApi<TestDataQuery> { ...@@ -90,6 +90,13 @@ export class TestDataDatasource implements DataSourceApi<TestDataQuery> {
return this.$q.when(events); return this.$q.when(events);
} }
getQueryDisplayText(query: TestDataQuery) {
if (query.alias) {
return query.scenarioId + ' as ' + query.alias;
}
return query.scenarioId;
}
testDatasource() { testDatasource() {
return Promise.resolve({ return Promise.resolve({
status: 'success', status: 'success',
......
import { DataQuery } from '@grafana/ui/src/types'; import { DataQuery } from '@grafana/ui/src/types';
export interface TestDataQuery extends DataQuery { export interface TestDataQuery extends DataQuery {
alias?: string;
scenarioId: string; scenarioId: string;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment