mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
* New rebase Signed-off-by: Lukasz Gryglicki <lukaszgryglicki@o2.pl> * Lint Signed-off-by: Lukasz Gryglicki <lukaszgryglicki@o2.pl>
This commit is contained in:
committed by
Torkel Ödegaard
parent
2c22a7b4ba
commit
24f395f986
@@ -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();
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user