Convert select-kit from es6 to js (#9246)

Convert select-kit from es6 to js (#9246)

  • Convert select-kit from es6 to js

  • Hide more git blames

diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs
index bf208be..cc4b81d 100644
--- a/.git-blame-ignore-revs
+++ b/.git-blame-ignore-revs
@@ -13,3 +13,9 @@ dafd3c3b47f116c6c1dc56cb18df614c11747733
 
 # Rename admin app es6 -> js
 181758e3248b14ad8b53abe063da8dc6a82d3089
+
+# Rename pretty-text from es6 -> js
+c15056650647e8650288f973d9038500dc9cf7bb
+
+# Rename select kit from es6 -> js
+acc5cbdf8ecb9293a0fa9474ee73baf499c02428
diff --git a/app/assets/javascripts/select-kit/components/admin-group-selector.js b/app/assets/javascripts/select-kit/components/admin-group-selector.js
new file mode 100644
index 0000000..1b02a45
--- /dev/null
+++ b/app/assets/javascripts/select-kit/components/admin-group-selector.js
@@ -0,0 +1,9 @@
+import MultiSelectComponent from "select-kit/components/multi-select";
+
+export default MultiSelectComponent.extend({
+  pluginApiIdentifiers: ["admin-group-selector"],
+  classNames: ["admin-group-selector"],
+  selectKitOptions: {
+    allowAny: false
+  }
+});
diff --git a/app/assets/javascripts/select-kit/components/admin-group-selector.js.es6 b/app/assets/javascripts/select-kit/components/admin-group-selector.js.es6
deleted file mode 100644
index 1b02a45..0000000
--- a/app/assets/javascripts/select-kit/components/admin-group-selector.js.es6
+++ /dev/null
@@ -1,9 +0,0 @@
-import MultiSelectComponent from "select-kit/components/multi-select";
-
-export default MultiSelectComponent.extend({
-  pluginApiIdentifiers: ["admin-group-selector"],
-  classNames: ["admin-group-selector"],
-  selectKitOptions: {
-    allowAny: false
-  }
-});
diff --git a/app/assets/javascripts/select-kit/components/categories-admin-dropdown.js b/app/assets/javascripts/select-kit/components/categories-admin-dropdown.js
new file mode 100644
index 0000000..f56b270
--- /dev/null
+++ b/app/assets/javascripts/select-kit/components/categories-admin-dropdown.js
@@ -0,0 +1,38 @@
+import DropdownSelectBoxComponent from "select-kit/components/dropdown-select-box";
+import { computed } from "@ember/object";
+import { setting } from "discourse/lib/computed";
+
+export default DropdownSelectBoxComponent.extend({
+  pluginApiIdentifiers: ["categories-admin-dropdown"],
+  classNames: ["categories-admin-dropdown"],
+  fixedCateoryPositions: setting("fixed_category_positions"),
+
+  selectKitOptions: {
+    icon: "bars",
+    showFullTitle: false,
+    autoFilterable: false,
+    filterable: false
+  },
+
+  content: computed(function() {
+    const items = [
+      {
+        id: "create",
+        name: I18n.t("category.create"),
+        description: I18n.t("category.create_long"),
+        icon: "plus"
+      }
+    ];
+
+    if (this.fixedCateoryPositions) {
+      items.push({
+        id: "reorder",
+        name: I18n.t("categories.reorder.title"),
+        description: I18n.t("categories.reorder.title_long"),
+        icon: "random"
+      });
+    }
+
+    return items;
+  })
+});
diff --git a/app/assets/javascripts/select-kit/components/categories-admin-dropdown.js.es6 b/app/assets/javascripts/select-kit/components/categories-admin-dropdown.js.es6
deleted file mode 100644
index f56b270..0000000
--- a/app/assets/javascripts/select-kit/components/categories-admin-dropdown.js.es6
+++ /dev/null
@@ -1,38 +0,0 @@
-import DropdownSelectBoxComponent from "select-kit/components/dropdown-select-box";
-import { computed } from "@ember/object";
-import { setting } from "discourse/lib/computed";
-
-export default DropdownSelectBoxComponent.extend({
-  pluginApiIdentifiers: ["categories-admin-dropdown"],
-  classNames: ["categories-admin-dropdown"],
-  fixedCateoryPositions: setting("fixed_category_positions"),
-
-  selectKitOptions: {
-    icon: "bars",
-    showFullTitle: false,
-    autoFilterable: false,
-    filterable: false
-  },
-
-  content: computed(function() {
-    const items = [
-      {
-        id: "create",
-        name: I18n.t("category.create"),
-        description: I18n.t("category.create_long"),
-        icon: "plus"
-      }
-    ];
-
-    if (this.fixedCateoryPositions) {
-      items.push({
-        id: "reorder",
-        name: I18n.t("categories.reorder.title"),
-        description: I18n.t("categories.reorder.title_long"),
-        icon: "random"
-      });
-    }
-
-    return items;
-  })
-});
diff --git a/app/assets/javascripts/select-kit/components/category-chooser.js b/app/assets/javascripts/select-kit/components/category-chooser.js
new file mode 100644
index 0000000..76c47a6
--- /dev/null
+++ b/app/assets/javascripts/select-kit/components/category-chooser.js
@@ -0,0 +1,146 @@
+import ComboBoxComponent from "select-kit/components/combo-box";
+import PermissionType from "discourse/models/permission-type";
+import Category from "discourse/models/category";
+import { categoryBadgeHTML } from "discourse/helpers/category-link";
+import { computed, set } from "@ember/object";
+import { isNone } from "@ember/utils";
+import { setting } from "discourse/lib/computed";
+
+export default ComboBoxComponent.extend({
+  pluginApiIdentifiers: ["category-chooser"],
+  classNames: ["category-chooser"],
+  allowUncategorizedTopics: setting("allow_uncategorized_topics"),
+  fixedCategoryPositionsOnCreate: setting("fixed_category_positions_on_create"),
+
+  selectKitOptions: {
+    filterable: true,
+    allowUncategorized: false,
+    allowSubCategories: true,
+    permissionType: PermissionType.FULL,
+    excludeCategoryId: null,
+    scopedCategoryId: null
+  },
+
+  modifyComponentForRow() {
+    return "category-row";
+  },
+
+  modifyNoSelection() {
+    if (!isNone(this.selectKit.options.none)) {
+      const none = this.selectKit.options.none;
+      const isString = typeof none === "string";
+      return this.defaultItem(
+        null,
+        I18n.t(
+          isString ? this.selectKit.options.none : "category.none"
+        ).htmlSafe()
+      );
+    } else if (
+      this.allowUncategorizedTopics ||
+      this.selectKit.options.allowUncategorized
+    ) {
+      return Category.findUncategorized();
+    } else {
+      return this.defaultItem(null, I18n.t("category.choose").htmlSafe());
+    }
+  },
+
+  modifySelection(content) {
+    if (this.selectKit.hasSelection) {
+      const category = Category.findById(this.value);
+
+      set(
+        content,
+        "label",
+        categoryBadgeHTML(category, {
+          link: false,
+          hideParent: category ? !!category.parent_category_id : true,
+          allowUncategorized: true,
+          recursive: true
+        }).htmlSafe()
+      );
+    }
+
+    return content;
+  },
+
+  search(filter) {
+    if (filter) {
+      return this.content.filter(item => {
+        const category = Category.findById(this.getValue(item));
+        const categoryName = this.getName(item);
+
+        if (category && category.parentCategory) {
+          const parentCategoryName = this.getName(category.parentCategory);
+          return (
+            this._matchCategory(filter, categoryName) ||
+            this._matchCategory(filter, parentCategoryName)
+          );
+        } else {
+          return this._matchCategory(filter, categoryName);
+        }
+      });
+    } else {
+      return this.content;
+    }
+  },
+
+  content: computed("selectKit.{filter,options.scopedCategoryId}", function() {
+    if (!this.selectKit.filter && this.selectKit.options.scopedCategoryId) {
+      return this.categoriesByScope(this.selectKit.options.scopedCategoryId);
+    } else {
+      return this.categoriesByScope();
+    }
+  }),
+
+  categoriesByScope(scopedCategoryId = null) {
+    const categories = this.fixedCategoryPositionsOnCreate
+      ? Category.list()
+      : Category.listByActivity();
+
+    if (scopedCategoryId) {
+      const scopedCat = Category.findById(scopedCategoryId);
+      scopedCategoryId = scopedCat.parent_category_id || scopedCat.id;
+    }
+
+    const excludeCategoryId = this.selectKit.options.excludeCategoryId;
+
+    return categories.filter(category => {

[... diff too long, it was truncated ...]

GitHub sha: 07813c4a

This commit appears in #9246 which was merged by eviltrout.