in scripts/dashboard-importer/src/dashboards/converter/template_variables/templating.ts [24:56]
export function getTemplateVariableMap(
templating: Templating,
): Result<Map<string, string>> {
const interpolationMap = new Map<string, string>();
if (templating.enable === false) {
return success(interpolationMap, [
'Templating was skipped because templating.enable was false',
]);
}
const warnings: string[] = [];
// iterates through the tv and sets the mapping depending on type
for (const templateVariable of templating.list) {
const type = templateVariable.type;
const name = templateVariable.name;
switch (type) {
case 'query':
interpolationMap.set(`$${name}`, `$\{${name}.value}`);
interpolationMap.set(`$\{${name}}`, `$\{${name}.value}`);
break;
case 'interval':
interpolationMap.set(`$${name}`, '${__interval}');
interpolationMap.set(`$\{${name}}`, '${__interval}');
break;
default:
warnings.push(
`Template variable '${name}' was skipped because its type '${type}' is not supported`,
);
}
}
return success(interpolationMap, warnings);
}