add csv templating format

This commit is contained in:
Mitsuhiro Tanda 2018-03-07 21:35:54 +09:00
parent 310d740667
commit 244cbe8cbd
2 changed files with 11 additions and 1 deletions

View File

@ -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');

View File

@ -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(',') + '}';