mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Templating: Optionally save interpolated expressions when replacing variables in a string (#65411)
* Testing a refactor * update * Update interface, test interoplations map * Refactoring * Add more explicit comment about new behavior * Update packages/grafana-runtime/src/services/templateSrv.ts Co-authored-by: Torkel Ödegaard <torkel@grafana.com> --------- Co-authored-by: Torkel Ödegaard <torkel@grafana.com>
This commit is contained in:
@@ -1,5 +1,23 @@
|
||||
import { ScopedVars, TimeRange, TypedVariableModel } from '@grafana/data';
|
||||
|
||||
/**
|
||||
* Can be used to gain more information about an interpolation operation
|
||||
*/
|
||||
export interface VariableInterpolation {
|
||||
/** The full matched expression including, example: ${varName.field:regex} */
|
||||
match: string;
|
||||
/** In the expression ${varName.field:regex} variableName is varName */
|
||||
variableName: string;
|
||||
/** In the expression ${varName.fields[0].name:regex} the fieldPath is fields[0].name */
|
||||
fieldPath?: string;
|
||||
/** In the expression ${varName:regex} the regex part is the format */
|
||||
format?: string;
|
||||
/** The formatted value of the variable expresion. Will equal match when variable not found or scopedVar was undefined or null **/
|
||||
value: string;
|
||||
// When value === match this will be true, meaning the variable was not found
|
||||
found?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Via the TemplateSrv consumers get access to all the available template variables
|
||||
* that can be used within the current active dashboard.
|
||||
@@ -15,8 +33,19 @@ export interface TemplateSrv {
|
||||
|
||||
/**
|
||||
* Replace the values within the target string. See also {@link InterpolateFunction}
|
||||
*
|
||||
* Note: interpolations array is being mutated by replace function by adding information about variables that
|
||||
* have been interpolated during replacement. Variables that were specified in the target but not found in
|
||||
* the list of available variables are also added to the array. See {@link VariableInterpolation} for more details.
|
||||
*
|
||||
* @param {VariableInterpolation[]} interpolations an optional map that is updated with interpolated variables
|
||||
*/
|
||||
replace(target?: string, scopedVars?: ScopedVars, format?: string | Function): string;
|
||||
replace(
|
||||
target?: string,
|
||||
scopedVars?: ScopedVars,
|
||||
format?: string | Function,
|
||||
interpolations?: VariableInterpolation[]
|
||||
): string;
|
||||
|
||||
/**
|
||||
* Checks if a target contains template variables.
|
||||
|
||||
Reference in New Issue
Block a user