From 712e171b34fa6376fc68705b47a53c01e9a8ed33 Mon Sep 17 00:00:00 2001 From: Daniel Waterworth Date: Mon, 2 Dec 2019 12:08:01 +0000 Subject: [PATCH] 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. --- .../templates/components/bread-crumbs.hbs | 3 +- .../select-kit/components/tag-drop.js.es6 | 28 +++++++++++++++++-- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/app/assets/javascripts/discourse/templates/components/bread-crumbs.hbs b/app/assets/javascripts/discourse/templates/components/bread-crumbs.hbs index 9f41a5d160d..e15d265a6b3 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 66d662be700..601398eb40a 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");