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,4 +1,5 @@
<Sidebar::Section {{#if this.displaySection}}
<Sidebar::Section
@sectionName="tags" @sectionName="tags"
@headerLinkText={{i18n "sidebar.sections.tags.header_link_text"}} @headerLinkText={{i18n "sidebar.sections.tags.header_link_text"}}
@collapsable={{@collapsable}} > @collapsable={{@collapsable}} >
@ -15,4 +16,5 @@
{{/each}} {{/each}}
<Sidebar::Common::AllTagsSectionLink /> <Sidebar::Common::AllTagsSectionLink />
</Sidebar::Section> </Sidebar::Section>
{{/if}}

View File

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

View File

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