A platform for community discussion. Free, open, simple.
UX: add review queue link to admin sidebar (#36611)
Krisf28e56cf7f04
diff --git a/frontend/discourse/app/components/sidebar/api-section.gjs b/frontend/discourse/app/components/sidebar/api-section.gjsindex 5bf073c64de..7611cbee773 100644--- a/frontend/discourse/app/components/sidebar/api-section.gjs+++ b/frontend/discourse/app/components/sidebar/api-section.gjs@@ -36,6 +36,7 @@ const SidebarApiSection = <template>@currentWhen={{link.currentWhen}}@href={{link.href}}@title={{link.title}}+ @badgeText={{link.badgeText}}@contentCSSClass={{link.contentCSSClass}}@prefixColor={{link.prefixColor}}@prefixBadge={{link.prefixBadge}}diff --git a/frontend/discourse/app/lib/sidebar/admin-nav-map.js b/frontend/discourse/app/lib/sidebar/admin-nav-map.jsindex 6ea99eecec3..3c49d1df205 100644--- a/frontend/discourse/app/lib/sidebar/admin-nav-map.js+++ b/frontend/discourse/app/lib/sidebar/admin-nav-map.js@@ -36,6 +36,14 @@ export const ADMIN_NAV_MAP = [description: "admin.config.site_settings.header_description",icon: "gear",},+ {+ name: "admin_review",+ route: "review",+ label: "sidebar.sections.community.links.review.content",+ description: "sidebar.sections.community.links.review.title",+ icon: "flag",+ moderator: true,+ },{name: "admin_whats_new",route: "admin.whatsNew",diff --git a/frontend/discourse/app/lib/sidebar/admin-sidebar.js b/frontend/discourse/app/lib/sidebar/admin-sidebar.jsindex 33d82dcb15d..87738e1c54e 100644--- a/frontend/discourse/app/lib/sidebar/admin-sidebar.js+++ b/frontend/discourse/app/lib/sidebar/admin-sidebar.js@@ -8,6 +8,7 @@ import PreloadStore from "discourse/lib/preload-store";import BaseCustomSidebarPanel from "discourse/lib/sidebar/base-custom-sidebar-panel";import BaseCustomSidebarSection from "discourse/lib/sidebar/base-custom-sidebar-section";import BaseCustomSidebarSectionLink from "discourse/lib/sidebar/base-custom-sidebar-section-link";+import { getReviewBadgeText } from "discourse/lib/sidebar/helpers/review-badge-helper";import { ADMIN_PANEL } from "discourse/lib/sidebar/panels";import { escapeExpression } from "discourse/lib/utilities";import I18n, { i18n } from "discourse-i18n";@@ -104,6 +105,12 @@ class SidebarAdminSectionLink extends BaseCustomSidebarSectionLink {);}+ get badgeText() {+ if (this.adminSidebarNavLink.name === "admin_review") {+ return getReviewBadgeText(this.currentUser);+ }+ }+get suffixType() {if (this.#hasUnseenFeatures) {return "icon";diff --git a/frontend/discourse/app/lib/sidebar/base-custom-sidebar-section-link.js b/frontend/discourse/app/lib/sidebar/base-custom-sidebar-section-link.jsindex 2f09adb412d..876bf24ca14 100644--- a/frontend/discourse/app/lib/sidebar/base-custom-sidebar-section-link.js+++ b/frontend/discourse/app/lib/sidebar/base-custom-sidebar-section-link.js@@ -70,6 +70,11 @@ export default class BaseCustomSidebarSectionLink {*/get contentComponent() {}+ /**+ * @returns {string} Text for the badge within the link+ */+ get badgeText() {}+/*** @returns {Object} Arguments to pass to the content component*/diff --git a/frontend/discourse/app/lib/sidebar/helpers/review-badge-helper.js b/frontend/discourse/app/lib/sidebar/helpers/review-badge-helper.jsnew file mode 100644index 00000000000..bffc3d25c93--- /dev/null+++ b/frontend/discourse/app/lib/sidebar/helpers/review-badge-helper.js@@ -0,0 +1,11 @@+import { i18n } from "discourse-i18n";++export function getReviewBadgeText(currentUser) {+ // force a tracker for reviewable_count by using .get to ensure badgeText+ // rerenders when reviewable_count changes+ if (currentUser?.get("reviewable_count") > 0) {+ return i18n("sidebar.sections.community.links.review.pending_count", {+ count: currentUser.reviewable_count,+ });+ }+}diff --git a/frontend/discourse/app/lib/sidebar/user/community-section/review-section-link.js b/frontend/discourse/app/lib/sidebar/user/community-section/review-section-link.jsindex 88cbe9001a2..44b76988599 100644--- a/frontend/discourse/app/lib/sidebar/user/community-section/review-section-link.js+++ b/frontend/discourse/app/lib/sidebar/user/community-section/review-section-link.js@@ -1,4 +1,5 @@import BaseSectionLink from "discourse/lib/sidebar/base-community-section-link";+import { getReviewBadgeText } from "discourse/lib/sidebar/helpers/review-badge-helper";import { i18n } from "discourse-i18n";export default class ReviewSectionLink extends BaseSectionLink {@@ -26,13 +27,7 @@ export default class ReviewSectionLink extends BaseSectionLink {}get badgeText() {- // force a tracker for reviewable_count by using .get to ensure badgeText- // rerenders when reviewable_count changes- if (this.currentUser?.get("reviewable_count") > 0) {- return i18n("sidebar.sections.community.links.review.pending_count", {- count: this.currentUser.reviewable_count,- });- }+ return getReviewBadgeText(this.currentUser);}get defaultPrefixValue() {diff --git a/frontend/discourse/tests/acceptance/admin-sidebar-section-test.js b/frontend/discourse/tests/acceptance/admin-sidebar-section-test.jsindex d5372d9fe45..e19ce472125 100644--- a/frontend/discourse/tests/acceptance/admin-sidebar-section-test.js+++ b/frontend/discourse/tests/acceptance/admin-sidebar-section-test.js@@ -4,7 +4,11 @@ import { AUTO_GROUPS } from "discourse/lib/constants";import { withPluginApi } from "discourse/lib/plugin-api";import PreloadStore from "discourse/lib/preload-store";import pretender, { response } from "discourse/tests/helpers/create-pretender";-import { acceptance } from "discourse/tests/helpers/qunit-helpers";+import {+ acceptance,+ loggedInUser,+ publishToMessageBus,+} from "discourse/tests/helpers/qunit-helpers";import I18n from "discourse-i18n";acceptance("Admin Sidebar - Sections", function (needs) {@@ -100,6 +104,32 @@ acceptance("Admin Sidebar - Sections", function (needs) {.dom(".admin-reports-list .admin-section-landing-item__content").exists({ count: 1 }, "filter is case insensitive");});++ test("review link is shown in root section and displays badge count", async function (assert) {+ await visit("/admin");++ assert+ .dom(+ ".sidebar-section[data-section-name='admin-root'] .sidebar-section-link[data-link-name='admin_review']"+ )+ .exists("review link is displayed in the root section");++ assert+ .dom(+ ".sidebar-section[data-section-name='admin-root'] .sidebar-section-link[data-link-name='admin_review'] .sidebar-section-link-content-badge"+ )+ .doesNotExist("badge is not shown when there are no pending reviewables");++ await publishToMessageBus(`/reviewable_counts/${loggedInUser().id}`, {+ reviewable_count: 42,+ });++ assert+ .dom(+ ".sidebar-section[data-section-name='admin-root'] .sidebar-section-link[data-link-name='admin_review'] .sidebar-section-link-content-badge"+ )+ .hasText("42 pending", "displays the pending reviewable count");+ });});acceptance("Admin Sidebar - Sections - Plugin API", function (needs) {diff --git a/frontend/discourse/tests/unit/lib/sidebar/helpers/review-badge-helper-test.js b/frontend/discourse/tests/unit/lib/sidebar/helpers/review-badge-helper-test.jsnew file mode 100644index 00000000000..dfd5acfcf4e--- /dev/null+++ b/frontend/discourse/tests/unit/lib/sidebar/helpers/review-badge-helper-test.js@@ -0,0 +1,35 @@+import { setupTest } from "ember-qunit";+import { module, test } from "qunit";+import { getReviewBadgeText } from "discourse/lib/sidebar/helpers/review-badge-helper";+import { logIn } from "discourse/tests/helpers/qunit-helpers";++module("Unit | Sidebar | Helpers | review-badge-helper", function (hooks) {+ setupTest(hooks);++ test("returns undefined when user has no reviewables", function (assert) {+ const currentUser = logIn(this.owner);+ currentUser.set("reviewable_count", 0);++ const result = getReviewBadgeText(currentUser);++ assert.strictEqual(result, undefined);+ });++ test("returns formatted badge text for single reviewable", function (assert) {+ const currentUser = logIn(this.owner);+ currentUser.set("reviewable_count", 1);++ const result = getReviewBadgeText(currentUser);++ assert.strictEqual(result, "1 pending");+ });++ test("returns formatted badge text for multiple reviewables", function (assert) {+ const currentUser = logIn(this.owner);+ currentUser.set("reviewable_count", 42);++ const result = getReviewBadgeText(currentUser);++ assert.strictEqual(result, "42 pending");+ });+});diff --git a/spec/system/admin_sidebar_navigation_spec.rb b/spec/system/admin_sidebar_navigation_spec.rbindex 73e5deca2e2..21def99df0d 100644--- a/spec/system/admin_sidebar_navigation_spec.rb+++ b/spec/system/admin_sidebar_navigation_spec.rb@@ -1,7 +1,7 @@# frozen_string_literal: truedescribe "Admin | Sidebar Navigation", type: :system do- UNFILTERED_LINK_COUNT = 41+ UNFILTERED_LINK_COUNT = 42fab!(:admin)fab!(:moderator)@@ -64,6 +64,7 @@ describe "Admin | Sidebar Navigation", type: :system doI18n.t("admin_js.admin.config.users.title"),I18n.t("admin_js.admin.config.groups.title"),I18n.t("admin_js.admin.config.site_settings.title"),+ I18n.t("js.sidebar.sections.community.links.review.content"),I18n.t("admin_js.admin.config.whats_new.title"),],)@@ -103,6 +104,7 @@ describe "Admin | Sidebar Navigation", type: :system doI18n.t("admin_js.admin.config.users.title"),I18n.t("admin_js.admin.config.groups.title"),I18n.t("admin_js.admin.config.site_settings.title"),+ I18n.t("js.sidebar.sections.community.links.review.content"),I18n.t("admin_js.admin.config.whats_new.title"),]expect(page).to have_selector(@@ -163,6 +165,7 @@ describe "Admin | Sidebar Navigation", type: :system doI18n.t("admin_js.admin.dashboard.title"),I18n.t("admin_js.admin.config.users.title"),I18n.t("admin_js.admin.config.groups.title"),+ I18n.t("js.sidebar.sections.community.links.review.content"),I18n.t("admin_js.admin.config.whats_new.title"),I18n.t("admin_js.admin.config.reports.title"),I18n.t("admin_js.admin.config.watched_words.title"),