A platform for community discussion. Free, open, simple.
FIX: ensures composer is not pre-filled with none/all tags (#16998)
Joffrey JAFFEUX42683d48741c
diff --git a/app/assets/javascripts/discourse/app/routes/tag-show.js b/app/assets/javascripts/discourse/app/routes/tag-show.jsindex 47d5740d2c0..19d5f8cb745 100644--- a/app/assets/javascripts/discourse/app/routes/tag-show.js+++ b/app/assets/javascripts/discourse/app/routes/tag-show.js@@ -18,6 +18,9 @@ import { setTopicList } from "discourse/lib/topic-list-tracker";import showModal from "discourse/lib/show-modal";import { action } from "@ember/object";+const NONE = "none";+const ALL = "all";+export default DiscourseRoute.extend(FilterModeMixin, {navMode: "latest",@@ -52,7 +55,7 @@ export default DiscourseRoute.extend(FilterModeMixin, {const filterType = this.navMode.split("/")[0];let tagNotification;- if (tag && tag.id !== "none" && this.currentUser) {+ if (tag && tag.id !== NONE && this.currentUser) {// If logged in, we should get the tag's user settingstagNotification = await this.store.find("tagNotification",@@ -68,7 +71,7 @@ export default DiscourseRoute.extend(FilterModeMixin, {{});const topicFilter = this.navMode;- const tagId = tag ? tag.id.toLowerCase() : "none";+ const tagId = tag ? tag.id.toLowerCase() : NONE;let filter;if (category) {@@ -76,7 +79,7 @@ export default DiscourseRoute.extend(FilterModeMixin, {filter = `tags/c/${Category.slugFor(category)}/${category.id}`;if (this.noSubcategories !== undefined) {- filter += this.noSubcategories ? "/none" : "/all";+ filter += this.noSubcategories ? `/${NONE}` : `/${ALL}`;}filter += `/${tagId}/l/${topicFilter}`;@@ -122,7 +125,7 @@ export default DiscourseRoute.extend(FilterModeMixin, {setupController(controller, model) {const noSubcategories =this.noSubcategories === undefined- ? model.category?.default_list_filter === "none"+ ? model.category?.default_list_filter === NONE: this.noSubcategories;this.controllerFor("tag.show").setProperties({@@ -196,13 +199,7 @@ export default DiscourseRoute.extend(FilterModeMixin, {// Pre-fill the tags input fieldif (composerController.canEditTags && controller.tag?.id) {const composerModel = this.controllerFor("composer").model;- composerModel.set(- "tags",- [- controller.get("model.id"),- ...makeArray(controller.additionalTags),- ].filter(Boolean)- );+ composerModel.set("tags", this._controllerTags(controller));}});}@@ -242,4 +239,10 @@ export default DiscourseRoute.extend(FilterModeMixin, {this.controllerFor("tag.show")._showFooter();return true;},++ _controllerTags(controller) {+ return [controller.get("model.id"), ...makeArray(controller.additionalTags)]+ .filter(Boolean)+ .filter((tag) => ![NONE, ALL].includes(tag));+ },});diff --git a/app/assets/javascripts/discourse/tests/acceptance/tags-test.js b/app/assets/javascripts/discourse/tests/acceptance/tags-test.jsindex 1d98b43a3f7..a4e898d48a5 100644--- a/app/assets/javascripts/discourse/tests/acceptance/tags-test.js+++ b/app/assets/javascripts/discourse/tests/acceptance/tags-test.js@@ -567,6 +567,66 @@ acceptance(});+acceptance("Tag show - create topic", function (needs) {+ needs.user();+ needs.site({ can_tag_topics: true });+ needs.settings({+ tagging_enabled: true,+ tags_listed_by_group: true,+ });+ needs.pretender((server, helper) => {+ server.get("/tag/:tag_name/notifications", (request) => {+ return helper.response({+ tag_notification: {+ id: request.params.tag_name,+ notification_level: 1,+ },+ });+ });+ server.get("/tag/:tag_name/l/latest.json", (request) => {+ return helper.response({+ users: [],+ primary_groups: [],+ topic_list: {+ can_create_topic: true,+ draft: null,+ draft_key: "new_topic",+ draft_sequence: 1,+ per_page: 30,+ tags: [+ {+ id: 1,+ name: request.params.tag_name,+ topic_count: 1,+ },+ ],+ topics: [],+ },+ });+ });+ });++ test("composer will not set tags with all/none tags when creating topic", async function (assert) {+ const composer = this.owner.lookup("controller:composer");++ await visit("/tag/none");+ await click("#create-topic");+ assert.deepEqual(composer.model.tags, []);++ await visit("/tag/all");+ await click("#create-topic");+ assert.deepEqual(composer.model.tags, []);+ });++ test("composer will set tags from selected tag", async function (assert) {+ const composer = this.owner.lookup("controller:composer");++ await visit("/tag/planters");+ await click("#create-topic");+ assert.deepEqual(composer.model.tags, ["planters"]);+ });+});+acceptance("Tag show - topic list without `more_topics_url`", function (needs) {needs.pretender((server, helper) => {server.get("/tag/:tagName/l/latest.json", () =>