FIX: Keep active state in sidebar button for category/tag hot routes (#30954)

Fixes issue reported in
https://meta.discourse.org/t/sidebar-links-loose-active-state-on-the-hot-list-filter/348468
This commit is contained in:
Penar Musaraj 2025-01-23 11:36:48 -05:00 committed by GitHub
parent f25b72b98f
commit 3801ccf7b0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 39 additions and 5 deletions

View File

@ -174,7 +174,7 @@ export default class CategorySectionLink {
} }
get currentWhen() { get currentWhen() {
return "discovery.unreadCategory discovery.topCategory discovery.newCategory discovery.latestCategory discovery.category discovery.categoryNone discovery.categoryAll"; return "discovery.unreadCategory discovery.hotCategory discovery.topCategory discovery.newCategory discovery.latestCategory discovery.category discovery.categoryNone discovery.categoryAll";
} }
get title() { get title() {

View File

@ -48,7 +48,7 @@ export default class TagSectionLink extends BaseTagSectionLink {
} }
get currentWhen() { get currentWhen() {
return "tag.show tag.showNew tag.showUnread tag.showTop"; return "tag.show tag.showNew tag.showUnread tag.showTop tag.showHot tag.showLatest";
} }
get badgeText() { get badgeText() {

View File

@ -70,7 +70,7 @@ acceptance("Sidebar - Logged on user - Categories Section", function (needs) {
}); });
needs.pretender((server, helper) => { needs.pretender((server, helper) => {
["latest", "top", "new", "unread"].forEach((type) => { ["latest", "top", "new", "unread", "hot"].forEach((type) => {
server.get(`/c/:categorySlug/:categoryId/l/${type}.json`, () => { server.get(`/c/:categorySlug/:categoryId/l/${type}.json`, () => {
return helper.response( return helper.response(
cloneJSON(discoveryFixture["/c/bug/1/l/latest.json"]) cloneJSON(discoveryFixture["/c/bug/1/l/latest.json"])
@ -718,6 +718,26 @@ acceptance("Sidebar - Logged on user - Categories Section", function (needs) {
); );
}); });
test("visiting category discovery hot route", async function (assert) {
const { category1 } = setupUserSidebarCategories();
await visit(`/c/${category1.slug}/${category1.id}/l/hot`);
assert
.dom(
".sidebar-section[data-section-name='categories'] .sidebar-section-link.active"
)
.exists({ count: 1 }, "only one link is marked as active");
assert
.dom(
`.sidebar-section-link-wrapper[data-category-id="${category1.id}"] a.active`
)
.exists(
"the category1 section link is marked as active for the hot route"
);
});
test("visiting category discovery no subcategories route", async function (assert) { test("visiting category discovery no subcategories route", async function (assert) {
const { category1 } = setupUserSidebarCategories(); const { category1 } = setupUserSidebarCategories();

View File

@ -57,7 +57,7 @@ acceptance("Sidebar - Logged on user - Tags section", function (needs) {
}); });
}); });
["latest", "top", "new", "unread"].forEach((type) => { ["latest", "top", "new", "unread", "hot"].forEach((type) => {
server.get(`/tag/:tagId/l/${type}.json`, () => { server.get(`/tag/:tagId/l/${type}.json`, () => {
return helper.response( return helper.response(
cloneJSON(discoveryFixture["/tag/important/l/latest.json"]) cloneJSON(discoveryFixture["/tag/important/l/latest.json"])
@ -269,7 +269,7 @@ acceptance("Sidebar - Logged on user - Tags section", function (needs) {
.exists("the tag1 section link is marked as active for the top route"); .exists("the tag1 section link is marked as active for the top route");
}); });
test("visiting tag discovery new ", async function (assert) { test("visiting tag discovery new route", async function (assert) {
await visit(`/tag/tag1/l/new`); await visit(`/tag/tag1/l/new`);
assert assert
@ -297,6 +297,20 @@ acceptance("Sidebar - Logged on user - Tags section", function (needs) {
.exists("the tag1 section link is marked as active for the unread route"); .exists("the tag1 section link is marked as active for the unread route");
}); });
test("visiting tag discovery hot route", async function (assert) {
await visit(`/tag/tag1/l/hot`);
assert
.dom(
".sidebar-section[data-section-name='tags'] .sidebar-section-link.active"
)
.exists({ count: 1 }, "only one link is marked as active");
assert
.dom(".sidebar-section-link-wrapper[data-tag-name=tag1] a.active")
.exists("the tag1 section link is marked as active for the hot route");
});
test("show suffix indicator for new content on tag section links", async function (assert) { test("show suffix indicator for new content on tag section links", async function (assert) {
updateCurrentUser({ updateCurrentUser({
user_option: { user_option: {