FIX: more... should not show when there are no visible links (#30405)
When lurking on a Discourse as anonymous, if the sidebar is enabled, and a section contains only secondary links that are not visible to anonymous users, we should not display the "more..." button. Otherwise it feels broken because clicking on it does nothing, since there are no "visible" links to be shown. Internal ref t/144716
This commit is contained in:
parent
f392259e3f
commit
268d4d4fb9
|
@ -34,9 +34,7 @@ export default class SidebarCustomSection extends Component {
|
||||||
|
|
||||||
if (this.args.sectionData.section_type !== "community") {
|
if (this.args.sectionData.section_type !== "community") {
|
||||||
return new Section(opts);
|
return new Section(opts);
|
||||||
}
|
} else if (this.currentUser?.admin) {
|
||||||
|
|
||||||
if (this.currentUser?.admin) {
|
|
||||||
return new AdminCommunitySection(opts);
|
return new AdminCommunitySection(opts);
|
||||||
} else {
|
} else {
|
||||||
return new CommonCommunitySection(opts);
|
return new CommonCommunitySection(opts);
|
||||||
|
@ -89,7 +87,7 @@ export default class SidebarCustomSection extends Component {
|
||||||
@text={{this.section.moreSectionButtonText}}
|
@text={{this.section.moreSectionButtonText}}
|
||||||
/>
|
/>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
{{else if this.section.moreLinks}}
|
{{else}}
|
||||||
<MoreSectionLinks
|
<MoreSectionLinks
|
||||||
@sectionLinks={{this.section.moreLinks}}
|
@sectionLinks={{this.section.moreLinks}}
|
||||||
@moreButtonAction={{this.section.moreSectionButtonAction}}
|
@moreButtonAction={{this.section.moreSectionButtonAction}}
|
||||||
|
|
|
@ -77,7 +77,8 @@ export default class CommunitySection {
|
||||||
|
|
||||||
return filtered;
|
return filtered;
|
||||||
}, [])
|
}, [])
|
||||||
.concat(this.apiPrimaryLinks);
|
.concat(this.apiPrimaryLinks)
|
||||||
|
.filter((link) => link.shouldDisplay);
|
||||||
|
|
||||||
this.moreLinks = this.section.links
|
this.moreLinks = this.section.links
|
||||||
.reduce((filtered, link) => {
|
.reduce((filtered, link) => {
|
||||||
|
@ -91,7 +92,8 @@ export default class CommunitySection {
|
||||||
|
|
||||||
return filtered;
|
return filtered;
|
||||||
}, [])
|
}, [])
|
||||||
.concat(this.apiSecondaryLinks);
|
.concat(this.apiSecondaryLinks)
|
||||||
|
.filter((link) => link.shouldDisplay);
|
||||||
}
|
}
|
||||||
|
|
||||||
teardown() {
|
teardown() {
|
||||||
|
|
|
@ -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();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
|
@ -214,8 +214,8 @@ RSpec.describe SiteSerializer do
|
||||||
|
|
||||||
it "is not included in the serialised object when user is not anonymous" do
|
it "is not included in the serialised object when user is not anonymous" do
|
||||||
guardian = Guardian.new(user)
|
guardian = Guardian.new(user)
|
||||||
|
|
||||||
serialized = described_class.new(Site.new(guardian), scope: guardian, root: false).as_json
|
serialized = described_class.new(Site.new(guardian), scope: guardian, root: false).as_json
|
||||||
|
expect(serialized).not_to have_key(:anonymous_sidebar_sections)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "includes only public sidebar sections serialised object when user is anonymous" do
|
it "includes only public sidebar sections serialised object when user is anonymous" do
|
||||||
|
|
Loading…
Reference in New Issue