mirror of
https://github.com/grafana/grafana.git
synced 2025-09-21 22:56:07 +08:00
Explore: Expand template variables when redirecting from dashboard panel (#19582)
* Fix redirect but adding getExploreState method to graphite * Explore: Create interpolateVariablesInQueries function for datasources * Explore: Add interpolateVariablesInQueries method to elasticsearch datasource * Add interpolateVariablesInQueries function to influx and postgres * Explore: Add interpolateVariablesInQueries to Mssql and Mysql datasources * Explore: Add datasources to queries * Explore: Code formatting * Prettier formating fix * Explore: Add rawQuery expanding of variables for influxdb * Remove console.logs * Explore: Add rawQuery expanding of multiple variables for influxdb * Explore: If no queries in Influxdb, return early [] * Explore: Refactor influxDb to follow the code structure
This commit is contained in:
@ -5,6 +5,8 @@ import { IQService } from 'angular';
|
||||
import { BackendSrv } from 'app/core/services/backend_srv';
|
||||
import { TemplateSrv } from 'app/features/templating/template_srv';
|
||||
import { TimeSrv } from 'app/features/dashboard/services/TimeSrv';
|
||||
//Types
|
||||
import { PostgresQueryForInterpolation } from './types';
|
||||
|
||||
export class PostgresDatasource {
|
||||
id: any;
|
||||
@ -49,6 +51,21 @@ export class PostgresDatasource {
|
||||
return quotedValues.join(',');
|
||||
};
|
||||
|
||||
interpolateVariablesInQueries(queries: PostgresQueryForInterpolation[]): PostgresQueryForInterpolation[] {
|
||||
let expandedQueries = queries;
|
||||
if (queries && queries.length > 0) {
|
||||
expandedQueries = queries.map(query => {
|
||||
const expandedQuery = {
|
||||
...query,
|
||||
datasource: this.name,
|
||||
rawSql: this.templateSrv.replace(query.rawSql, {}, this.interpolateVariable),
|
||||
};
|
||||
return expandedQuery;
|
||||
});
|
||||
}
|
||||
return expandedQueries;
|
||||
}
|
||||
|
||||
query(options: any) {
|
||||
const queries = _.filter(options.targets, target => {
|
||||
return target.hide !== true;
|
||||
|
Reference in New Issue
Block a user