DEV: Don't pass multiple categories to tag-drop

DEV: Don’t pass multiple categories to tag-drop

The tag-drop component uses the passed in categories to calculate paths, but only the last category is relevant, since, from a category we can calculate its ancestors.

diff --git a/app/assets/javascripts/discourse/templates/components/bread-crumbs.hbs b/app/assets/javascripts/discourse/templates/components/bread-crumbs.hbs
index 9f41a5d160..e15d265a6b 100644
--- a/app/assets/javascripts/discourse/templates/components/bread-crumbs.hbs
+++ b/app/assets/javascripts/discourse/templates/components/bread-crumbs.hbs
@@ -14,8 +14,7 @@
 
 {{#if siteSettings.tagging_enabled}}
   {{tag-drop
-    firstCategory=firstCategory
-    secondCategory=secondCategory
+    currentCategory=category
     tagId=tagId}}
 {{/if}}
 
diff --git a/app/assets/javascripts/select-kit/components/tag-drop.js.es6 b/app/assets/javascripts/select-kit/components/tag-drop.js.es6
index 66d662be70..601398eb40 100644
--- a/app/assets/javascripts/select-kit/components/tag-drop.js.es6
+++ b/app/assets/javascripts/select-kit/components/tag-drop.js.es6
@@ -1,4 +1,5 @@
-import { alias, or } from "@ember/object/computed";
+import { computed } from "@ember/object";
+import { alias } from "@ember/object/computed";
 import { makeArray } from "discourse-common/lib/helpers";
 import ComboBoxComponent from "select-kit/components/combo-box";
 import DiscourseURL from "discourse/lib/url";
@@ -6,6 +7,7 @@ import TagsMixin from "select-kit/mixins/tags";
 import { default as discourseComputed } from "discourse-common/utils/decorators";
 const { isEmpty, run } = Ember;
 import Category from "discourse/models/category";
+import deprecated from "discourse-common/lib/deprecated";
 
 export default ComboBoxComponent.extend(TagsMixin, {
   pluginApiIdentifiers: ["tag-drop"],
@@ -17,7 +19,6 @@ export default ComboBoxComponent.extend(TagsMixin, {
   allowAutoSelectFirst: false,
   tagName: "li",
   showFilterByTag: alias("siteSettings.show_filter_by_tag"),
-  currentCategory: or("secondCategory", "firstCategory"),
   tagId: null,
   categoryStyle: alias("siteSettings.category_style"),
   mutateAttributes() {},
@@ -27,6 +28,27 @@ export default ComboBoxComponent.extend(TagsMixin, {
   allowContentReplacement: true,
   isAsync: true,
 
+  currentCategory: computed("secondCategory", "firstCategory", {
+    set(key, value) {
+      this.currentCategoryRaw = value;
+      return value;
+    },
+
+    get() {
+      if (this.currentCategoryRaw) {
+        return this.currentCategoryRaw;
+      }
+
+      const result = this.secondCategory || this.firstCategory;
+      if (result) {
+        deprecated(
+          "Setting firstCategory and secondCategory on tag-drop directly is deprecated. Please use currentCategory instead."
+        );
+        return result;
+      }
+    }
+  }),
+
   @discourseComputed("tagId")
   noTagsSelected() {
     return this.tagId === "none";
@@ -70,7 +92,7 @@ export default ComboBoxComponent.extend(TagsMixin, {
     return tagId ? `tag-${tagId}` : "tag_all";
   },
 
-  @discourseComputed("firstCategory", "secondCategory")
+  @discourseComputed("currentCategory")
   allTagsUrl() {
     if (this.currentCategory) {
       return Discourse.getURL(this.get("currentCategory.url") + "?allTags=1");

GitHub sha: 712e171b

1 Like