Commit 24f395f9 by Łukasz Gryglicki Committed by Torkel Ödegaard

Add support for skipping variable value in URL, fixes #12174 (#12541)

* New rebase

Signed-off-by: Lukasz Gryglicki <lukaszgryglicki@o2.pl>

* Lint

Signed-off-by: Lukasz Gryglicki <lukaszgryglicki@o2.pl>
parent 2c22a7b4
......@@ -3,6 +3,7 @@ import { Variable, assignModelProperties, variableTypes } from './variable';
export class AdhocVariable implements Variable {
filters: any[];
skipUrlSync: boolean;
defaults = {
type: 'adhoc',
......@@ -11,6 +12,7 @@ export class AdhocVariable implements Variable {
hide: 0,
datasource: null,
filters: [],
skipUrlSync: false,
};
/** @ngInject **/
......
......@@ -4,6 +4,7 @@ export class ConstantVariable implements Variable {
query: string;
options: any[];
current: any;
skipUrlSync: boolean;
defaults = {
type: 'constant',
......@@ -13,6 +14,7 @@ export class ConstantVariable implements Variable {
query: '',
current: {},
options: [],
skipUrlSync: false,
};
/** @ngInject **/
......
......@@ -7,6 +7,7 @@ export class CustomVariable implements Variable {
includeAll: boolean;
multi: boolean;
current: any;
skipUrlSync: boolean;
defaults = {
type: 'custom',
......@@ -19,6 +20,7 @@ export class CustomVariable implements Variable {
includeAll: false,
multi: false,
allValue: null,
skipUrlSync: false,
};
/** @ngInject **/
......
......@@ -7,6 +7,7 @@ export class DatasourceVariable implements Variable {
options: any;
current: any;
refresh: any;
skipUrlSync: boolean;
defaults = {
type: 'datasource',
......@@ -18,6 +19,7 @@ export class DatasourceVariable implements Variable {
options: [],
query: '',
refresh: 1,
skipUrlSync: false,
};
/** @ngInject **/
......
......@@ -11,6 +11,7 @@ export class IntervalVariable implements Variable {
query: string;
refresh: number;
current: any;
skipUrlSync: boolean;
defaults = {
type: 'interval',
......@@ -24,6 +25,7 @@ export class IntervalVariable implements Variable {
auto: false,
auto_min: '10s',
auto_count: 30,
skipUrlSync: false,
};
/** @ngInject **/
......
......@@ -22,6 +22,7 @@ export class QueryVariable implements Variable {
tagsQuery: string;
tagValuesQuery: string;
tags: any[];
skipUrlSync: boolean;
defaults = {
type: 'query',
......@@ -42,6 +43,7 @@ export class QueryVariable implements Variable {
useTags: false,
tagsQuery: '',
tagValuesQuery: '',
skipUrlSync: false,
};
/** @ngInject **/
......
......@@ -345,6 +345,49 @@ describe('templateSrv', function() {
});
});
describe('fillVariableValuesForUrl skip url sync', function() {
beforeEach(function() {
initTemplateSrv([
{
name: 'test',
skipUrlSync: true,
current: { value: 'value' },
getValueForUrl: function() {
return this.current.value;
},
},
]);
});
it('should not include template variable value in url', function() {
var params = {};
_templateSrv.fillVariableValuesForUrl(params);
expect(params['var-test']).toBe(undefined);
});
});
describe('fillVariableValuesForUrl with multi value with skip url sync', function() {
beforeEach(function() {
initTemplateSrv([
{
type: 'query',
name: 'test',
skipUrlSync: true,
current: { value: ['val1', 'val2'] },
getValueForUrl: function() {
return this.current.value;
},
},
]);
});
it('should not include template variable value in url', function() {
var params = {};
_templateSrv.fillVariableValuesForUrl(params);
expect(params['var-test']).toBe(undefined);
});
});
describe('fillVariableValuesForUrl with multi value and scopedVars', function() {
beforeEach(function() {
initTemplateSrv([{ type: 'query', name: 'test', current: { value: ['val1', 'val2'] } }]);
......@@ -359,6 +402,20 @@ describe('templateSrv', function() {
});
});
describe('fillVariableValuesForUrl with multi value, scopedVars and skip url sync', function() {
beforeEach(function() {
initTemplateSrv([{ type: 'query', name: 'test', current: { value: ['val1', 'val2'] } }]);
});
it('should not set scoped value as url params', function() {
var params = {};
_templateSrv.fillVariableValuesForUrl(params, {
test: { name: 'test', value: 'val1', skipUrlSync: true },
});
expect(params['var-test']).toBe(undefined);
});
});
describe('replaceWithText', function() {
beforeEach(function() {
initTemplateSrv([
......
......@@ -250,8 +250,14 @@ export class TemplateSrv {
fillVariableValuesForUrl(params, scopedVars) {
_.each(this.variables, function(variable) {
if (scopedVars && scopedVars[variable.name] !== void 0) {
if (scopedVars[variable.name].skipUrlSync) {
return;
}
params['var-' + variable.name] = scopedVars[variable.name].value;
} else {
if (variable.skipUrlSync) {
return;
}
params['var-' + variable.name] = variable.getValueForUrl();
}
});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment