Commit d891cc59 by Ryan McKinley Committed by GitHub

TemplateSrv: expose the replace function (#24353)

parent fa260fec
import { VariableModel } from '@grafana/data';
import { VariableModel, ScopedVars } from '@grafana/data';
/**
* Via the TemplateSrv consumers get access to all the available template variables
......@@ -8,7 +8,15 @@ import { VariableModel } from '@grafana/data';
* @public
*/
export interface TemplateSrv {
/**
* List the dashboard variables
*/
getVariables(): VariableModel[];
/**
* Replace the values within the target string. See also {@link InterpolateFunction}
*/
replace(target: string, scopedVars?: ScopedVars, format?: string | Function): string;
}
let singletonInstance: TemplateSrv;
......
......@@ -317,7 +317,7 @@ export class TemplateSrv implements BaseTemplateSrv {
return scopedVar.value;
}
replace(target: string, scopedVars?: ScopedVars, format?: string | Function): any {
replace(target: string, scopedVars?: ScopedVars, format?: string | Function): string {
if (!target) {
return target;
}
......
......@@ -300,7 +300,7 @@ export class CloudWatchDatasource extends DataSourceApi<CloudWatchQuery, CloudWa
}
getPeriod(target: CloudWatchMetricsQuery, options: any) {
let period = this.templateSrv.replace(target.period, options.scopedVars);
let period = this.templateSrv.replace(target.period, options.scopedVars) as any;
if (period && period.toLowerCase() !== 'auto') {
if (/^\d+$/.test(period)) {
period = parseInt(period, 10);
......
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