Skip to content

Commit f6845cd

Browse files
committed
Variable value select fixes and refactorings
1 parent c20fa85 commit f6845cd

File tree

6 files changed

+39
-10
lines changed

6 files changed

+39
-10
lines changed

public/app/directives/all.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ define([
1111
'./spectrumPicker',
1212
'./tags',
1313
'./bodyClass',
14-
'./selectDropDown',
14+
'./valueSelectDropdown',
1515
'./metric.segment',
1616
'./grafanaVersionCheck',
1717
'./dropdown.typeahead',

public/app/directives/selectDropDown.js renamed to public/app/directives/valueSelectDropdown.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ function (angular, app, _) {
99

1010
angular
1111
.module('grafana.controllers')
12-
.controller('SelectDropdownCtrl', function($q) {
12+
.controller('ValueSelectDropdownCtrl', function($q) {
1313
var vm = this;
1414

1515
vm.show = function() {
@@ -31,7 +31,13 @@ function (angular, app, _) {
3131
vm.selectedValues = _.filter(vm.options, {selected: true});
3232

3333
vm.tags = _.map(vm.variable.tags, function(value) {
34-
return { text: value, selected: false };
34+
var tag = { text: value, selected: false };
35+
_.each(vm.variable.current.tags, function(tagObj) {
36+
if (tagObj.text === value) {
37+
tag.selected = true;
38+
}
39+
});
40+
return tag;
3541
});
3642

3743
vm.search = {query: '', options: vm.options};
@@ -225,12 +231,12 @@ function (angular, app, _) {
225231

226232
angular
227233
.module('grafana.directives')
228-
.directive('selectDropdown', function($compile, $window, $timeout) {
234+
.directive('valueSelectDropdown', function($compile, $window, $timeout) {
229235

230236
return {
231237
scope: { variable: "=", onUpdated: "&", getValuesForTag: "&" },
232-
templateUrl: 'app/partials/selectDropdown.html',
233-
controller: 'SelectDropdownCtrl',
238+
templateUrl: 'app/partials/valueSelectDropdown.html',
239+
controller: 'ValueSelectDropdownCtrl',
234240
controllerAs: 'vm',
235241
bindToController: true,
236242
link: function(scope, elem) {

public/app/partials/submenu.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<span class="template-variable tight-form-item" ng-show="!variable.hideLabel" style="padding-right: 5px">
77
{{variable.label || variable.name}}:
88
</span>
9-
<select-dropdown variable="variable" on-updated="variableUpdated(variable)" get-values-for-tag="getValuesForTag(variable, tagKey)"></select-dropdown>
9+
<value-select-dropdown variable="variable" on-updated="variableUpdated(variable)" get-values-for-tag="getValuesForTag(variable, tagKey)"></value-select-dropdown>
1010
</li>
1111
</ul>
1212

public/test/specs/selectDropdownCtrl-specs.js renamed to public/test/specs/valueSelectDropdown-specs.js

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
define([
2-
'directives/variableValueSelect',
2+
'directives/valueSelectDropdown',
33
],
44
function () {
55
'use strict';
@@ -15,7 +15,7 @@ function () {
1515
beforeEach(inject(function($controller, $rootScope, $q) {
1616
rootScope = $rootScope;
1717
scope = $rootScope.$new();
18-
ctrl = $controller('SelectDropdownCtrl', {$scope: scope});
18+
ctrl = $controller('ValueSelectDropdownCtrl', {$scope: scope});
1919
ctrl.getValuesForTag = function(obj) {
2020
return $q.when(tagValuesMap[obj.tagKey]);
2121
};
@@ -134,5 +134,28 @@ function () {
134134
});
135135
});
136136
});
137+
138+
describe("Given variable with selected tags", function() {
139+
beforeEach(function() {
140+
ctrl.variable = {
141+
current: {text: 'server-1', value: 'server-1', tags: [{text: 'key1'}] },
142+
options: [
143+
{text: 'server-1', value: 'server-1'},
144+
{text: 'server-2', value: 'server-2'},
145+
{text: 'server-3', value: 'server-3'},
146+
],
147+
tags: ["key1", "key2", "key3"],
148+
multi: true
149+
};
150+
ctrl.init();
151+
ctrl.show();
152+
});
153+
154+
it("should set tag as selected", function() {
155+
expect(ctrl.tags[0].selected).to.be(true);
156+
});
157+
158+
});
159+
137160
});
138161
});

public/test/test-main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ require([
144144
'specs/singlestat-specs',
145145
'specs/dynamicDashboardSrv-specs',
146146
'specs/unsavedChangesSrv-specs',
147-
'specs/selectDropdownCtrl-specs',
147+
'specs/valueSelectDropdown-specs',
148148
];
149149

150150
var pluginSpecs = (config.plugins.specs || []).map(function (spec) {

0 commit comments

Comments
 (0)