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

Sections cannot be created or edited or deleted in
the admin sidebar. Also move the footer component into
a gjs file.
This commit is contained in:
Martin Brennan 2024-04-08 15:21:24 +10:00 committed by GitHub
parent fbfeb5d6d0
commit fb5ae16630
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 90 additions and 57 deletions

View File

@ -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>
}

View File

@ -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>

View File

@ -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);
}
}

View File

@ -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

View File

@ -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