getAllVariableValuesForUrl.ts 847 B

123456789101112131415161718192021222324252627
  1. import { ScopedVars, UrlQueryMap } from '@grafana/data';
  2. import { getTemplateSrv } from '@grafana/runtime';
  3. import { variableAdapters } from './adapters';
  4. export function getVariablesUrlParams(scopedVars?: ScopedVars): UrlQueryMap {
  5. const params: UrlQueryMap = {};
  6. const variables = getTemplateSrv().getVariables();
  7. for (let i = 0; i < variables.length; i++) {
  8. const variable = variables[i];
  9. if (scopedVars && scopedVars[variable.name] !== void 0) {
  10. if (scopedVars[variable.name].skipUrlSync) {
  11. continue;
  12. }
  13. params['var-' + variable.name] = scopedVars[variable.name].value;
  14. } else {
  15. // @ts-ignore
  16. if (variable.skipUrlSync) {
  17. continue;
  18. }
  19. params['var-' + variable.name] = variableAdapters.get(variable.type).getValueForUrl(variable as any);
  20. }
  21. }
  22. return params;
  23. }