mirror of
https://github.com/grafana/grafana.git
synced 2025-02-13 09:05:45 -06:00
* Templating: Introduce macros to simplify and optimize some scopedVars * Fixing tests * fix test * minor fix * refactoring so macros work with formatting * remove breaking change and keep current inconsistency * Rename valueIndex to rowIndex * Minor fixes * Added test dashboard * Added tags to dashboard * Update * Added test to check it returns match * Update * Fixed dashboard * fix
28 lines
817 B
TypeScript
28 lines
817 B
TypeScript
import { ScopedVars, UrlQueryMap } from '@grafana/data';
|
|
import { getTemplateSrv } from '@grafana/runtime';
|
|
|
|
import { variableAdapters } from './adapters';
|
|
import { VARIABLE_PREFIX } from './constants';
|
|
|
|
export function getVariablesUrlParams(scopedVars?: ScopedVars): UrlQueryMap {
|
|
const params: UrlQueryMap = {};
|
|
const variables = getTemplateSrv().getVariables();
|
|
|
|
for (let i = 0; i < variables.length; i++) {
|
|
const variable = variables[i];
|
|
const scopedVar = scopedVars && scopedVars[variable.name];
|
|
|
|
if (variable.skipUrlSync) {
|
|
continue;
|
|
}
|
|
|
|
if (scopedVar) {
|
|
params[VARIABLE_PREFIX + variable.name] = scopedVar.value;
|
|
} else {
|
|
params[VARIABLE_PREFIX + variable.name] = variableAdapters.get(variable.type).getValueForUrl(variable as any);
|
|
}
|
|
}
|
|
|
|
return params;
|
|
}
|