You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@trafficcontrol.apache.org by GitBox <gi...@apache.org> on 2020/03/11 17:12:08 UTC
[GitHub] [trafficcontrol] ocket8888 commented on a change in pull request
#4423: Deprecate cachegroup/:id/unassigned_parameters
ocket8888 commented on a change in pull request #4423: Deprecate cachegroup/:id/unassigned_parameters
URL: https://github.com/apache/trafficcontrol/pull/4423#discussion_r391129633
##########
File path: traffic_portal/app/src/common/modules/table/cacheGroupParameters/TableCacheGroupParamsUnassignedController.js
##########
@@ -17,13 +17,15 @@
* under the License.
*/
-var TableCacheGroupParamsUnassignedController = function(cg, parameters, $scope, $uibModalInstance) {
+var TableCacheGroupParamsUnassignedController = function(cg, allParams, assignedParams, $scope, $uibModalInstance) {
var selectedParams = [];
$scope.cg = cg;
- $scope.unassignedParams = parameters;
+ $scope.unassignedParams = _.filter(allParams, function(param) {
+ return !_.find(assignedParams, function(assignedParam) { return assignedParam.id == param.id });
Review comment:
Instead of using `_.find`, consider using the Javascript built-in [`Array.find`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find) method.
Also, though, you could avoid iterating the whole array of assigned params if it's a Set of ids first:
```javascript
// In TableCacheGroupParametersController.js
// ...
assignedParams: function() {
return new Set(parameters.map(x=>x.id));
// I think maybe webpack won't actually handle fat-arrow functions, so might need to do:
// return new Set(parameters.map(function(x){return x.id;}));
}
//...
// now in TableCacheGroupParamsUnassignedController.js
$scope.unassignedParams = allParams.filter(x=>!assignedParams.has(x.id));
// or, if you can't use "fat-arrow" functions:
$scope.unassignedParams = allParams.filter(
function(p) {
return !assignedParams.has(p.id);
}
);
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services