grafana/public/app/features/variables/getAllVariableValuesForUrl.ts
Torkel Ödegaard b7b608418d
Templating: Introduce macros to simplify and optimize some scopedVars (#65317)
* 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
2023-03-28 19:22:34 +02:00

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;
}