mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
added urlescape formatting option
This commit is contained in:
parent
ad84a145f5
commit
a2967565de
@ -52,6 +52,7 @@ Filter Option | Example | Raw | Interpolated | Description
|
|||||||
`csv`| ${servers:csv} | `'test1', 'test2'` | `test1,test2` | Formats multi-value variable as a comma-separated string
|
`csv`| ${servers:csv} | `'test1', 'test2'` | `test1,test2` | Formats multi-value variable as a comma-separated string
|
||||||
`distributed`| ${servers:distributed} | `'test1', 'test2'` | `test1,servers=test2` | Formats multi-value variable in custom format for OpenTSDB.
|
`distributed`| ${servers:distributed} | `'test1', 'test2'` | `test1,servers=test2` | Formats multi-value variable in custom format for OpenTSDB.
|
||||||
`lucene`| ${servers:lucene} | `'test', 'test2'` | `("test" OR "test2")` | Formats multi-value variable as a lucene expression.
|
`lucene`| ${servers:lucene} | `'test', 'test2'` | `("test" OR "test2")` | Formats multi-value variable as a lucene expression.
|
||||||
|
`urlescape` | ${servers:urlescape} | `'foo()bar baz', 'test2'` | `{foo%28%29bar%20baz%2Ctest2}` | Formats multi-value variable into a glob, url escaped
|
||||||
|
|
||||||
Test the formatting options on the [Grafana Play site](http://play.grafana.org/d/cJtIfcWiz/template-variable-formatting-options?orgId=1).
|
Test the formatting options on the [Grafana Play site](http://play.grafana.org/d/cJtIfcWiz/template-variable-formatting-options?orgId=1).
|
||||||
|
|
||||||
|
@ -275,6 +275,11 @@ describe('templateSrv', function() {
|
|||||||
expect(result).toBe('test,test2');
|
expect(result).toBe('test,test2');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('multi value and urlescape format should render url-escaped string', function() {
|
||||||
|
var result = _templateSrv.formatValue(['foo()bar baz', 'test2'], 'urlescape');
|
||||||
|
expect(result).toBe('foo%28%29bar%20baz%2Ctest2');
|
||||||
|
});
|
||||||
|
|
||||||
it('slash should be properly escaped in regex format', function() {
|
it('slash should be properly escaped in regex format', function() {
|
||||||
var result = _templateSrv.formatValue('Gi3/14', 'regex');
|
var result = _templateSrv.formatValue('Gi3/14', 'regex');
|
||||||
expect(result).toBe('Gi3\\/14');
|
expect(result).toBe('Gi3\\/14');
|
||||||
|
@ -124,6 +124,13 @@ export class TemplateSrv {
|
|||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
case 'urlescape': {
|
||||||
|
// like glob, but url escaped
|
||||||
|
if (_.isArray(value)) {
|
||||||
|
return escape('{' + value.join(',') + '}');
|
||||||
|
}
|
||||||
|
return escape(value);
|
||||||
|
}
|
||||||
default: {
|
default: {
|
||||||
if (_.isArray(value)) {
|
if (_.isArray(value)) {
|
||||||
return '{' + value.join(',') + '}';
|
return '{' + value.join(',') + '}';
|
||||||
|
Loading…
Reference in New Issue
Block a user