From 49d4f7c0660e21891b88ea70439fcb543e0a72a7 Mon Sep 17 00:00:00 2001 From: Alan Guo Xiang Tan Date: Fri, 22 Jul 2022 16:00:06 +0800 Subject: [PATCH] FEATURE: Add users and groups links to community section in sidebar (#17609) --- .../components/sidebar/community-section.js | 4 ++ .../community-section/groups-section-link.js | 21 +++++++++ .../community-section/users-section-link.js | 21 +++++++++ .../sidebar-community-section-test.js | 44 +++++++++++++++++++ config/locales/client.en.yml | 6 +++ 5 files changed, 96 insertions(+) create mode 100644 app/assets/javascripts/discourse/app/lib/sidebar/community-section/groups-section-link.js create mode 100644 app/assets/javascripts/discourse/app/lib/sidebar/community-section/users-section-link.js diff --git a/app/assets/javascripts/discourse/app/components/sidebar/community-section.js b/app/assets/javascripts/discourse/app/components/sidebar/community-section.js index db718adcba3..c6cc1f59d67 100644 --- a/app/assets/javascripts/discourse/app/components/sidebar/community-section.js +++ b/app/assets/javascripts/discourse/app/components/sidebar/community-section.js @@ -6,6 +6,8 @@ import { customSectionLinks } from "discourse/lib/sidebar/custom-community-secti import EverythingSectionLink from "discourse/lib/sidebar/community-section/everything-section-link"; import TrackedSectionLink from "discourse/lib/sidebar/community-section/tracked-section-link"; import MyPostsSectionLink from "discourse/lib/sidebar/community-section/my-posts-section-link"; +import GroupsSectionLink from "discourse/lib/sidebar/community-section/groups-section-link"; +import UsersSectionLink from "discourse/lib/sidebar/community-section/users-section-link"; import { action } from "@ember/object"; import { next } from "@ember/runloop"; @@ -13,6 +15,8 @@ import { next } from "@ember/runloop"; const DEFAULT_SECTION_LINKS = [ EverythingSectionLink, TrackedSectionLink, + GroupsSectionLink, + UsersSectionLink, MyPostsSectionLink, ]; diff --git a/app/assets/javascripts/discourse/app/lib/sidebar/community-section/groups-section-link.js b/app/assets/javascripts/discourse/app/lib/sidebar/community-section/groups-section-link.js new file mode 100644 index 00000000000..acd4e1f56d3 --- /dev/null +++ b/app/assets/javascripts/discourse/app/lib/sidebar/community-section/groups-section-link.js @@ -0,0 +1,21 @@ +import I18n from "I18n"; + +import BaseSectionLink from "discourse/lib/sidebar/community-section/base-section-link"; + +export default class GroupsSectionLink extends BaseSectionLink { + get name() { + return "groups"; + } + + get route() { + return "groups"; + } + + get title() { + return I18n.t("sidebar.sections.community.links.groups.title"); + } + + get text() { + return I18n.t("sidebar.sections.community.links.groups.content"); + } +} diff --git a/app/assets/javascripts/discourse/app/lib/sidebar/community-section/users-section-link.js b/app/assets/javascripts/discourse/app/lib/sidebar/community-section/users-section-link.js new file mode 100644 index 00000000000..696363c3e1b --- /dev/null +++ b/app/assets/javascripts/discourse/app/lib/sidebar/community-section/users-section-link.js @@ -0,0 +1,21 @@ +import I18n from "I18n"; + +import BaseSectionLink from "discourse/lib/sidebar/community-section/base-section-link"; + +export default class UsersSectionLink extends BaseSectionLink { + get name() { + return "users"; + } + + get route() { + return "users"; + } + + get title() { + return I18n.t("sidebar.sections.community.links.users.title"); + } + + get text() { + return I18n.t("sidebar.sections.community.links.users.content"); + } +} diff --git a/app/assets/javascripts/discourse/tests/acceptance/sidebar-community-section-test.js b/app/assets/javascripts/discourse/tests/acceptance/sidebar-community-section-test.js index 79619e42802..0b3df4789a1 100644 --- a/app/assets/javascripts/discourse/tests/acceptance/sidebar-community-section-test.js +++ b/app/assets/javascripts/discourse/tests/acceptance/sidebar-community-section-test.js @@ -158,6 +158,50 @@ acceptance("Sidebar - Community Section", function (needs) { ); }); + test("clicking on users link", async function (assert) { + await visit("/t/280"); + await click(".sidebar-section-community .sidebar-section-link-users"); + + assert.strictEqual( + currentURL(), + "/u?order=likes_received", + "it should transition to the users url" + ); + + assert.strictEqual( + count(".sidebar-section-community .sidebar-section-link.active"), + 1, + "only one link is marked as active" + ); + + assert.ok( + exists(".sidebar-section-community .sidebar-section-link-users.active"), + "the users link is marked as active" + ); + }); + + test("clicking on groups link", async function (assert) { + await visit("/t/280"); + await click(".sidebar-section-community .sidebar-section-link-groups"); + + assert.strictEqual( + currentURL(), + "/g", + "it should transition to the groups url" + ); + + assert.strictEqual( + count(".sidebar-section-community .sidebar-section-link.active"), + 1, + "only one link is marked as active" + ); + + assert.ok( + exists(".sidebar-section-community .sidebar-section-link-groups.active"), + "the groups link is marked as active" + ); + }); + test("clicking on my posts link", async function (assert) { await visit("/t/280"); await click(".sidebar-section-community .sidebar-section-link-my-posts"); diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index b5fb12d2061..43f663c3be8 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -4107,6 +4107,12 @@ en: tracked: content: "Tracked" title: "All tracked topics" + groups: + content: "Groups" + title: "All groups" + users: + content: "Users" + title: "All users" my_posts: content: "My Posts" title: "My posts"