grafana/public/app/features/variables/getAllVariableValuesForUrl.ts
Ashley Harrison ff0642bf6e
Chore: Type improvements 🧹 (#75271)
* fix some e2e flows types

* some type fixes

* must... fix... more...

* MOAR

* MOREMOREMORE

* 1 more
2023-09-22 15:06:49 +01:00

28 lines
810 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);
}
}
return params;
}