mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: Sidebar categories for anonymous not being sorted by name (#18339)
Sort it by name for now even though we have an on going conversation to decide how categories should be sorted in sidebar https://meta.discourse.org/t/sidebar-categories-are-out-of-order-for-anonymous-users/239679
This commit is contained in:
parent
b515a45cf4
commit
8c7a38449c
@ -1,16 +1,11 @@
|
|||||||
import { cached } from "@glimmer/tracking";
|
|
||||||
import { inject as service } from "@ember/service";
|
import { inject as service } from "@ember/service";
|
||||||
import Component from "@glimmer/component";
|
|
||||||
import CategorySectionLink from "discourse/lib/sidebar/user/categories-section/category-section-link";
|
|
||||||
import { canDisplayCategory } from "discourse/lib/sidebar/helpers";
|
import { canDisplayCategory } from "discourse/lib/sidebar/helpers";
|
||||||
|
import SidebarCommonCategoriesSection from "discourse/components/sidebar/common/categories-section";
|
||||||
|
|
||||||
export default class SidebarAnonymousCategoriesSection extends Component {
|
export default class SidebarAnonymousCategoriesSection extends SidebarCommonCategoriesSection {
|
||||||
@service topicTrackingState;
|
|
||||||
@service site;
|
@service site;
|
||||||
@service siteSettings;
|
|
||||||
|
|
||||||
@cached
|
get categories() {
|
||||||
get sectionLinks() {
|
|
||||||
let categories = this.site.categoriesList;
|
let categories = this.site.categoriesList;
|
||||||
|
|
||||||
if (this.siteSettings.default_sidebar_categories) {
|
if (this.siteSettings.default_sidebar_categories) {
|
||||||
@ -31,11 +26,6 @@ export default class SidebarAnonymousCategoriesSection extends Component {
|
|||||||
.slice(0, 5);
|
.slice(0, 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
return categories.map((category) => {
|
return categories;
|
||||||
return new CategorySectionLink({
|
|
||||||
category,
|
|
||||||
topicTrackingState: this.topicTrackingState,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,29 @@
|
|||||||
|
import Component from "@glimmer/component";
|
||||||
|
import { cached } from "@glimmer/tracking";
|
||||||
|
import { inject as service } from "@ember/service";
|
||||||
|
|
||||||
|
import CategorySectionLink from "discourse/lib/sidebar/user/categories-section/category-section-link";
|
||||||
|
|
||||||
|
export default class SidebarCommonCategoriesSection extends Component {
|
||||||
|
@service topicTrackingState;
|
||||||
|
@service siteSettings;
|
||||||
|
|
||||||
|
// Override in child
|
||||||
|
get categories() {}
|
||||||
|
|
||||||
|
@cached
|
||||||
|
get sectionLinks() {
|
||||||
|
return this.categories
|
||||||
|
.sort((a, b) => a.name.localeCompare(b.name))
|
||||||
|
.reduce((links, category) => {
|
||||||
|
links.push(
|
||||||
|
new CategorySectionLink({
|
||||||
|
category,
|
||||||
|
topicTrackingState: this.topicTrackingState,
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
return links;
|
||||||
|
}, []);
|
||||||
|
}
|
||||||
|
}
|
@ -1,18 +1,14 @@
|
|||||||
import I18n from "I18n";
|
import I18n from "I18n";
|
||||||
|
|
||||||
import { cached } from "@glimmer/tracking";
|
|
||||||
import { inject as service } from "@ember/service";
|
import { inject as service } from "@ember/service";
|
||||||
import { action } from "@ember/object";
|
import { action } from "@ember/object";
|
||||||
|
|
||||||
import Component from "@glimmer/component";
|
|
||||||
import CategorySectionLink from "discourse/lib/sidebar/user/categories-section/category-section-link";
|
|
||||||
import { canDisplayCategory } from "discourse/lib/sidebar/helpers";
|
import { canDisplayCategory } from "discourse/lib/sidebar/helpers";
|
||||||
|
import SidebarCommonCategoriesSection from "discourse/components/sidebar/common/categories-section";
|
||||||
|
|
||||||
export default class SidebarUserCategoriesSection extends Component {
|
export default class SidebarUserCategoriesSection extends SidebarCommonCategoriesSection {
|
||||||
@service router;
|
@service router;
|
||||||
@service topicTrackingState;
|
|
||||||
@service currentUser;
|
@service currentUser;
|
||||||
@service siteSettings;
|
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super(...arguments);
|
super(...arguments);
|
||||||
@ -28,24 +24,10 @@ export default class SidebarUserCategoriesSection extends Component {
|
|||||||
this.topicTrackingState.offStateChange(this.callbackId);
|
this.topicTrackingState.offStateChange(this.callbackId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@cached
|
get categories() {
|
||||||
get sectionLinks() {
|
return this.currentUser.sidebarCategories.filter((category) => {
|
||||||
const links = [];
|
|
||||||
|
|
||||||
const categories = this.currentUser.sidebarCategories.filter((category) => {
|
|
||||||
return canDisplayCategory(category, this.siteSettings);
|
return canDisplayCategory(category, this.siteSettings);
|
||||||
});
|
});
|
||||||
|
|
||||||
for (const category of categories) {
|
|
||||||
links.push(
|
|
||||||
new CategorySectionLink({
|
|
||||||
category,
|
|
||||||
topicTrackingState: this.topicTrackingState,
|
|
||||||
})
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return links;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get noCategoriesText() {
|
get noCategoriesText() {
|
||||||
|
@ -333,11 +333,9 @@ const User = RestModel.extend({
|
|||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
return Site.current()
|
return Site.current().categoriesList.filter((category) =>
|
||||||
.categoriesList.filter((category) =>
|
|
||||||
sidebarCategoryIds.includes(category.id)
|
sidebarCategoryIds.includes(category.id)
|
||||||
)
|
);
|
||||||
.sort((a, b) => a.name.localeCompare(b.name));
|
|
||||||
},
|
},
|
||||||
|
|
||||||
changeUsername(new_username) {
|
changeUsername(new_username) {
|
||||||
|
@ -20,10 +20,10 @@ acceptance("Sidebar - Anonymous Categories Section", function (needs) {
|
|||||||
".sidebar-section-categories .sidebar-section-link-wrapper"
|
".sidebar-section-categories .sidebar-section-link-wrapper"
|
||||||
);
|
);
|
||||||
assert.strictEqual(categories.length, 6);
|
assert.strictEqual(categories.length, 6);
|
||||||
assert.strictEqual(categories[0].textContent.trim(), "support");
|
assert.strictEqual(categories[0].textContent.trim(), "bug");
|
||||||
assert.strictEqual(categories[1].textContent.trim(), "bug");
|
assert.strictEqual(categories[1].textContent.trim(), "dev");
|
||||||
assert.strictEqual(categories[2].textContent.trim(), "feature");
|
assert.strictEqual(categories[2].textContent.trim(), "feature");
|
||||||
assert.strictEqual(categories[3].textContent.trim(), "dev");
|
assert.strictEqual(categories[3].textContent.trim(), "support");
|
||||||
assert.strictEqual(categories[4].textContent.trim(), "ux");
|
assert.strictEqual(categories[4].textContent.trim(), "ux");
|
||||||
|
|
||||||
assert.ok(
|
assert.ok(
|
||||||
@ -41,9 +41,9 @@ acceptance("Sidebar - Anonymous Categories Section", function (needs) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
assert.strictEqual(categories.length, 4);
|
assert.strictEqual(categories.length, 4);
|
||||||
assert.strictEqual(categories[0].textContent.trim(), "bug");
|
assert.strictEqual(categories[0].textContent.trim(), "blog");
|
||||||
assert.strictEqual(categories[1].textContent.trim(), "meta");
|
assert.strictEqual(categories[1].textContent.trim(), "bug");
|
||||||
assert.strictEqual(categories[2].textContent.trim(), "blog");
|
assert.strictEqual(categories[2].textContent.trim(), "meta");
|
||||||
|
|
||||||
assert.ok(
|
assert.ok(
|
||||||
exists("a.sidebar-section-link-all-categories"),
|
exists("a.sidebar-section-link-all-categories"),
|
||||||
|
Loading…
Reference in New Issue
Block a user