Skip to content

A platform for community discussion. Free, open, simple.

UX: ensure plugin links are included in experimental user nav (#44116)

Krise8b12dbafebe
diff --git a/app/assets/stylesheets/common/base/sidebar-user-nav.scss b/app/assets/stylesheets/common/base/sidebar-user-nav.scss
index f296afa86b8..0c996d15f45 100644
--- a/app/assets/stylesheets/common/base/sidebar-user-nav.scss
+++ b/app/assets/stylesheets/common/base/sidebar-user-nav.scss
@@ -40,6 +40,10 @@ body.user-nav-panel-active {
}
}
+ .new-user-wrapper .user-navigation {
+ border: none;
+ }
+
@include viewport.until(sm) {
.user-content tbody {
border-top: none;
diff --git a/frontend/discourse/app/lib/plugin-api.gjs b/frontend/discourse/app/lib/plugin-api.gjs
index d36b5c237e3..81cafba199c 100644
--- a/frontend/discourse/app/lib/plugin-api.gjs
+++ b/frontend/discourse/app/lib/plugin-api.gjs
@@ -124,7 +124,7 @@ import {
registerCustomCountable as registerUserCategorySectionLinkCountable,
} from "discourse/lib/sidebar/user/categories-section/category-section-link";
import { registerCustomTagSectionLinkPrefixIcon } from "discourse/lib/sidebar/user/tags-section/base-tag-section-link";
-import { addUserNavPreferencesLink } from "discourse/lib/sidebar/user-nav-sidebar";
+import { addUserNavSidebarLink } from "discourse/lib/sidebar/user-nav-sidebar";
import { consolePrefix } from "discourse/lib/source-identifier";
import {
_addTransformerName,
@@ -2995,31 +2995,36 @@ class _PluginApi {
/**
* EXPERIMENTAL. Do not use.
- * Adds a link to the preferences section of the user nav sidebar panel.
+ * Adds a link to a section of the user nav sidebar panel.
*
- * The `user-preferences-nav` plugin outlet renders markup the panel cannot
- * read, so a plugin with a preferences tab registers it here as well to stay
- * reachable once the horizontal nav is hidden.
+ * The panel replaces the horizontal user navs, and the outlets a plugin adds
+ * its tabs through (`user-main-nav`, `user-activity-bottom`,
+ * `user-notifications-bottom`, `user-preferences-nav`) render markup the
+ * panel cannot read. A plugin with a tab in any of them registers it here as
+ * well to stay reachable once those navs are hidden.
*
* ```javascript
- * api.addUserNavPreferencesLink({
- * name: "preferences-chat",
- * route: "preferences.chat",
- * label: "chat.title_capitalized",
- * icon: "d-chat",
- * displayed: ({ siteSettings }) => siteSettings.chat_enabled,
+ * api.addUserNavSidebarLink("activity", {
+ * name: "activity-solved",
+ * route: "userActivity.solved",
+ * label: "solved.title",
+ * icon: "square-check",
+ * displayed: ({ siteSettings }) => siteSettings.solved_enabled,
* });
* ```
*
- * @param {Object} link - A link object representing a preferences link.
+ * @param {String} sectionName - The panel section to add the link to: profile,
+ * activity, notifications, messages, invites or preferences.
+ * @param {Object} link - A link object representing a section link.
* @param {string} link.name - The name of the link. Needs to be dasherized and lowercase.
* @param {string} link.route - The Ember route name the link points at.
* @param {string} link.label - The i18n key for the link's text.
* @param {string} [link.icon] - The FontAwesome icon to display for the link.
+ * @param {Array} [link.routeParams] - Extra route models, after the username.
* @param {Function} [link.displayed] - Predicate deciding whether to show the link.
*/
- addUserNavPreferencesLink(link) {
- addUserNavPreferencesLink(link);
+ addUserNavSidebarLink(sectionName, link) {
+ addUserNavSidebarLink(sectionName, link);
}
/**
diff --git a/frontend/discourse/app/lib/sidebar/user-nav-sidebar.js b/frontend/discourse/app/lib/sidebar/user-nav-sidebar.js
index a8f3bf61140..003d8acfab8 100644
--- a/frontend/discourse/app/lib/sidebar/user-nav-sidebar.js
+++ b/frontend/discourse/app/lib/sidebar/user-nav-sidebar.js
@@ -10,19 +10,21 @@ import { USER_NAV_PANEL } from "discourse/lib/sidebar/panels";
import { i18n } from "discourse-i18n";
/**
- * Preferences tabs registered by plugins. They reach the horizontal nav through
- * the `user-preferences-nav` outlet, which renders markup this panel cannot
- * read, so a plugin that wants its tab in the panel registers it here too.
+ * Links plugins add to the panel, keyed by section name. Plugins reach the
+ * horizontal navs through outlets — `user-main-nav`, `user-activity-bottom`,
+ * `user-notifications-bottom`, `user-preferences-nav` — whose markup this panel
+ * cannot read, so a plugin that wants its tab here registers it too.
*/
-let additionalPreferencesLinks = [];
+let additionalLinks = {};
-export function addUserNavPreferencesLink(link) {
- additionalPreferencesLinks.push(link);
+export function addUserNavSidebarLink(sectionName, link) {
+ additionalLinks[sectionName] ??= [];
+ additionalLinks[sectionName].push(link);
}
// For testing
-export function clearAdditionalUserNavPreferencesLinks() {
- additionalPreferencesLinks = [];
+export function clearAdditionalUserNavSidebarLinks() {
+ additionalLinks = {};
}
// Mirrors `components/user-nav.gjs`. The tabs that own a secondary nav become
@@ -121,7 +123,6 @@ const NOTIFICATION_LINKS = [
route: "userNotifications.index",
label: "user.filters.all",
icon: "bell",
- count: ({ currentUser }) => currentUser?.all_unread_notifications_count,
},
{
name: "notifications-responses",
@@ -498,9 +499,11 @@ const NAV_SECTIONS = [
name: "preferences",
title: "user.preferences.title",
// Staff can open someone else's preferences, so this follows `can_edit`
- // rather than "is this me".
- displayed: ({ user }) => !!user?.can_edit,
- links: () => [...PREFERENCES_LINKS, ...additionalPreferencesLinks],
+ // rather than "is this me". A user's admin page serializes a different
+ // shape that carries no `can_edit`, and only staff can be there at all.
+ displayed: ({ user, currentUser }) =>
+ user?.can_edit ?? !!currentUser?.staff,
+ links: () => PREFERENCES_LINKS,
},
];
@@ -655,7 +658,13 @@ function buildSection(config) {
}
get links() {
- return buildLinks(config.links, getOwner(this));
+ return buildLinks(
+ (context) => [
+ ...config.links(context),
+ ...(additionalLinks[config.name] ?? []),
+ ],
+ getOwner(this)
+ );
}
get moreLinks() {
diff --git a/frontend/discourse/tests/acceptance/sidebar-plugin-api-test.gjs b/frontend/discourse/tests/acceptance/sidebar-plugin-api-test.gjs
index 64c2f4efe94..26c68e330a7 100644
--- a/frontend/discourse/tests/acceptance/sidebar-plugin-api-test.gjs
+++ b/frontend/discourse/tests/acceptance/sidebar-plugin-api-test.gjs
@@ -1385,3 +1385,45 @@ acceptance("Sidebar - Plugin API", function (needs) {
);
});
});
+
+acceptance("Sidebar - User nav panel - Plugin API", function (needs) {
+ needs.user({});
+
+ needs.settings({
+ navigation_menu: "sidebar",
+ sidebar_user_navigation: true,
+ });
+
+ test("adds links to a section of the user nav panel", async function (assert) {
+ withPluginApi((api) => {
+ api.addUserNavSidebarLink("activity", {
+ name: "activity-test",
+ route: "userActivity.index",
+ label: "user.filters.all",
+ icon: "bars-staggered",
+ });
+
+ api.addUserNavSidebarLink("activity", {
+ name: "activity-hidden",
+ route: "userActivity.index",
+ label: "user.filters.all",
+ icon: "bars-staggered",
+ displayed: () => false,
+ });
+ });
+
+ await visit("/u/eviltrout/activity");
+
+ assert
+ .dom(
+ ".user-nav-panel .sidebar-section-link[data-link-name='user-nav-activity-test']"
+ )
+ .exists("a registered link renders in the section it named");
+
+ assert
+ .dom(
+ ".user-nav-panel .sidebar-section-link[data-link-name='user-nav-activity-hidden']"
+ )
+ .doesNotExist("a link whose `displayed` returns false is dropped");
+ });
+});
diff --git a/frontend/discourse/tests/helpers/qunit-helpers.js b/frontend/discourse/tests/helpers/qunit-helpers.js
index bbccfea33cb..6c73820d2db 100644
--- a/frontend/discourse/tests/helpers/qunit-helpers.js
+++ b/frontend/discourse/tests/helpers/qunit-helpers.js
@@ -77,7 +77,7 @@ import { resetLogSearchLinkClickedCallbacks } from "discourse/lib/search";
import { clearAdditionalAdminSidebarSectionLinks } from "discourse/lib/sidebar/admin-sidebar";
import { resetDefaultSectionLinks as resetTopicsSectionLinks } from "discourse/lib/sidebar/custom-community-section-links";
import { resetSidebarPanels } from "discourse/lib/sidebar/custom-sections";
-import { clearAdditionalUserNavPreferencesLinks } from "discourse/lib/sidebar/user-nav-sidebar";
+import { clearAdditionalUserNavSidebarLinks } from "discourse/lib/sidebar/user-nav-sidebar";
import {
resetHighestReadCache,
setTopicList,
@@ -283,7 +283,7 @@ export function testCleanup(container, app) {
resetBeforeAuthCompleteCallbacks();
clearPopupMenuOptions();
clearAdditionalAdminSidebarSectionLinks();
- clearAdditionalUserNavPreferencesLinks();
+ clearAdditionalUserNavSidebarLinks();
resetAdminPluginConfigNav();
resetTransformers();
rollbackAllPrepends();
diff --git a/plugins/chat/assets/javascripts/discourse/initializers/chat-setup.js b/plugins/chat/assets/javascripts/discourse/initializers/chat-setup.js
index 840d0554962..cf7fb651222 100644
--- a/plugins/chat/assets/javascripts/discourse/initializers/chat-setup.js
+++ b/plugins/chat/assets/javascripts/discourse/initializers/chat-setup.js
@@ -32,7 +32,7 @@ class ChatSetupInit {
this.appEvents.on("discourse:focus-changed", this, "_handleFocusChanged");
withPluginApi((api) => {
- api.addUserNavPreferencesLink({
+ api.addUserNavSidebarLink("preferences", {
name: "preferences-chat",
route: "preferences.chat",
label: "chat.title_capitalized",
diff --git a/plugins/discourse-assign/assets/javascripts/discourse/initializers/extend-for-assigns.js b/plugins/discourse-assign/assets/javascripts/discourse/initializers/extend-for-assigns.js
index 2429683de68..6870ec38735 100644
--- a/plugins/discourse-assign/assets/javascripts/discourse/initializers/extend-for-assigns.js
+++ b/plugins/discourse-assign/assets/javascripts/discourse/initializers/extend-for-assigns.js
@@ -600,6 +600,14 @@ export default {
}
withPluginApi((api) => {
+ api.addUserNavSidebarLink("activity", {
+ name: "activity-assigned",
+ route: "userActivity.assigned",
+ label: "discourse_assign.assigned",
+ icon: "user-plus",
+ displayed: ({ currentUser }) => currentUser?.can_assign_globally,
+ });
+
const currentUser = container.lookup("service:current-user");
if (currentUser?.can_assign_globally) {
api.modifyClass(
diff --git a/plugins/discourse-reactions/assets/javascripts/discourse/initializers/discourse-reactions.gjs b/plugins/discourse-reactions/assets/javascripts/discourse/initializers/discourse-reactions.gjs
index 0bc91da8267..6306cfa095d 100644
--- a/plugins/discourse-reactions/assets/javascripts/discourse/initializers/discourse-reactions.gjs
+++ b/plugins/discourse-reactions/assets/javascripts/discourse/initializers/discourse-reactions.gjs
@@ -15,6 +15,27 @@ replaceIcon("notification.reaction", "bell");
function initializeDiscourseReactions(api) {
customizePostMenu(api);
+ for (const [section, link] of [
+ [
+ "activity",
+ { name: "activity-reactions", route: "userActivity.reactions" },
+ ],
+ [
+ "notifications",
+ {
+ name: "notifications-reactions",
+ route: "userNotifications.reactionsReceived",
+ },
+ ],
+ ]) {
+ api.addUserNavSidebarLink(section, {
+ ...link,
+ label: "discourse_reactions.reactions_title",
+ icon: "far-face-smile",
+ displayed: ({ siteSettings }) => siteSettings.discourse_reactions_enabled,
+ });
+ }
+
api.addKeyboardShortcut(
"l",
() => {
diff --git a/plugins/discourse-rewind/assets/javascripts/discourse/initializers/rewind-setup.js b/plugins/discourse-rewind/assets/javascripts/discourse/initializers/rewind-setup.js
index d11f2aa34db..e803a42878b 100644
--- a/plugins/discourse-rewind/assets/javascripts/discourse/initializers/rewind-setup.js
+++ b/plugins/discourse-rewind/assets/javascripts/discourse/initializers/rewind-setup.js
@@ -18,7 +18,7 @@ export default {
}
withPluginApi((api) => {
- api.addUserNavPreferencesLink({
+ api.addUserNavSidebarLink("preferences", {
name: "preferences-rewind",
route: "preferences.rewind",
label: "discourse_rewind.title",
@@ -32,6 +32,13 @@ export default {
});
if (this.rewind.enabled) {
+ api.addUserNavSidebarLink("activity", {
+ name: "activity-rewind",
+ route: "userActivity.rewind",
+ label: "discourse_rewind.title",
+ icon: "repeat",
+ });
+
api.addQuickAccessProfileItem({
icon: "repeat",
href: "/my/activity/rewind",
diff --git a/plugins/discourse-solved/assets/javascripts/discourse/initializers/extend-for-solved-button.gjs b/plugins/discourse-solved/assets/javascripts/discourse/initializers/extend-for-solved-button.gjs
index 31ffce1f595..e52266b96b9 100644
--- a/plugins/discourse-solved/assets/javascripts/discourse/initializers/extend-for-solved-button.gjs
+++ b/plugins/discourse-solved/assets/javascripts/discourse/initializers/extend-for-solved-button.gjs
@@ -173,6 +173,14 @@ export default {
withPluginApi(initializeWithApi);
withPluginApi((api) => {
+ api.addUserNavSidebarLink("activity", {
+ name: "activity-solved",
+ route: "userActivity.solved",
+ label: "solved.title",
+ icon: "square-check",
+ displayed: ({ siteSettings }) => siteSettings.solved_enabled,
+ });
+
api.replaceIcon(
"notification.solved.accepted_notification",
"square-check"
diff --git a/plugins/discourse-subscriptions/assets/javascripts/discourse/initializers/setup-subscriptions.js b/plugins/discourse-subscriptions/assets/javascripts/discourse/initializers/setup-subscriptions.js
index 93c9e7fe690..0f1126d7a30 100644
--- a/plugins/discourse-subscriptions/assets/javascripts/discourse/initializers/setup-subscriptions.js
+++ b/plugins/discourse-subscriptions/assets/javascripts/discourse/initializers/setup-subscriptions.js
@@ -5,6 +5,14 @@ export default {
name: "setup-subscriptions",
initialize(container) {
withPluginApi((api) => {
+ api.addUserNavSidebarLink("profile", {
+ name: "billing",
+ route: "user.billing",
+ label: "discourse_subscriptions.navigation.billing",
+ icon: "far-credit-card",
+ displayed: ({ currentUser, user }) => currentUser?.id === user?.id,
+ });
+
const siteSettings = container.lookup("service:site-settings");
const isNavLinkEnabled =
siteSettings.discourse_subscriptions_extra_nav_subscribe;
diff --git a/plugins/discourse-topic-voting/assets/javascripts/discourse/initializers/discourse-topic-voting.js b/plugins/discourse-topic-voting/assets/javascripts/discourse/initializers/discourse-topic-voting.js
index 4628a06d1da..56b8795b7e1 100644
--- a/plugins/discourse-topic-voting/assets/javascripts/discourse/initializers/discourse-topic-voting.js
+++ b/plugins/discourse-topic-voting/assets/javascripts/discourse/initializers/discourse-topic-voting.js
@@ -7,6 +7,15 @@ export default {
initialize() {
withPluginApi((api) => {
+ api.addUserNavSidebarLink("activity", {
+ name: "activity-votes",
+ route: "userActivity.votes",
+ label: "topic_voting.vote_title_plural",
+ icon: "check-to-slot",
+ displayed: ({ siteSettings }) =>
+ siteSettings.topic_voting_show_votes_on_profile,
+ });
+
api.replaceIcon("topic_voting.voting_closed", "lock");
api.registerNotificationTypeRenderer(
diff --git a/spec/system/user_nav_sidebar_spec.rb b/spec/system/user_nav_sidebar_spec.rb
index 6858ec59d13..3266ca01db1 100644
--- a/spec/system/user_nav_sidebar_spec.rb
+++ b/spec/system/user_nav_sidebar_spec.rb
@@ -102,6 +102,7 @@ RSpec.describe "User nav sidebar" do
expect(page).to have_css(panel)
within(panel) { expect(page).to have_link("Summary") }
expect(page).to have_css(".sidebar-sections__back-to-forum", text: "Back to Forum")
+ expect(page).to have_css(section("preferences"))
end
it "points the back link at admin when the admin area was the entry point" do
@@ -163,18 +164,14 @@ RSpec.describe "User nav sidebar" do
".sidebar-section-link-content-badge"
end
- it "marks drafts, unread messages and notifications, as a dot or a count" do
+ it "marks drafts and unread messages, as a dot or a count" do
# Never read, so it counts as new rather than unread.
Fabricate(:private_message_post, user: other_user, recipient: current_user)
- Fabricate(:notification, user: current_user, read: false)
Draft.set(current_user, "#{Draft::NEW_TOPIC}_1", 0, { reply: "a draft" }.to_json)
visit("/u/alice/messages")
expect(page).to have_css(link_suffix("messages-new"))
- visit("/u/alice/notifications")
- expect(page).to have_css(link_suffix("notifications-all"))
-
# The count belongs in the suffix, not folded into the label.
visit("/u/alice/activity")
expect(page).to have_link("Drafts")