UX: Hide tags section from anonymous user when site has no tags (#18538)

If there are no top tags that an anonymous user can see and the site do
not have default sidebar tags configured for anonymous users, hide the
tag section entirely.
This commit is contained in:
Alan Guo Xiang Tan 2022-10-11 13:33:50 +08:00 committed by GitHub
parent 472abe532e
commit b75dc04a25
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 52 additions and 53 deletions

View File

@ -1,18 +1,20 @@
<Sidebar::Section
@sectionName="tags"
@headerLinkText={{i18n "sidebar.sections.tags.header_link_text"}}
@collapsable={{@collapsable}} >
{{#if this.displaySection}}
<Sidebar::Section
@sectionName="tags"
@headerLinkText={{i18n "sidebar.sections.tags.header_link_text"}}
@collapsable={{@collapsable}} >
{{#each this.sectionLinks as |sectionLink|}}
<Sidebar::SectionLink
@route={{sectionLink.route}}
@content={{sectionLink.text}}
@currentWhen={{sectionLink.currentWhen}}
@prefixType={{sectionLink.prefixType}}
@prefixValue={{sectionLink.prefixValue}}
@models={{sectionLink.models}} >
</Sidebar::SectionLink>
{{/each}}
{{#each this.sectionLinks as |sectionLink|}}
<Sidebar::SectionLink
@route={{sectionLink.route}}
@content={{sectionLink.text}}
@currentWhen={{sectionLink.currentWhen}}
@prefixType={{sectionLink.prefixType}}
@prefixValue={{sectionLink.prefixValue}}
@models={{sectionLink.models}} >
</Sidebar::SectionLink>
{{/each}}
<Sidebar::Common::AllTagsSectionLink />
</Sidebar::Section>
<Sidebar::Common::AllTagsSectionLink />
</Sidebar::Section>
{{/if}}

View File

@ -8,6 +8,13 @@ export default class SidebarAnonymousTagsSection extends Component {
@service topicTrackingState;
@service site;
get displaySection() {
return (
this.site.anonymous_default_sidebar_tags?.length > 0 ||
this.site.top_tags?.length > 0
);
}
@cached
get sectionLinks() {
let tags;

View File

@ -5,6 +5,7 @@ import {
exists,
queryAll,
} from "discourse/tests/helpers/qunit-helpers";
import Site from "discourse/models/site";
acceptance("Sidebar - Anonymous Tags Section", function (needs) {
needs.settings({
@ -18,12 +19,13 @@ acceptance("Sidebar - Anonymous Tags Section", function (needs) {
top_tags: ["design", "development", "fun"],
});
test("tag section links", async function (assert) {
test("tag section links when site has top tags", async function (assert) {
await visit("/");
const categories = queryAll(
".sidebar-section-tags .sidebar-section-link-wrapper"
);
assert.strictEqual(categories.length, 4);
assert.strictEqual(categories[0].textContent.trim(), "design");
assert.strictEqual(categories[1].textContent.trim(), "development");
@ -34,22 +36,11 @@ acceptance("Sidebar - Anonymous Tags Section", function (needs) {
"all tags link is visible"
);
});
});
acceptance("Sidebar - Anonymous Tags Section - default tags", function (needs) {
needs.settings({
enable_experimental_sidebar_hamburger: true,
enable_sidebar: true,
suppress_uncategorized_badge: false,
tagging_enabled: true,
});
test("tag section links when site has default sidebar tags configured", async function (assert) {
const site = Site.current();
site.set("anonymous_default_sidebar_tags", ["random", "meta"]);
needs.site({
top_tags: ["design", "development", "fun"],
anonymous_default_sidebar_tags: ["random", "meta"],
});
test("tag section links", async function (assert) {
await visit("/");
const categories = queryAll(
@ -64,26 +55,25 @@ acceptance("Sidebar - Anonymous Tags Section - default tags", function (needs) {
"all tags link is visible"
);
});
test("tag section is hidden when tagging is disabled", async function (assert) {
this.siteSettings.tagging_enabled = false;
await visit("/");
assert.ok(!exists(".sidebar-section-tags"), "section is not visible");
});
test("tag section is hidden when anonymous has no visible top tags and site has not default sidebar tags configured", async function (assert) {
const site = Site.current();
site.setProperties({
top_tags: [],
anonymous_default_sidebar_tags: [],
});
await visit("/");
assert.ok(!exists(".sidebar-section-tags"), "section is not visible");
});
});
acceptance(
"Sidebar - Anonymous Tags Section - Tagging disabled",
function (needs) {
needs.settings({
enable_experimental_sidebar_hamburger: true,
enable_sidebar: true,
suppress_uncategorized_badge: false,
tagging_enabled: false,
});
needs.site({
top_tags: ["design", "development", "fun"],
});
test("tag section links", async function (assert) {
await visit("/");
assert.ok(!exists(".sidebar-section-tags"), "section is not visible");
});
}
);