Skip to content

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

FIX: Do not duplicate admin sidebar plugin links (#25780)

Martin Brennan95014e9ab85d
diff --git a/app/assets/javascripts/discourse/app/lib/sidebar/admin-sidebar.js b/app/assets/javascripts/discourse/app/lib/sidebar/admin-sidebar.js
index 5d7a221d047..c575aea55ac 100644
--- a/app/assets/javascripts/discourse/app/lib/sidebar/admin-sidebar.js
+++ b/app/assets/javascripts/discourse/app/lib/sidebar/admin-sidebar.js
@@ -1,3 +1,4 @@
+import { cached } from "@glimmer/tracking";
import PreloadStore from "discourse/lib/preload-store";
import { ADMIN_NAV_MAP } from "discourse/lib/sidebar/admin-nav-map";
import BaseCustomSidebarPanel from "discourse/lib/sidebar/base-custom-sidebar-panel";
@@ -213,6 +214,7 @@ export default class AdminSidebarPanel extends BaseCustomSidebarPanel {
key = ADMIN_PANEL;
hidden = true;
+ @cached
get sections() {
const currentUser = getOwnerWithFallback().lookup("service:current-user");
const siteSettings = getOwnerWithFallback().lookup("service:site-settings");
diff --git a/plugins/chat/spec/system/admin_sidebar_navigation_spec.rb b/plugins/chat/spec/system/admin_sidebar_navigation_spec.rb
index e79f6e955e9..4cbe806a2f7 100644
--- a/plugins/chat/spec/system/admin_sidebar_navigation_spec.rb
+++ b/plugins/chat/spec/system/admin_sidebar_navigation_spec.rb
@@ -14,4 +14,12 @@ describe "Admin Revamp | Sidebar Navigation | Plugin Links", type: :system do
visit("/admin")
expect(sidebar).to have_section_link("Chat", href: "/admin/plugins/chat")
end
+
+ it "does not duplicate links to enabled plugin admin routes when showing and hiding sidebar" do
+ visit("/admin")
+ expect(sidebar).to have_section_link("Chat", href: "/admin/plugins/chat", count: 1)
+ find(".header-sidebar-toggle").click
+ find(".header-sidebar-toggle").click
+ expect(sidebar).to have_section_link("Chat", href: "/admin/plugins/chat", count: 1)
+ end
end
diff --git a/spec/system/page_objects/components/navigation_menu/base.rb b/spec/system/page_objects/components/navigation_menu/base.rb
index 890af45926b..4e335595e61 100644
--- a/spec/system/page_objects/components/navigation_menu/base.rb
+++ b/spec/system/page_objects/components/navigation_menu/base.rb
@@ -36,8 +36,15 @@ module PageObjects
has_css?(".#{SIDEBAR_SECTION_LINK_SELECTOR}--active", count: 1)
end
- def has_section_link?(name, href: nil, active: false, target: nil)
- section_link_present?(name, href: href, active: active, target: target, present: true)
+ def has_section_link?(name, href: nil, active: false, target: nil, count: 1)
+ section_link_present?(
+ name,
+ href: href,
+ active: active,
+ target: target,
+ present: true,
+ count: count,
+ )
end
def has_no_section_link?(name, href: nil, active: false)
@@ -163,12 +170,13 @@ module PageObjects
private
- def section_link_present?(name, href: nil, active: false, target: nil, present:)
+ def section_link_present?(name, href: nil, active: false, target: nil, count: 1, present:)
attributes = { exact_text: name }
attributes[:href] = href if href
attributes[:class] = SIDEBAR_SECTION_LINK_SELECTOR
attributes[:class] += "--active" if active
attributes[:target] = target if target
+ attributes[:count] = count
page.public_send(present ? :has_link? : :has_no_link?, **attributes)
end