UX: Sort tags alphabetically in sidebar (#17959)

This commit is contained in:
Alan Guo Xiang Tan 2022-08-17 14:47:29 +08:00 committed by GitHub
parent f7ed09a02c
commit 97a20d6d82
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 12 deletions

View File

@ -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"),

View File

@ -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("/");