grafana/public/app/features/templating/macroRegistry.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

23 lines
801 B
TypeScript

import { DataLinkBuiltInVars, ScopedVars, urlUtil } from '@grafana/data';
import { getTimeSrv } from '../dashboard/services/TimeSrv';
import { getVariablesUrlParams } from '../variables/getAllVariableValuesForUrl';
import { valueMacro } from './dataMacros';
import { MacroHandler } from './types';
export const macroRegistry: Record<string, MacroHandler> = {
['__value']: valueMacro,
[DataLinkBuiltInVars.includeVars]: includeVarsMacro,
[DataLinkBuiltInVars.keepTime]: urlTimeRangeMacro,
};
function includeVarsMacro(match: string, fieldPath?: string, scopedVars?: ScopedVars) {
const allVariablesParams = getVariablesUrlParams(scopedVars);
return urlUtil.toUrlParams(allVariablesParams);
}
function urlTimeRangeMacro() {
return urlUtil.toUrlParams(getTimeSrv().timeRangeForUrl());
}