UX: Sort categories alphabetically in Sidebar (#17958)

This commit is contained in:
Alan Guo Xiang Tan 2022-08-17 12:39:02 +08:00 committed by GitHub
parent 4657110c35
commit f7ed09a02c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 9 deletions

View File

@ -337,16 +337,18 @@ const User = RestModel.extend({
return []; return [];
} }
return Site.current().categoriesList.filter((category) => { return Site.current()
if ( .categoriesList.filter((category) => {
this.siteSettings.suppress_uncategorized_badge && if (
category.isUncategorizedCategory this.siteSettings.suppress_uncategorized_badge &&
) { category.isUncategorizedCategory
return false; ) {
} return false;
}
return sidebarCategoryIds.includes(category.id); return sidebarCategoryIds.includes(category.id);
}); })
.sort((a, b) => a.name.localeCompare(b.name));
}, },
changeUsername(new_username) { changeUsername(new_username) {

View File

@ -7,6 +7,7 @@ import {
exists, exists,
publishToMessageBus, publishToMessageBus,
query, query,
queryAll,
updateCurrentUser, updateCurrentUser,
} from "discourse/tests/helpers/qunit-helpers"; } from "discourse/tests/helpers/qunit-helpers";
@ -149,6 +150,32 @@ acceptance("Sidebar - Categories Section", function (needs) {
); );
}); });
test("category section links are sorted by category name alphabetically", async function (assert) {
const { category1, category2, category3 } = setupUserSidebarCategories();
category3.set("name", "aBC");
category2.set("name", "abc");
category1.set("name", "efg");
await visit("/");
const categorySectionLinks = queryAll(
".sidebar-section-categories .sidebar-section-link"
);
const categoryNames = [];
categorySectionLinks.each((_index, categorySectionLink) => {
categoryNames.push(categorySectionLink.textContent.trim());
});
assert.deepEqual(
categoryNames,
["abc", "aBC", "efg"],
"category section links are displayed in the right order"
);
});
test("category section links", async function (assert) { test("category section links", async function (assert) {
const { category1, category2, category3 } = setupUserSidebarCategories(); const { category1, category2, category3 } = setupUserSidebarCategories();