mirror of
https://github.com/grafana/grafana.git
synced 2024-11-22 08:56:43 -06:00
TemplateSrv: expose the replace function (#24353)
This commit is contained in:
parent
fa260fec87
commit
d891cc5949
@ -1,4 +1,4 @@
|
||||
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);
|
||||
|
Loading…
Reference in New Issue
Block a user