Skip to content

A platform for community discussion. Free, open, simple.

FIX: Do not show edit sections button on admin sidebar (#26547)

Martin Brennanfb5ae16630b3
diff --git a/app/assets/javascripts/discourse/app/components/sidebar/footer.gjs b/app/assets/javascripts/discourse/app/components/sidebar/footer.gjs
new file mode 100644
index 00000000000..eddcb7fb13d
--- /dev/null
+++ b/app/assets/javascripts/discourse/app/components/sidebar/footer.gjs
@@ -0,0 +1,74 @@
+import Component from "@glimmer/component";
+import { action } from "@ember/object";
+import { service } from "@ember/service";
+import DButton from "discourse/components/d-button";
+import SidebarSectionForm from "discourse/components/modal/sidebar-section-form";
+import PluginOutlet from "discourse/components/plugin-outlet";
+import routeAction from "discourse/helpers/route-action";
+import { ADMIN_PANEL } from "discourse/lib/sidebar/panels";
+
+export default class SidebarFooter extends Component {
+ @service capabilities;
+ @service currentUser;
+ @service modal;
+ @service site;
+ @service siteSettings;
+ @service sidebarState;
+
+ get showManageSectionsButton() {
+ return this.currentUser && !this.sidebarState.isCurrentPanel(ADMIN_PANEL);
+ }
+
+ get showToggleMobileButton() {
+ return (
+ this.site.mobileView ||
+ (this.siteSettings.enable_mobile_theme && this.capabilities.touch)
+ );
+ }
+
+ get showKeyboardShortcutsButton() {
+ return this.site.desktopView;
+ }
+
+ @action
+ manageSections() {
+ this.modal.show(SidebarSectionForm);
+ }
+
+ <template>
+ <div class="sidebar-footer-wrapper">
+ <div class="sidebar-footer-container">
+ <div class="sidebar-footer-actions">
+ <PluginOutlet @name="sidebar-footer-actions" />
+
+ {{#if this.showManageSectionsButton}}
+ <DButton
+ @icon="plus"
+ @action={{this.manageSections}}
+ @title="sidebar.sections.custom.add"
+ class="btn-flat sidebar-footer-actions-button add-section"
+ />
+ {{/if}}
+
+ {{#if this.showToggleMobileButton}}
+ <DButton
+ @action={{routeAction "toggleMobileView"}}
+ @title={{if this.site.mobileView "desktop_view" "mobile_view"}}
+ @icon={{if this.site.mobileView "desktop" "mobile-alt"}}
+ class="btn-flat sidebar-footer-actions-button sidebar-footer-actions-toggle-mobile-view"
+ />
+ {{/if}}
+
+ {{#if this.showKeyboardShortcutsButton}}
+ <DButton
+ @action={{routeAction "showKeyboardShortcutsHelp"}}
+ @title="keyboard_shortcuts_help.title"
+ @icon="keyboard"
+ class="btn-flat sidebar-footer-actions-button sidebar-footer-actions-keyboard-shortcuts"
+ />
+ {{/if}}
+ </div>
+ </div>
+ </div>
+ </template>
+}
diff --git a/app/assets/javascripts/discourse/app/components/sidebar/footer.hbs b/app/assets/javascripts/discourse/app/components/sidebar/footer.hbs
deleted file mode 100644
index dc8da794f90..00000000000
--- a/app/assets/javascripts/discourse/app/components/sidebar/footer.hbs
+++ /dev/null
@@ -1,39 +0,0 @@
-<div class="sidebar-footer-wrapper">
- <div class="sidebar-footer-container">
- <div class="sidebar-footer-actions">
- <PluginOutlet @name="sidebar-footer-actions" />
-
- {{#if this.currentUser}}
- <DButton
- @icon="plus"
- @action={{this.addSection}}
- @title="sidebar.sections.custom.add"
- class="btn-flat sidebar-footer-actions-button add-section"
- />
- {{/if}}
-
- {{#if
- (or
- this.site.mobileView
- (and this.siteSettings.enable_mobile_theme this.capabilities.touch)
- )
- }}
- <DButton
- @action={{route-action "toggleMobileView"}}
- @title={{if this.site.mobileView "desktop_view" "mobile_view"}}
- @icon={{if this.site.mobileView "desktop" "mobile-alt"}}
- class="btn-flat sidebar-footer-actions-button sidebar-footer-actions-toggle-mobile-view"
- />
- {{/if}}
-
- {{#if this.site.desktopView}}
- <DButton
- @action={{route-action "showKeyboardShortcutsHelp"}}
- @title="keyboard_shortcuts_help.title"
- @icon="keyboard"
- class="btn-flat sidebar-footer-actions-button sidebar-footer-actions-keyboard-shortcuts"
- />
- {{/if}}
- </div>
- </div>
-</div>
\ No newline at end of file
diff --git a/app/assets/javascripts/discourse/app/components/sidebar/footer.js b/app/assets/javascripts/discourse/app/components/sidebar/footer.js
deleted file mode 100644
index eebc014bd80..00000000000
--- a/app/assets/javascripts/discourse/app/components/sidebar/footer.js
+++ /dev/null
@@ -1,17 +0,0 @@
-import Component from "@glimmer/component";
-import { action } from "@ember/object";
-import { service } from "@ember/service";
-import SidebarSectionForm from "discourse/components/modal/sidebar-section-form";
-
-export default class SidebarFooter extends Component {
- @service capabilities;
- @service currentUser;
- @service modal;
- @service site;
- @service siteSettings;
-
- @action
- addSection() {
- this.modal.show(SidebarSectionForm);
- }
-}
diff --git a/spec/system/admin_sidebar_navigation_spec.rb b/spec/system/admin_sidebar_navigation_spec.rb
index 4ef77dc38f1..5ea676f599f 100644
--- a/spec/system/admin_sidebar_navigation_spec.rb
+++ b/spec/system/admin_sidebar_navigation_spec.rb
@@ -129,4 +129,11 @@ describe "Admin Revamp | Sidebar Navigation", type: :system do
expect(links.count).to eq(1)
expect(links.map(&:text)).to eq(["Installed"])
end
+
+ it "does not show the button to customize sidebar sections, that is only supported in the main panel" do
+ visit("/")
+ expect(sidebar).to have_add_section_button
+ visit("/admin")
+ expect(sidebar).to have_no_add_section_button
+ end
end
diff --git a/spec/system/page_objects/components/navigation_menu/base.rb b/spec/system/page_objects/components/navigation_menu/base.rb
index 943153f2283..5d72edeb375 100644
--- a/spec/system/page_objects/components/navigation_menu/base.rb
+++ b/spec/system/page_objects/components/navigation_menu/base.rb
@@ -143,7 +143,11 @@ module PageObjects
end
def has_no_add_section_button?
- page.has_no_button?(add_section_button_text)
+ has_no_css?(add_section_button_css)
+ end
+
+ def has_add_section_button?
+ has_css?(add_section_button_css)
end
def click_edit_categories_button
@@ -195,6 +199,10 @@ module PageObjects
def add_link_button_text
I18n.t("js.sidebar.sections.custom.links.add")
end
+
+ def add_section_button_css
+ ".sidebar-footer-actions-button.add-section"
+ end
end
end
end