UX: Add short site description for anonymous user in sidebar (#18084)

Displays the `short_site_description` site setting in the community
section when the site setting is set
This commit is contained in:
Alan Guo Xiang Tan 2022-09-21 11:38:29 +08:00 committed by GitHub
parent 04cdc2910d
commit 1413de2809
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 58 additions and 5 deletions

View File

@ -1,6 +1,7 @@
<Sidebar::Section <Sidebar::Section
@sectionName="categories" @sectionName="categories"
@headerLinkText={{i18n "sidebar.sections.categories.header_link_text"}} > @headerLinkText={{i18n "sidebar.sections.categories.header_link_text"}}
@collapsable={{@collapsable}} >
{{#each this.sectionLinks as |sectionLink|}} {{#each this.sectionLinks as |sectionLink|}}
<Sidebar::SectionLink <Sidebar::SectionLink

View File

@ -8,12 +8,26 @@ import BadgesSectionLink from "discourse/lib/sidebar/common/community-section/ba
export default class SidebarAnonymousCommunitySection extends SidebarCommonCommunitySection { export default class SidebarAnonymousCommunitySection extends SidebarCommonCommunitySection {
get defaultMainSectionLinks() { get defaultMainSectionLinks() {
return [ const defaultLinks = [
EverythingSectionLink, EverythingSectionLink,
UsersSectionLink, UsersSectionLink,
AboutSectionLink,
FAQSectionLink, FAQSectionLink,
]; ];
defaultLinks.splice(
this.displayShortSiteDescription ? 0 : 2,
0,
AboutSectionLink
);
return defaultLinks;
}
get displayShortSiteDescription() {
return (
!this.currentUser &&
(this.siteSettings.short_site_description || "").length > 0
);
} }
get defaultMoreSectionLinks() { get defaultMoreSectionLinks() {

View File

@ -1,6 +1,7 @@
<Sidebar::Section <Sidebar::Section
@sectionName="tags" @sectionName="tags"
@headerLinkText={{i18n "sidebar.sections.tags.header_link_text"}} > @headerLinkText={{i18n "sidebar.sections.tags.header_link_text"}}
@collapsable={{@collapsable}} >
{{#each this.sectionLinks as |sectionLink|}} {{#each this.sectionLinks as |sectionLink|}}
<Sidebar::SectionLink <Sidebar::SectionLink

View File

@ -5,6 +5,12 @@
@headerActions={{this.headerActions}} @headerActions={{this.headerActions}}
@collapsable={{@collapsable}} > @collapsable={{@collapsable}} >
{{#if this.displayShortSiteDescription}}
<Sidebar::SectionMessage>
{{this.siteSettings.short_site_description}}
</Sidebar::SectionMessage>
{{/if}}
{{#each this.sectionLinks as |sectionLink|}} {{#each this.sectionLinks as |sectionLink|}}
<Sidebar::SectionLink <Sidebar::SectionLink
@linkName={{sectionLink.name}} @linkName={{sectionLink.name}}

View File

@ -2,7 +2,11 @@ import I18n from "I18n";
import { test } from "qunit"; import { test } from "qunit";
import { acceptance, queryAll } from "discourse/tests/helpers/qunit-helpers"; import {
acceptance,
query,
queryAll,
} from "discourse/tests/helpers/qunit-helpers";
import { click, visit } from "@ember/test-helpers"; import { click, visit } from "@ember/test-helpers";
acceptance("Sidebar - Anonymous user - Community Section", function (needs) { acceptance("Sidebar - Anonymous user - Community Section", function (needs) {
@ -11,6 +15,31 @@ acceptance("Sidebar - Anonymous user - Community Section", function (needs) {
enable_sidebar: true, enable_sidebar: true,
}); });
test("display short site description site setting when it is set", async function (assert) {
this.siteSettings.short_site_description =
"This is a short description about the site";
await visit("/");
assert.strictEqual(
query(
".sidebar-section-community .sidebar-section-message"
).textContent.trim(),
this.siteSettings.short_site_description,
"displays the short site description under the community section"
);
const sectionLinks = queryAll(
".sidebar-section-community .sidebar-section-link"
);
assert.strictEqual(
sectionLinks[0].textContent.trim(),
I18n.t("sidebar.sections.community.links.about.content"),
"displays the about section link first"
);
});
test("everything, users, about and FAQ section links are shown by default ", async function (assert) { test("everything, users, about and FAQ section links are shown by default ", async function (assert) {
await visit("/"); await visit("/");

View File

@ -4136,6 +4136,8 @@ en:
all_categories: "All categories" all_categories: "All categories"
all_tags: "All tags" all_tags: "All tags"
sections: sections:
about:
header_link_text: "About"
messages: messages:
header_link_text: "Messages" header_link_text: "Messages"
header_action_title: "create a personal message" header_action_title: "create a personal message"