From 17bca14c4b0e707fc1e847d3a71e64042fc4ee5c Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Tue, 1 Sep 2020 13:24:41 -0400 Subject: [PATCH] REFACTOR: Remove `_.sortBy` --- .../admin/components/themes-list.js | 23 +++++++++++-------- .../discourse/app/controllers/badges/index.js | 22 +++++++++--------- .../app/mixins/user-fields-validation.js | 6 ++--- .../discourse/app/models/category.js | 4 +--- 4 files changed, 28 insertions(+), 27 deletions(-) diff --git a/app/assets/javascripts/admin/components/themes-list.js b/app/assets/javascripts/admin/components/themes-list.js index 153e9ae5b8b..d9434e56cdd 100644 --- a/app/assets/javascripts/admin/components/themes-list.js +++ b/app/assets/javascripts/admin/components/themes-list.js @@ -52,16 +52,19 @@ export default Component.extend({ if (this.componentsTabActive) { return themes.filter(theme => theme.get("parent_themes.length") > 0); } else { - themes = themes.filter( - theme => theme.get("user_selectable") || theme.get("default") - ); - return _.sortBy(themes, t => { - return [ - !t.get("default"), - !t.get("user_selectable"), - t.get("name").toLowerCase() - ]; - }); + return themes + .filter(theme => theme.get("user_selectable") || theme.get("default")) + .sort((a, b) => { + if (a.get("default") && !b.get("default")) { + return -1; + } else if (b.get("default")) { + return 1; + } + return a + .get("name") + .toLowerCase() + .localeCompare(b.get("name").toLowerCase()); + }); } }, diff --git a/app/assets/javascripts/discourse/app/controllers/badges/index.js b/app/assets/javascripts/discourse/app/controllers/badges/index.js index e0564017035..15b699e8d51 100644 --- a/app/assets/javascripts/discourse/app/controllers/badges/index.js +++ b/app/assets/javascripts/discourse/app/controllers/badges/index.js @@ -1,20 +1,20 @@ import discourseComputed from "discourse-common/utils/decorators"; import Controller from "@ember/controller"; +function badgeKey(badge) { + let pos = badge.get("badge_grouping.position"); + let type = badge.get("badge_type_id"); + let name = badge.get("name"); + return ("000" + pos).slice(-4) + (10 - type) + name; +} + export default Controller.extend({ @discourseComputed("model") badgeGroups(model) { - var sorted = _.sortBy(model, function(badge) { - var pos = badge.get("badge_grouping.position"); - var type = badge.get("badge_type_id"); - var name = badge.get("name"); - - return ("000" + pos).slice(-4) + (10 - type) + name; - }); - - var grouped = []; - var group = [], - groupId; + let sorted = model.sort((a, b) => badgeKey(a).localeCompare(badgeKey(b))); + let grouped = []; + let group = []; + let groupId; sorted.forEach(function(badge) { if (groupId !== badge.badge_grouping_id) { diff --git a/app/assets/javascripts/discourse/app/mixins/user-fields-validation.js b/app/assets/javascripts/discourse/app/mixins/user-fields-validation.js index 46051a9e500..09c11e20663 100644 --- a/app/assets/javascripts/discourse/app/mixins/user-fields-validation.js +++ b/app/assets/javascripts/discourse/app/mixins/user-fields-validation.js @@ -13,9 +13,9 @@ export default Mixin.create({ let userFields = this.site.get("user_fields"); if (userFields) { - userFields = _.sortBy(userFields, "position").map(function(f) { - return EmberObject.create({ value: null, field: f }); - }); + userFields = userFields + .sortBy("position") + .map(f => EmberObject.create({ value: null, field: f })); } this.set("userFields", userFields); }, diff --git a/app/assets/javascripts/discourse/app/models/category.js b/app/assets/javascripts/discourse/app/models/category.js index 049a1bb18f7..635518887f5 100644 --- a/app/assets/javascripts/discourse/app/models/category.js +++ b/app/assets/javascripts/discourse/app/models/category.js @@ -544,9 +544,7 @@ Category.reopenClass({ } } - return _.sortBy(data, category => { - return category.get("read_restricted"); - }); + return data.sortBy("read_restricted"); } });