Skip to content

Commit 3540257

Browse files
amngagomesmarcusolsson
authored
Fixes #222 - Added grafana global variables when doing a query using jsonata. (#223)
Co-authored-by: agomes <agomes@localhost.localdomain> Co-authored-by: Marcus Olsson <marcus.olsson@hey.com>
1 parent 3d158e4 commit 3540257

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/datasource.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,14 @@ export class JsonDataSource extends DataSourceApi<JsonApiQuery, JsonApiDataSourc
146146
bindings[v.name] = v.value;
147147
});
148148

149+
150+
// Bind Global variables to JSONata variables.
151+
globalVariables
152+
.map((v) => ({ name: v, value: getVariable(v) }))
153+
.forEach((v) => {
154+
bindings[v.name] = v.value;
155+
});
156+
149157
if (range) {
150158
bindings['__unixEpochFrom'] = range.from.valueOf();
151159
bindings['__unixEpochTo'] = range.to.valueOf();
@@ -301,3 +309,18 @@ const getVariable = (name: any): string[] => {
301309

302310
return values;
303311
};
312+
313+
const globalVariables: string[] = [
314+
'__dashboard',
315+
'__from',
316+
'__to',
317+
'__interval',
318+
'__interval_ms',
319+
'__name',
320+
'__org',
321+
'__user',
322+
'__range',
323+
'__rate_interval',
324+
'timeFilter',
325+
'__timeFilter',
326+
];

0 commit comments

Comments
 (0)