From 0898164c0e5e485ed53f96a37fd23ae2009ed743 Mon Sep 17 00:00:00 2001 From: PhracturedBlue Date: Sat, 1 Jun 2019 06:56:23 -0700 Subject: [PATCH] Add support for multi-value variables based on https://github.com/grafana/grafana/blob/v5.0.4/public/app/plugins/datasource/postgres/datasource.ts#L16-L33 --- dist/datasource.js | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/dist/datasource.js b/dist/datasource.js index c9bcdb9..39e8462 100644 --- a/dist/datasource.js +++ b/dist/datasource.js @@ -144,6 +144,26 @@ System.register(['lodash'], function (_export, _context) { return this.backendSrv.datasourceRequest(options); } + }, { + key: 'interpolateVariable', + value: function interpolateVariable(value, variable) { + if (typeof value === 'string') { + if (variable.multi || variable.includeAll) { + return '"' + value + '"'; + } else { + return value; + } + } + + if (typeof value === 'number') { + return value; + } + + var quotedValues = _.map(value, function(val) { + return '"' + val + '"'; + }); + return quotedValues.join(','); + } }, { key: 'buildQueryParameters', value: function buildQueryParameters(options) { @@ -156,7 +176,7 @@ System.register(['lodash'], function (_export, _context) { var targets = _.map(options.targets, function (target) { return { - target: _this.templateSrv.replace(target.target, options.scopedVars, ''), + target: _this.templateSrv.replace(target.target, options.scopedVars, _this.interpolateVariable), refId: target.refId, hide: target.hide, type: target.type || 'timeserie'