A platform for community discussion. Free, open, simple.
UX: Hide tags section from anonymous user when site has no tags (#18538)
Alan Guo Xiang Tanb75dc04a2549
diff --git a/app/assets/javascripts/discourse/app/components/sidebar/anonymous/tags-section.hbs b/app/assets/javascripts/discourse/app/components/sidebar/anonymous/tags-section.hbsindex b8b339f7e2a..b750e8d3c24 100644--- a/app/assets/javascripts/discourse/app/components/sidebar/anonymous/tags-section.hbs+++ b/app/assets/javascripts/discourse/app/components/sidebar/anonymous/tags-section.hbs@@ -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}}diff --git a/app/assets/javascripts/discourse/app/components/sidebar/anonymous/tags-section.js b/app/assets/javascripts/discourse/app/components/sidebar/anonymous/tags-section.jsindex 0dc3804ba51..3a3596ad520 100644--- a/app/assets/javascripts/discourse/app/components/sidebar/anonymous/tags-section.js+++ b/app/assets/javascripts/discourse/app/components/sidebar/anonymous/tags-section.js@@ -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+ );+ }+@cachedget sectionLinks() {let tags;diff --git a/app/assets/javascripts/discourse/tests/acceptance/sidebar-anonymous-tags-section-test.js b/app/assets/javascripts/discourse/tests/acceptance/sidebar-anonymous-tags-section-test.jsindex dc2ba51e564..09d805069b4 100644--- a/app/assets/javascripts/discourse/tests/acceptance/sidebar-anonymous-tags-section-test.js+++ b/app/assets/javascripts/discourse/tests/acceptance/sidebar-anonymous-tags-section-test.js@@ -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,- });- needs.site({- top_tags: ["design", "development", "fun"],- anonymous_default_sidebar_tags: ["random", "meta"],- });+ 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"]);- 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");});-});-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,- });+ test("tag section is hidden when tagging is disabled", async function (assert) {+ this.siteSettings.tagging_enabled = false;- needs.site({- top_tags: ["design", "development", "fun"],- });+ await visit("/");++ assert.ok(!exists(".sidebar-section-tags"), "section is not visible");+ });- test("tag section links", async function (assert) {- await visit("/");+ 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();- assert.ok(!exists(".sidebar-section-tags"), "section is not visible");+ site.setProperties({+ top_tags: [],+ anonymous_default_sidebar_tags: [],});- }-);++ await visit("/");++ assert.ok(!exists(".sidebar-section-tags"), "section is not visible");+ });+});