From 244cbe8cbd3ef7d6d5273865ad614ba3e9e5fcab Mon Sep 17 00:00:00 2001 From: Mitsuhiro Tanda Date: Wed, 7 Mar 2018 21:35:54 +0900 Subject: [PATCH] add csv templating format --- public/app/features/templating/specs/template_srv.jest.ts | 6 +++++- public/app/features/templating/template_srv.ts | 6 ++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/public/app/features/templating/specs/template_srv.jest.ts b/public/app/features/templating/specs/template_srv.jest.ts index 37e2f5e4fe5..f28fbf9ac64 100644 --- a/public/app/features/templating/specs/template_srv.jest.ts +++ b/public/app/features/templating/specs/template_srv.jest.ts @@ -107,7 +107,6 @@ describe('templateSrv', function() { ]); }); - it('should replace $test with globbed value', function() { var target = _templateSrv.replace('this.$test.filters', {}, 'glob'); expect(target).toBe('this.{value1,value2}.filters'); @@ -261,6 +260,11 @@ describe('templateSrv', function() { expect(result).toBe('test'); }); + it('multi value and csv format should render csv string', function() { + var result = _templateSrv.formatValue(['test', 'test2'], 'csv'); + expect(result).toBe('test,test2'); + }); + it('slash should be properly escaped in regex format', function() { var result = _templateSrv.formatValue('Gi3/14', 'regex'); expect(result).toBe('Gi3\\/14'); diff --git a/public/app/features/templating/template_srv.ts b/public/app/features/templating/template_srv.ts index 40f119ea10b..5b31072d140 100644 --- a/public/app/features/templating/template_srv.ts +++ b/public/app/features/templating/template_srv.ts @@ -115,6 +115,12 @@ export class TemplateSrv { } return this.distributeVariable(value, variable.name); } + case 'csv': { + if (_.isArray(value)) { + return value.join(','); + } + return value; + } default: { if (_.isArray(value)) { return '{' + value.join(',') + '}';