mirror of
https://github.com/grafana/grafana.git
synced 2025-02-16 18:34:52 -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
|
* Via the TemplateSrv consumers get access to all the available template variables
|
||||||
@ -8,7 +8,15 @@ import { VariableModel } from '@grafana/data';
|
|||||||
* @public
|
* @public
|
||||||
*/
|
*/
|
||||||
export interface TemplateSrv {
|
export interface TemplateSrv {
|
||||||
|
/**
|
||||||
|
* List the dashboard variables
|
||||||
|
*/
|
||||||
getVariables(): VariableModel[];
|
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;
|
let singletonInstance: TemplateSrv;
|
||||||
|
@ -317,7 +317,7 @@ export class TemplateSrv implements BaseTemplateSrv {
|
|||||||
return scopedVar.value;
|
return scopedVar.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
replace(target: string, scopedVars?: ScopedVars, format?: string | Function): any {
|
replace(target: string, scopedVars?: ScopedVars, format?: string | Function): string {
|
||||||
if (!target) {
|
if (!target) {
|
||||||
return target;
|
return target;
|
||||||
}
|
}
|
||||||
|
@ -300,7 +300,7 @@ export class CloudWatchDatasource extends DataSourceApi<CloudWatchQuery, CloudWa
|
|||||||
}
|
}
|
||||||
|
|
||||||
getPeriod(target: CloudWatchMetricsQuery, options: any) {
|
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 (period && period.toLowerCase() !== 'auto') {
|
||||||
if (/^\d+$/.test(period)) {
|
if (/^\d+$/.test(period)) {
|
||||||
period = parseInt(period, 10);
|
period = parseInt(period, 10);
|
||||||
|
Loading…
Reference in New Issue
Block a user