Skip to content

Commit 0fa0066

Browse files
committed
tech(lodash): began migration work
1 parent 2146e69 commit 0fa0066

35 files changed

+62
-6854
lines changed

bower.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
],
1515
"dependencies": {
1616
"jquery": "3.1.0",
17+
"lodash": "~4.15.0",
1718
"angular": "1.5.3",
1819
"angular-route": "1.5.3",
1920
"angular-mocks": "1.5.3",

public/app/core/directives/metric_segment.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ function (_, $, coreModule) {
4040
}
4141

4242
$scope.$apply(function() {
43-
var selected = _.findWhere($scope.altSegments, { value: value });
43+
var selected = _.find($scope.altSegments, {value: value});
4444
if (selected) {
4545
segment.value = selected.value;
4646
segment.html = selected.html;
@@ -174,7 +174,7 @@ function (_, $, coreModule) {
174174
pre: function postLink($scope, elem, attrs) {
175175

176176
$scope.valueToSegment = function(value) {
177-
var option = _.findWhere($scope.options, {value: value});
177+
var option = _.find($scope.options, {value: value});
178178
var segment = {
179179
cssClass: attrs.cssClass,
180180
custom: attrs.custom,
@@ -196,7 +196,7 @@ function (_, $, coreModule) {
196196

197197
$scope.onSegmentChange = function() {
198198
if ($scope.options) {
199-
var option = _.findWhere($scope.options, {text: $scope.segment.value});
199+
var option = _.find($scope.options, {text: $scope.segment.value});
200200
if (option && option.value !== $scope.property) {
201201
$scope.property = option.value;
202202
} else if (attrs.custom !== 'false') {

public/app/core/directives/value_select_dropdown.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ function (angular, _, coreModule) {
5151
});
5252

5353
// convert values to text
54-
var currentTexts = _.pluck(selectedAndNotInTag, 'text');
54+
var currentTexts = _.map(selectedAndNotInTag, 'text');
5555

5656
// join texts
5757
vm.linkText = currentTexts.join(' + ');
@@ -167,16 +167,16 @@ function (angular, _, coreModule) {
167167
_.each(vm.tags, function(tag) {
168168
if (tag.selected) {
169169
_.each(tag.values, function(value) {
170-
if (!_.findWhere(vm.selectedValues, {value: value})) {
170+
if (!_.find(vm.selectedValues, {value: value})) {
171171
tag.selected = false;
172172
}
173173
});
174174
}
175175
});
176176

177177
vm.selectedTags = _.filter(vm.tags, {selected: true});
178-
vm.variable.current.value = _.pluck(vm.selectedValues, 'value');
179-
vm.variable.current.text = _.pluck(vm.selectedValues, 'text').join(' + ');
178+
vm.variable.current.value = _.map(vm.selectedValues, 'value');
179+
vm.variable.current.text = _.map(vm.selectedValues, 'text').join(' + ');
180180
vm.variable.current.tags = vm.selectedTags;
181181

182182
if (!vm.variable.multi) {

public/app/core/utils/datemath.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ export function parseDateMath(mathString, time, roundUp?) {
9393
}
9494
unit = mathString.charAt(i++);
9595

96-
if (!_.contains(units, unit)) {
96+
if (!_.includes(units, unit)) {
9797
return undefined;
9898
} else {
9999
if (type === 0) {

public/app/features/admin/adminEditUserCtrl.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,20 +81,20 @@ function (angular, _) {
8181

8282
$scope.searchOrgs = function(queryStr, callback) {
8383
if ($scope.orgsSearchCache.length > 0) {
84-
callback(_.pluck($scope.orgsSearchCache, "name"));
84+
callback(_.map($scope.orgsSearchCache, "name"));
8585
return;
8686
}
8787

8888
backendSrv.get('/api/orgs', {query: ''}).then(function(result) {
8989
$scope.orgsSearchCache = result;
90-
callback(_.pluck(result, "name"));
90+
callback(_.map(result, "name"));
9191
});
9292
};
9393

9494
$scope.addOrgUser = function() {
9595
if (!$scope.addOrgForm.$valid) { return; }
9696

97-
var orgInfo = _.findWhere($scope.orgsSearchCache, {name: $scope.newOrg.name});
97+
var orgInfo = _.find($scope.orgsSearchCache, {name: $scope.newOrg.name});
9898
if (!orgInfo) { return; }
9999

100100
$scope.newOrg.loginOrEmail = $scope.user.login;

public/app/features/alerting/alert_tab_ctrl.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export class AlertTabCtrl {
6868
this.notifications = res;
6969

7070
_.each(this.alert.notifications, item => {
71-
var model = _.findWhere(this.notifications, {id: item.id});
71+
var model = _.find(this.notifications, {id: item.id});
7272
if (model) {
7373
model.iconClass = this.getNotificationIcon(model.type);
7474
this.alertNotifications.push(model);
@@ -123,7 +123,7 @@ export class AlertTabCtrl {
123123
}
124124

125125
notificationAdded() {
126-
var model = _.findWhere(this.notifications, {name: this.addNotificationSegment.value});
126+
var model = _.find(this.notifications, {name: this.addNotificationSegment.value});
127127
if (!model) {
128128
return;
129129
}

public/app/features/annotations/annotations_srv.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export class AnnotationsSrv {
6565
return this.globalAnnotationsPromise;
6666
}
6767

68-
var annotations = _.where(dashboard.annotations.list, {enable: true});
68+
var annotations = _.filter(dashboard.annotations.list, {enable: true});
6969
var range = this.timeSrv.timeRange();
7070

7171
this.globalAnnotationsPromise = this.$q.all(_.map(annotations, annotation => {

public/app/features/dashboard/dashboardSrv.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ function (angular, $, _, moment) {
298298

299299
if (oldVersion < 6) {
300300
// move pulldowns to new schema
301-
var annotations = _.findWhere(old.pulldowns, { type: 'annotations' });
301+
var annotations = _.find(old.pulldowns, { type: 'annotations' });
302302

303303
if (annotations) {
304304
this.annotations = {
@@ -328,7 +328,7 @@ function (angular, $, _, moment) {
328328
if (!target.refId) {
329329
target.refId = this.getNextQueryLetter(panel);
330330
}
331-
}, this);
331+
}.bind(this));
332332
});
333333
}
334334

public/app/features/dashboard/dynamic_dashboard_srv.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ export class DynamicDashboardSrv {
106106
// returns a new row clone or reuses a clone from previous iteration
107107
repeatRow(row, rowIndex) {
108108
var variables = this.dashboard.templating.list;
109-
var variable = _.findWhere(variables, {name: row.repeat});
109+
var variable = _.find(variables, {name: row.repeat});
110110
if (!variable) {
111111
return;
112112
}
@@ -167,7 +167,7 @@ export class DynamicDashboardSrv {
167167

168168
repeatPanel(panel, row) {
169169
var variables = this.dashboard.templating.list;
170-
var variable = _.findWhere(variables, {name: panel.repeat});
170+
var variable = _.find(variables, {name: panel.repeat});
171171
if (!variable) { return; }
172172

173173
var selected;

public/app/features/dashboard/rowCtrl.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ function (angular, _, config) {
129129
});
130130

131131
scope.onAppEvent('panel-fullscreen-enter', function(evt, info) {
132-
var hasPanel = _.findWhere(scope.row.panels, {id: info.panelId});
132+
var hasPanel = _.find(scope.row.panels, {id: info.panelId});
133133
if (!hasPanel) {
134134
element.hide();
135135
}

public/app/features/dashboard/specs/exporter_specs.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,36 +102,36 @@ describe('given dashboard with repeated panels', function() {
102102
});
103103

104104
it('should add datasource to required', function() {
105-
var require = _.findWhere(exported.__requires, {name: 'TestDB'});
105+
var require = _.find(exported.__requires, {name: 'TestDB'});
106106
expect(require.name).to.be("TestDB");
107107
expect(require.id).to.be("testdb");
108108
expect(require.type).to.be("datasource");
109109
expect(require.version).to.be("1.2.1");
110110
});
111111

112112
it('should add panel to required', function() {
113-
var require = _.findWhere(exported.__requires, {name: 'Graph'});
113+
var require = _.find(exported.__requires, {name: 'Graph'});
114114
expect(require.name).to.be("Graph");
115115
expect(require.id).to.be("graph");
116116
expect(require.version).to.be("1.1.0");
117117
});
118118

119119
it('should add grafana version', function() {
120-
var require = _.findWhere(exported.__requires, {name: 'Grafana'});
120+
var require = _.find(exported.__requires, {name: 'Grafana'});
121121
expect(require.type).to.be("grafana");
122122
expect(require.id).to.be("grafana");
123123
expect(require.version).to.be("3.0.2");
124124
});
125125

126126
it('should add constant template variables as inputs', function() {
127-
var input = _.findWhere(exported.__inputs, {name: 'VAR_PREFIX'});
127+
var input = _.find(exported.__inputs, {name: 'VAR_PREFIX'});
128128
expect(input.type).to.be("constant");
129129
expect(input.label).to.be("prefix");
130130
expect(input.value).to.be("collectd");
131131
});
132132

133133
it('should templatize constant variables', function() {
134-
var variable = _.findWhere(exported.templating.list, {name: 'prefix'});
134+
var variable = _.find(exported.templating.list, {name: 'prefix'});
135135
expect(variable.query).to.be("${VAR_PREFIX}");
136136
expect(variable.current.text).to.be("${VAR_PREFIX}");
137137
expect(variable.current.value).to.be("${VAR_PREFIX}");

public/app/features/dashboard/unsavedChangesSrv.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ function(angular, _) {
111111
this.cleanDashboardFromIgnoredChanges(current);
112112
this.cleanDashboardFromIgnoredChanges(original);
113113

114-
var currentTimepicker = _.findWhere(current.nav, { type: 'timepicker' });
115-
var originalTimepicker = _.findWhere(original.nav, { type: 'timepicker' });
114+
var currentTimepicker = _.find(current.nav, { type: 'timepicker' });
115+
var originalTimepicker = _.find(original.nav, { type: 'timepicker' });
116116

117117
if (currentTimepicker && originalTimepicker) {
118118
currentTimepicker.now = originalTimepicker.now;

public/app/features/panel/metrics_ds_selector.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export class MetricsDsSelectorCtrl {
7777
}
7878

7979
datasourceChanged() {
80-
var ds = _.findWhere(this.datasources, {name: this.dsSegment.value});
80+
var ds = _.find(this.datasources, {name: this.dsSegment.value});
8181
if (ds) {
8282
this.current = ds;
8383
this.panelCtrl.setDatasource(ds);

public/app/features/panellinks/module.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ function (angular, _) {
4141

4242
$scope.dashboardChanged = function(link) {
4343
backendSrv.search({query: link.dashboard}).then(function(hits) {
44-
var dashboard = _.findWhere(hits, {title: link.dashboard});
44+
var dashboard = _.find(hits, {title: link.dashboard});
4545
if (dashboard) {
4646
link.dashUri = dashboard.uri;
4747
link.title = dashboard.title;

public/app/features/playlist/playlist_edit_ctrl.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ export class PlaylistEditCtrl {
3636

3737
filterFoundPlaylistItems() {
3838
this.filteredDashboards = _.reject(this.dashboardresult, (playlistItem) => {
39-
return _.findWhere(this.playlistItems, (listPlaylistItem) => {
39+
return _.find(this.playlistItems, (listPlaylistItem) => {
4040
return parseInt(listPlaylistItem.value) === playlistItem.id;
4141
});
4242
});
4343

4444
this.filteredTags = _.reject(this.tagresult, (tag) => {
45-
return _.findWhere(this.playlistItems, (listPlaylistItem) => {
45+
return _.find(this.playlistItems, (listPlaylistItem) => {
4646
return listPlaylistItem.value === tag.term;
4747
});
4848
});

public/app/features/plugins/ds_edit_ctrl.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export class DataSourceEditCtrl {
8181
this.hasDashboards = false;
8282
return this.backendSrv.get('/api/plugins/' + this.current.type + '/settings').then(pluginInfo => {
8383
this.datasourceMeta = pluginInfo;
84-
this.hasDashboards = _.findWhere(pluginInfo.includes, {type: 'dashboard'});
84+
this.hasDashboards = _.find(pluginInfo.includes, {type: 'dashboard'});
8585
});
8686
}
8787

public/app/features/plugins/plugin_edit_ctrl.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export class PluginEditCtrl {
5151
this.tabIndex = 1;
5252
this.tabs.push('Config');
5353

54-
this.hasDashboards = _.findWhere(result.includes, {type: 'dashboard'});
54+
this.hasDashboards = _.find(result.includes, {type: 'dashboard'});
5555
if (this.hasDashboards) {
5656
this.tabs.push('Dashboards');
5757
}

public/app/features/plugins/plugin_page_ctrl.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export class AppPageCtrl {
2424

2525
initPage(app) {
2626
this.appModel = app;
27-
this.page = _.findWhere(app.includes, {slug: this.$routeParams.slug});
27+
this.page = _.find(app.includes, {slug: this.$routeParams.slug});
2828
this.appLogoUrl = app.info.logos.small;
2929

3030
pluginInfoCache[this.pluginId] = app;

public/app/features/templating/editorCtrl.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ function (angular, _) {
102102
return false;
103103
}
104104

105-
var sameName = _.findWhere($scope.variables, { name: $scope.current.name });
105+
var sameName = _.find($scope.variables, { name: $scope.current.name });
106106
if (sameName && sameName !== $scope.current) {
107107
$scope.appEvent('alert-warning', ['Validation', 'Variable with the same name already exists']);
108108
return false;

public/app/features/templating/templateValuesSrv.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function (angular, _, $, kbn) {
1919
$rootScope.onAppEvent('refresh', function() {
2020

2121
// look for interval variables
22-
var intervalVariable = _.findWhere(self.variables, { type: 'interval' });
22+
var intervalVariable = _.find(self.variables, { type: 'interval' });
2323
if (intervalVariable) {
2424
self.updateAutoInterval(intervalVariable);
2525
}
@@ -290,7 +290,7 @@ function (angular, _, $, kbn) {
290290

291291
return self.setVariableValue(variable, selected, false);
292292
} else {
293-
var currentOption = _.findWhere(variable.options, {text: variable.current.text});
293+
var currentOption = _.find(variable.options, {text: variable.current.text});
294294
if (currentOption) {
295295
return self.setVariableValue(variable, currentOption, false);
296296
} else {
@@ -372,8 +372,8 @@ function (angular, _, $, kbn) {
372372

373373
options.push({text: text, value: value});
374374
}
375-
options = _.uniq(options, 'value');
376375

376+
options = _.uniq(options, 'value');
377377
return this.sortVariableValues(options, variable.sort);
378378
};
379379

public/app/plugins/datasource/cloudwatch/datasource.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ function (angular, _, moment, dateMath, CloudWatchAnnotationQuery) {
220220
return this.performEC2DescribeInstances(region, filters, null).then(function(result) {
221221
var attributes = _.chain(result.Reservations)
222222
.map(function(reservations) {
223-
return _.pluck(reservations.Instances, targetAttributeName);
223+
return _.map(reservations.Instances, targetAttributeName);
224224
})
225225
.flatten().uniq().sortBy().value();
226226
return transformSuggestData(attributes);

public/app/plugins/datasource/elasticsearch/config_ctrl.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export class ElasticConfigCtrl {
2727
];
2828

2929
indexPatternTypeChanged() {
30-
var def = _.findWhere(this.indexPatternTypes, {value: this.current.jsonData.interval});
30+
var def = _.find(this.indexPatternTypes, {value: this.current.jsonData.interval});
3131
this.current.database = def.example || 'es-index-name';
3232
}
3333
}

public/app/plugins/datasource/elasticsearch/elastic_response.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ function (_, queryDef) {
149149
var maxDepth = target.bucketAggs.length-1;
150150

151151
for (aggId in aggs) {
152-
aggDef = _.findWhere(target.bucketAggs, {id: aggId});
152+
aggDef = _.find(target.bucketAggs, {id: aggId});
153153
esAgg = aggs[aggId];
154154

155155
if (!aggDef) {
@@ -178,9 +178,9 @@ function (_, queryDef) {
178178
};
179179

180180
ElasticResponse.prototype._getMetricName = function(metric) {
181-
var metricDef = _.findWhere(queryDef.metricAggTypes, {value: metric});
181+
var metricDef = _.find(queryDef.metricAggTypes, {value: metric});
182182
if (!metricDef) {
183-
metricDef = _.findWhere(queryDef.extendedStats, {value: metric});
183+
metricDef = _.find(queryDef.extendedStats, {value: metric});
184184
}
185185

186186
return metricDef ? metricDef.text : metric;
@@ -205,7 +205,7 @@ function (_, queryDef) {
205205
}
206206

207207
if (series.field && queryDef.isPipelineAgg(series.metric)) {
208-
var appliedAgg = _.findWhere(target.metrics, { id: series.field });
208+
var appliedAgg = _.find(target.metrics, { id: series.field });
209209
if (appliedAgg) {
210210
metricName += ' ' + queryDef.describeMetric(appliedAgg);
211211
} else {
@@ -233,8 +233,8 @@ function (_, queryDef) {
233233
};
234234

235235
ElasticResponse.prototype.nameSeries = function(seriesList, target) {
236-
var metricTypeCount = _.uniq(_.pluck(seriesList, 'metric')).length;
237-
var fieldNameCount = _.uniq(_.pluck(seriesList, 'field')).length;
236+
var metricTypeCount = _.uniq(_.map(seriesList, 'metric')).length;
237+
var fieldNameCount = _.uniq(_.map(seriesList, 'field')).length;
238238

239239
for (var i = 0; i < seriesList.length; i++) {
240240
var series = seriesList[i];
@@ -270,7 +270,7 @@ function (_, queryDef) {
270270
};
271271

272272
ElasticResponse.prototype.trimDatapoints = function(aggregations, target) {
273-
var histogram = _.findWhere(target.bucketAggs, { type: 'date_histogram'});
273+
var histogram = _.find(target.bucketAggs, { type: 'date_histogram'});
274274

275275
var shouldDropFirstAndLast = histogram && histogram.settings && histogram.settings.trimEdges;
276276
if (shouldDropFirstAndLast) {

0 commit comments

Comments
 (0)