Skip to content

Commit 599fe49

Browse files
committed
fix(templating): fix to datasource variable, was not updated on dashboard load, added unit test for case as well
1 parent 68370ba commit 599fe49

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

public/app/features/templating/datasource_variable.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export class DatasourceVariable implements Variable {
1010
query: string;
1111
options: any;
1212
current: any;
13+
refresh: any;
1314

1415
defaults = {
1516
type: 'datasource',
@@ -20,11 +21,13 @@ export class DatasourceVariable implements Variable {
2021
regex: '',
2122
options: [],
2223
query: '',
24+
refresh: 1,
2325
};
2426

2527
/** @ngInject **/
2628
constructor(private model, private datasourceSrv, private variableSrv) {
2729
assignModelProperties(this, model, this.defaults);
30+
this.refresh = 1;
2831
}
2932

3033
getModel() {

public/app/features/templating/specs/variable_srv_init_specs.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ describe('VariableSrv init', function() {
6262
options: [{text: "test", value: "test"}]
6363
}];
6464
scenario.urlParams["var-apps"] = "new";
65+
scenario.metricSources = [];
6566
});
6667

6768
it('should update current value', () => {
@@ -110,6 +111,30 @@ describe('VariableSrv init', function() {
110111
});
111112
});
112113

114+
describeInitScenario('when datasource variable is initialized', scenario => {
115+
scenario.setup(() => {
116+
scenario.variables = [{
117+
type: 'datasource',
118+
query: 'graphite',
119+
name: 'test',
120+
current: {value: 'backend4_pee', text: 'backend4_pee'},
121+
regex: '/pee$/'
122+
}
123+
];
124+
scenario.metricSources = [
125+
{name: 'backend1', meta: {id: 'influx'}},
126+
{name: 'backend2_pee', meta: {id: 'graphite'}},
127+
{name: 'backend3', meta: {id: 'graphite'}},
128+
{name: 'backend4_pee', meta: {id: 'graphite'}},
129+
];
130+
});
131+
132+
it('should update current value', function() {
133+
var variable = ctx.variableSrv.variables[0];
134+
expect(variable.options.length).to.be(2);
135+
});
136+
});
137+
113138
describeInitScenario('when template variable is present in url multiple times', scenario => {
114139
scenario.setup(() => {
115140
scenario.variables = [{

0 commit comments

Comments
 (0)