Skip to content

Commit eafe0d6

Browse files
committed
fix(templating): fixed issue when adding template variable, fixes grafana#6622
1 parent 196fdbf commit eafe0d6

File tree

12 files changed

+17
-21
lines changed

12 files changed

+17
-21
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* **Graph Panel**: Bar width if bars was only used in series override, [#6528](https://github.com/grafana/grafana/issues/6528)
66
* **UI/Browser**: Fixed issue with page/view header gradient border not showing in Safari, [#6530](https://github.com/grafana/grafana/issues/6530)
77
* **UX**: Panel Drop zone visible after duplicating panel, and when entering fullscreen/edit view, [#6598](https://github.com/grafana/grafana/issues/6598)
8+
* **Templating**: Newly added variable was not visible directly only after dashboard reload, [#6622](https://github.com/grafana/grafana/issues/6622)
89

910
### Enhancements
1011
* **Singlestat**: Support repeated template variables in prefix/postfix [#6595](https://github.com/grafana/grafana/issues/6595)

public/app/features/dashboard/model.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,19 +98,23 @@ export class DashboardModel {
9898
var events = this.events;
9999
var meta = this.meta;
100100
var rows = this.rows;
101+
var variables = this.templating.list;
102+
101103
delete this.events;
102104
delete this.meta;
103105

104106
// prepare save model
105-
this.rows = _.map(this.rows, row => row.getSaveModel());
106-
events.emit('prepare-save-model');
107+
this.rows = _.map(rows, row => row.getSaveModel());
108+
this.templating.list = _.map(variables, variable => variable.getSaveModel());
107109

108110
var copy = $.extend(true, {}, this);
109111

110112
// restore properties
111113
this.events = events;
112114
this.meta = meta;
113115
this.rows = rows;
116+
this.templating.list = variables;
117+
114118
return copy;
115119
}
116120

public/app/features/templating/adhoc_variable.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export class AdhocVariable implements Variable {
2626
return Promise.resolve();
2727
}
2828

29-
getModel() {
29+
getSaveModel() {
3030
assignModelProperties(this.model, this, this.defaults);
3131
return this.model;
3232
}

public/app/features/templating/constant_variable.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export class ConstantVariable implements Variable {
2424
assignModelProperties(this, model, this.defaults);
2525
}
2626

27-
getModel() {
27+
getSaveModel() {
2828
assignModelProperties(this.model, this, this.defaults);
2929
return this.model;
3030
}

public/app/features/templating/custom_variable.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export class CustomVariable implements Variable {
3434
return this.variableSrv.setOptionAsCurrent(this, option);
3535
}
3636

37-
getModel() {
37+
getSaveModel() {
3838
assignModelProperties(this.model, this, this.defaults);
3939
return this.model;
4040
}

public/app/features/templating/datasource_variable.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export class DatasourceVariable implements Variable {
3030
this.refresh = 1;
3131
}
3232

33-
getModel() {
33+
getSaveModel() {
3434
assignModelProperties(this.model, this, this.defaults);
3535
return this.model;
3636
}

public/app/features/templating/interval_variable.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export class IntervalVariable implements Variable {
3434
this.refresh = 2;
3535
}
3636

37-
getModel() {
37+
getSaveModel() {
3838
assignModelProperties(this.model, this, this.defaults);
3939
return this.model;
4040
}

public/app/features/templating/partials/editor.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ <h5 class="section-heading">Interval Options</h5>
136136
<div ng-if="current.type === 'custom'" class="gf-form-group">
137137
<h5 class="section-heading">Custom Options</h5>
138138
<div class="gf-form">
139-
<span class="gf-form-label width-13">Values separated by comma</span>
139+
<span class="gf-form-label width-14">Values separated by comma</span>
140140
<input type="text" class="gf-form-input" ng-model='current.query' ng-blur="runQuery()" placeholder="1, 10, 20, myvalue" required></input>
141141
</div>
142142
</div>

public/app/features/templating/query_variable.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export class QueryVariable implements Variable {
4747
assignModelProperties(this, model, this.defaults);
4848
}
4949

50-
getModel() {
50+
getSaveModel() {
5151
// copy back model properties to model
5252
assignModelProperties(this.model, this, this.defaults);
5353
return this.model;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ describe('QueryVariable', function() {
2525
variable.regex = 'asd';
2626
variable.sort = 50;
2727

28-
var model = variable.getModel();
28+
var model = variable.getSaveModel();
2929
expect(model.options.length).to.be(1);
3030
expect(model.options[0].text).to.be('test');
3131
expect(model.datasource).to.be('google');

0 commit comments

Comments
 (0)