Skip to content

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

FIX: more... should not show when there are no visible links (#30405)

Régis Hanol268d4d4fb9f9
diff --git a/app/assets/javascripts/discourse/app/components/sidebar/common/custom-section.gjs b/app/assets/javascripts/discourse/app/components/sidebar/common/custom-section.gjs
index 6867d6b3101..58f9434092b 100644
--- a/app/assets/javascripts/discourse/app/components/sidebar/common/custom-section.gjs
+++ b/app/assets/javascripts/discourse/app/components/sidebar/common/custom-section.gjs
@@ -34,9 +34,7 @@ export default class SidebarCustomSection extends Component {
if (this.args.sectionData.section_type !== "community") {
return new Section(opts);
- }
-
- if (this.currentUser?.admin) {
+ } else if (this.currentUser?.admin) {
return new AdminCommunitySection(opts);
} else {
return new CommonCommunitySection(opts);
@@ -89,7 +87,7 @@ export default class SidebarCustomSection extends Component {
@text={{this.section.moreSectionButtonText}}
/>
{{/if}}
- {{else if this.section.moreLinks}}
+ {{else}}
<MoreSectionLinks
@sectionLinks={{this.section.moreLinks}}
@moreButtonAction={{this.section.moreSectionButtonAction}}
diff --git a/app/assets/javascripts/discourse/app/lib/sidebar/common/community-section/section.js b/app/assets/javascripts/discourse/app/lib/sidebar/common/community-section/section.js
index 5eb7c2e8f93..aa001378eaf 100644
--- a/app/assets/javascripts/discourse/app/lib/sidebar/common/community-section/section.js
+++ b/app/assets/javascripts/discourse/app/lib/sidebar/common/community-section/section.js
@@ -77,7 +77,8 @@ export default class CommunitySection {
return filtered;
}, [])
- .concat(this.apiPrimaryLinks);
+ .concat(this.apiPrimaryLinks)
+ .filter((link) => link.shouldDisplay);
this.moreLinks = this.section.links
.reduce((filtered, link) => {
@@ -91,7 +92,8 @@ export default class CommunitySection {
return filtered;
}, [])
- .concat(this.apiSecondaryLinks);
+ .concat(this.apiSecondaryLinks)
+ .filter((link) => link.shouldDisplay);
}
teardown() {
diff --git a/app/assets/javascripts/discourse/tests/acceptance/sidebar-anonymous-community-section-test.js b/app/assets/javascripts/discourse/tests/acceptance/sidebar-anonymous-community-section-test.js
index 41a10506f1f..f47c08bbb68 100644
--- a/app/assets/javascripts/discourse/tests/acceptance/sidebar-anonymous-community-section-test.js
+++ b/app/assets/javascripts/discourse/tests/acceptance/sidebar-anonymous-community-section-test.js
@@ -83,3 +83,34 @@ acceptance("Sidebar - Anonymous user - Community Section", function (needs) {
);
});
});
+
+acceptance(
+ "Sidebar - Anonymous user - Community Section with hidden links",
+ function (needs) {
+ needs.settings({ navigation_menu: "sidebar" });
+
+ needs.site({
+ anonymous_sidebar_sections: [
+ {
+ id: 1,
+ title: "The A Team",
+ section_type: "community",
+ links: [
+ {
+ id: 2,
+ name: "Admin",
+ value: "/admin",
+ segment: "secondary",
+ },
+ ],
+ },
+ ],
+ });
+
+ test("more... is not shown when there are no displayable links", async function (assert) {
+ await visit("/");
+
+ assert.dom(".sidebar-more-section-links-details-summary").doesNotExist();
+ });
+ }
+);
diff --git a/spec/serializers/site_serializer_spec.rb b/spec/serializers/site_serializer_spec.rb
index c8860e4846d..fc73e12c19e 100644
--- a/spec/serializers/site_serializer_spec.rb
+++ b/spec/serializers/site_serializer_spec.rb
@@ -214,8 +214,8 @@ RSpec.describe SiteSerializer do
it "is not included in the serialised object when user is not anonymous" do
guardian = Guardian.new(user)
-
serialized = described_class.new(Site.new(guardian), scope: guardian, root: false).as_json
+ expect(serialized).not_to have_key(:anonymous_sidebar_sections)
end
it "includes only public sidebar sections serialised object when user is anonymous" do