Skip to content

A platform for community discussion. Free, open, simple.

UX: Sort tags alphabetically in sidebar (#17959)

Alan Guo Xiang Tan97a20d6d8244
diff --git a/app/assets/javascripts/discourse/app/models/user.js b/app/assets/javascripts/discourse/app/models/user.js
index 0ac0c2d46ff..64b1077a98b 100644
--- a/app/assets/javascripts/discourse/app/models/user.js
+++ b/app/assets/javascripts/discourse/app/models/user.js
@@ -320,13 +320,9 @@ const User = RestModel.extend({
return [];
}
- if (this.siteSettings.tags_sort_alphabetically) {
- return sidebarTags.sort((a, b) => {
- return a.name.localeCompare(b);
- });
- } else {
- return sidebarTags;
- }
+ return sidebarTags.sort((a, b) => {
+ return a.name.localeCompare(b.name);
+ });
},
sidebarTagNames: mapBy("sidebarTags", "name"),
diff --git a/app/assets/javascripts/discourse/tests/acceptance/sidebar-tags-section-test.js b/app/assets/javascripts/discourse/tests/acceptance/sidebar-tags-section-test.js
index c70e71b0f47..cc5b0924a8a 100644
--- a/app/assets/javascripts/discourse/tests/acceptance/sidebar-tags-section-test.js
+++ b/app/assets/javascripts/discourse/tests/acceptance/sidebar-tags-section-test.js
@@ -7,6 +7,7 @@ import {
exists,
publishToMessageBus,
query,
+ queryAll,
updateCurrentUser,
} from "discourse/tests/helpers/qunit-helpers";
import discoveryFixture from "discourse/tests/fixtures/discovery-fixtures";
@@ -43,16 +44,16 @@ acceptance("Sidebar - Tags section", function (needs) {
watched_tags: ["tag2", "tag3"],
watching_first_post_tags: [],
sidebar_tags: [
- { name: "tag1", pm_only: false },
{ name: "tag2", pm_only: false },
- {
- name: "tag3",
- pm_only: false,
- },
+ { name: "tag1", pm_only: false },
{
name: "tag4",
pm_only: true,
},
+ {
+ name: "tag3",
+ pm_only: false,
+ },
],
});
@@ -126,6 +127,26 @@ acceptance("Sidebar - Tags section", function (needs) {
);
});
+ test("tag section links are sorted alphabetically by tag's name", async function (assert) {
+ await visit("/");
+
+ const tagSectionLinks = queryAll(
+ ".sidebar-section-tags .sidebar-section-link"
+ );
+
+ const tagNames = [];
+
+ tagSectionLinks.each((_index, tagSectionLink) => {
+ tagNames.push(tagSectionLink.textContent.trim());
+ });
+
+ assert.deepEqual(
+ tagNames,
+ ["tag1", "tag2", "tag3", "tag4"],
+ "tag section links are displayed in the right order"
+ );
+ });
+
test("tag section links for user", async function (assert) {
await visit("/");