From ab053ac66948e7c8e0a68ed01ca0ac435687b7e5 Mon Sep 17 00:00:00 2001 From: Alan Guo Xiang Tan Date: Tue, 11 Jul 2023 09:40:37 +0800 Subject: [PATCH] UX: Remove section heading for community section (#22405) Why is this change being made? We've decided that the previous "community" section should look more like a primary section that holds the most important navigation links for the site and the word "community" doesn't quite fit that description. Therefore, we've made the decision to drop the section heading for the community section. As part of removing the section heading, the following changes are made as well: 1. Button to customize the section has been moved to the "footer" of the "More..." section when `navigation_menu` site setting is set to `sidebar`. When `navigation_menu` is set to `header dropdown`, a button to customize the section is shown inline. 2. The section will no longer be collapsable. 3. The title of the section is no longer customisable as it is no longer displayed. As a technical note, we have not dropped any previous customisations of the section's title previously in case we have to bring back the header in the future. 4. The new topic button that was previously present in the header has been removed alongside the header. Admins can add a custom section link to the `/new-topic` route if there would like to make it easier for users to create a new topic in the sidebar. --- .../components/modal/sidebar-section-form.hbs | 50 ++++--- .../components/modal/sidebar-section-form.js | 19 ++- .../sidebar/common/custom-section.hbs | 18 ++- .../sidebar/common/custom-section.js | 16 +- .../components/sidebar/more-section-links.hbs | 14 +- .../components/sidebar/more-section-links.js | 6 +- .../sidebar/section-link-button.hbs | 15 ++ .../app/components/sidebar/section.hbs | 93 ++++++------ .../community-section/section.js} | 70 +-------- .../discourse/app/lib/sidebar/section-link.js | 8 + .../discourse/app/lib/sidebar/section.js | 3 +- .../user/community-section/admin-section.js | 30 ++++ .../discourse/app/services/navigation-menu.js | 13 ++ .../discourse/app/widgets/header.js | 1 + .../sidebar-user-community-section-test.js | 66 --------- .../tests/acceptance/sidebar-user-test.js | 4 +- .../base/sidebar-more-section-links.scss | 16 ++ .../common/base/sidebar-section-link.scss | 23 ++- .../stylesheets/common/base/sidebar.scss | 13 +- config/locales/client.en.yml | 6 +- .../chat/spec/system/deleted_message_spec.rb | 2 +- plugins/chat/spec/system/navigation_spec.rb | 2 +- .../system/sidebar_navigation_menu_spec.rb | 2 +- spec/system/custom_sidebar_sections_spec.rb | 64 +++----- ...ting_sidebar_categories_navigation_spec.rb | 2 +- .../editing_sidebar_community_section_spec.rb | 67 +++++++++ .../editing_sidebar_tags_navigation_spec.rb | 2 +- .../components/navigation_menu/base.rb | 129 ++++++++++++++++ .../navigation_menu/header_dropdown.rb | 25 ++++ .../components/navigation_menu/sidebar.rb | 45 ++++++ .../system/page_objects/components/sidebar.rb | 138 ------------------ .../components/sidebar_header_dropdown.rb | 4 +- .../modals/sidebar_section_form.rb | 8 + .../viewing_sidebar_as_anonymous_user_spec.rb | 2 +- spec/system/viewing_sidebar_mobile_spec.rb | 3 +- spec/system/viewing_sidebar_spec.rb | 14 +- 36 files changed, 561 insertions(+), 432 deletions(-) create mode 100644 app/assets/javascripts/discourse/app/components/sidebar/section-link-button.hbs rename app/assets/javascripts/discourse/app/lib/sidebar/{community-section.js => common/community-section/section.js} (69%) create mode 100644 app/assets/javascripts/discourse/app/lib/sidebar/user/community-section/admin-section.js create mode 100644 app/assets/javascripts/discourse/app/services/navigation-menu.js create mode 100644 spec/system/editing_sidebar_community_section_spec.rb create mode 100644 spec/system/page_objects/components/navigation_menu/base.rb create mode 100644 spec/system/page_objects/components/navigation_menu/header_dropdown.rb create mode 100644 spec/system/page_objects/components/navigation_menu/sidebar.rb delete mode 100644 spec/system/page_objects/components/sidebar.rb diff --git a/app/assets/javascripts/discourse/app/components/modal/sidebar-section-form.hbs b/app/assets/javascripts/discourse/app/components/modal/sidebar-section-form.hbs index 5429f6b6ab0..a64b2faf18f 100644 --- a/app/assets/javascripts/discourse/app/components/modal/sidebar-section-form.hbs +++ b/app/assets/javascripts/discourse/app/components/modal/sidebar-section-form.hbs @@ -6,38 +6,46 @@ class="sidebar-section-form-modal" > <:body> -
-
- - - {{#if this.transformedModel.invalidTitleMessage}} -
- {{this.transformedModel.invalidTitleMessage}} -
- {{/if}} -
+ + {{#unless this.transformedModel.hideTitleInput}} + + {{/unless}} +
+ +
+ {{#each this.activeLinks as |link|}} { + title: section.title, + publicSection: section.public, + sectionType: section.section_type, + links: section.links.reduce((acc, link) => { if (link.segment === "primary") { this.nextObjectId++; acc.push(this.initLink(link)); } return acc; }, A()), - secondaryLinks: this.model.links.reduce((acc, link) => { + secondaryLinks: section.links.reduce((acc, link) => { if (link.segment === "secondary") { this.nextObjectId++; acc.push(this.initLink(link)); } return acc; }, A()), - id: this.model.id, + id: section.id, + hideTitleInput: this.model.hideSectionHeader, }); } else { return new Section({ diff --git a/app/assets/javascripts/discourse/app/components/sidebar/common/custom-section.hbs b/app/assets/javascripts/discourse/app/components/sidebar/common/custom-section.hbs index cde9643f48f..30e36c03454 100644 --- a/app/assets/javascripts/discourse/app/components/sidebar/common/custom-section.hbs +++ b/app/assets/javascripts/discourse/app/components/sidebar/common/custom-section.hbs @@ -6,6 +6,7 @@ @headerActions={{this.section.headerActions}} @headerActionsIcon={{this.section.headerActionIcon}} @class={{this.section.dragCss}} + @hideSectionHeader={{this.section.hideSectionHeader}} > {{#each this.section.links as |link|}} {{#if link.externalOrFullReload}} @@ -61,12 +62,25 @@ {{/each}} {{#if this.section.moreLinks}} - {{#if this.isDesktopDropdownMode}} + {{#if this.navigationMenu.isDesktopDropdownMode}} {{#each this.section.moreLinks as |sectionLink|}} {{/each}} + + {{#if this.section.moreSectionButtonAction}} + + {{/if}} {{else if this.section.moreLinks}} - + {{/if}} {{/if}} \ No newline at end of file diff --git a/app/assets/javascripts/discourse/app/components/sidebar/common/custom-section.js b/app/assets/javascripts/discourse/app/components/sidebar/common/custom-section.js index ca165f5db9b..2bf3946b865 100644 --- a/app/assets/javascripts/discourse/app/components/sidebar/common/custom-section.js +++ b/app/assets/javascripts/discourse/app/components/sidebar/common/custom-section.js @@ -4,9 +4,12 @@ import { tracked } from "@glimmer/tracking"; import { inject as service } from "@ember/service"; import Section from "discourse/lib/sidebar/section"; -import CommunitySection from "discourse/lib/sidebar/community-section"; +import AdminCommunitySection from "discourse/lib/sidebar/user/community-section/admin-section"; +import CommonCommunitySection from "discourse/lib/sidebar/common/community-section/section"; export default class SidebarCustomSection extends Component { + @service currentUser; + @service navigationMenu; @service site; @service siteSettings; @@ -22,19 +25,14 @@ export default class SidebarCustomSection extends Component { super.willDestroy(); } - get isDesktopDropdownMode() { - const headerDropdownMode = - this.siteSettings.navigation_menu === "header dropdown"; - - return !this.site.mobileView && headerDropdownMode; - } - #initializeSection() { let sectionClass = Section; switch (this.args.sectionData.section_type) { case "community": - sectionClass = CommunitySection; + sectionClass = this.currentUser?.admin + ? AdminCommunitySection + : CommonCommunitySection; break; } diff --git a/app/assets/javascripts/discourse/app/components/sidebar/more-section-links.hbs b/app/assets/javascripts/discourse/app/components/sidebar/more-section-links.hbs index b0f3c1b83db..bcb99107116 100644 --- a/app/assets/javascripts/discourse/app/components/sidebar/more-section-links.hbs +++ b/app/assets/javascripts/discourse/app/components/sidebar/more-section-links.hbs @@ -20,11 +20,21 @@ > diff --git a/app/assets/javascripts/discourse/app/components/sidebar/more-section-links.js b/app/assets/javascripts/discourse/app/components/sidebar/more-section-links.js index 285288df52f..72e2f415abf 100644 --- a/app/assets/javascripts/discourse/app/components/sidebar/more-section-links.js +++ b/app/assets/javascripts/discourse/app/components/sidebar/more-section-links.js @@ -48,9 +48,9 @@ export default class SidebarMoreSectionLinks extends Component { @bind closeDetails(event) { if (this.open) { - const isLinkClick = event.target.className.includes( - "sidebar-section-link" - ); + const isLinkClick = + event.target.className.includes("sidebar-section-link") || + event.target.className.includes("sidebar-section-link-button"); if (isLinkClick || this.#isOutsideDetailsClick(event)) { this.open = false; diff --git a/app/assets/javascripts/discourse/app/components/sidebar/section-link-button.hbs b/app/assets/javascripts/discourse/app/components/sidebar/section-link-button.hbs new file mode 100644 index 00000000000..852bcc1d381 --- /dev/null +++ b/app/assets/javascripts/discourse/app/components/sidebar/section-link-button.hbs @@ -0,0 +1,15 @@ + \ No newline at end of file diff --git a/app/assets/javascripts/discourse/app/components/sidebar/section.hbs b/app/assets/javascripts/discourse/app/components/sidebar/section.hbs index e8cc64fc055..5ec274885a1 100644 --- a/app/assets/javascripts/discourse/app/components/sidebar/section.hbs +++ b/app/assets/javascripts/discourse/app/components/sidebar/section.hbs @@ -3,54 +3,59 @@ class={{concat-class "sidebar-section-wrapper sidebar-section" @class}} data-section-name={{@sectionName}} > - + {{/unless}} {{#if this.displaySectionContent}}