FIX: Admin sidebar was hiding chat/forum toggle button (#25781)
We have separated and combined modes for sidebar panels. Separated means the panels show only their own sections, combined means sections from all panels are shown. The admin sidebar only shows its own panels, so it must set the mode to separated; however when we navigate to chat or home we must revert to the initial mode setttings.
This commit is contained in:
parent
95014e9ab8
commit
ac92cc526d
|
@ -1,5 +1,11 @@
|
|||
import { tracked } from "@glimmer/tracking";
|
||||
import { inject as service } from "@ember/service";
|
||||
import { ADMIN_PANEL, MAIN_PANEL } from "discourse/lib/sidebar/panels";
|
||||
import {
|
||||
ADMIN_PANEL,
|
||||
COMBINED_MODE,
|
||||
MAIN_PANEL,
|
||||
SEPARATED_MODE,
|
||||
} from "discourse/lib/sidebar/panels";
|
||||
import DiscourseRoute from "discourse/routes/discourse";
|
||||
import I18n from "discourse-i18n";
|
||||
|
||||
|
@ -7,6 +13,7 @@ export default class AdminRoute extends DiscourseRoute {
|
|||
@service sidebarState;
|
||||
@service siteSettings;
|
||||
@service currentUser;
|
||||
@tracked initialSidebarState;
|
||||
|
||||
titleToken() {
|
||||
return I18n.t("admin_title");
|
||||
|
@ -14,6 +21,11 @@ export default class AdminRoute extends DiscourseRoute {
|
|||
|
||||
activate() {
|
||||
if (this.currentUser.use_admin_sidebar) {
|
||||
this.initialSidebarState = {
|
||||
mode: this.sidebarState.mode,
|
||||
displaySwitchPanelButtons: this.sidebarState.displaySwitchPanelButtons,
|
||||
};
|
||||
|
||||
this.sidebarState.setPanel(ADMIN_PANEL);
|
||||
this.sidebarState.setSeparatedMode();
|
||||
this.sidebarState.hideSwitchPanelButtons();
|
||||
|
@ -29,6 +41,18 @@ export default class AdminRoute extends DiscourseRoute {
|
|||
|
||||
if (this.currentUser.use_admin_sidebar) {
|
||||
if (!transition?.to.name.startsWith("admin")) {
|
||||
if (this.initialSidebarState.mode === SEPARATED_MODE) {
|
||||
this.sidebarState.setSeparatedMode();
|
||||
} else if (this.initialSidebarState.mode === COMBINED_MODE) {
|
||||
this.sidebarState.setCombinedMode();
|
||||
}
|
||||
|
||||
if (this.initialSidebarState.displaySwitchPanelButtons) {
|
||||
this.sidebarState.showSwitchPanelButtons();
|
||||
} else {
|
||||
this.sidebarState.hideSwitchPanelButtons();
|
||||
}
|
||||
|
||||
this.sidebarState.setPanel(MAIN_PANEL);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,12 +4,6 @@ import { getUserChatSeparateSidebarMode } from "discourse/plugins/chat/discourse
|
|||
export const CHAT_PANEL = "chat";
|
||||
|
||||
export function initSidebarState(api, user) {
|
||||
if (api.getSidebarPanel()?.key === ADMIN_PANEL) {
|
||||
return;
|
||||
}
|
||||
|
||||
api.setSidebarPanel(MAIN_PANEL);
|
||||
|
||||
const chatSeparateSidebarMode = getUserChatSeparateSidebarMode(user);
|
||||
if (chatSeparateSidebarMode.fullscreen) {
|
||||
api.setCombinedSidebarMode();
|
||||
|
@ -20,4 +14,10 @@ export function initSidebarState(api, user) {
|
|||
api.setCombinedSidebarMode();
|
||||
api.hideSidebarSwitchPanelButtons();
|
||||
}
|
||||
|
||||
if (api.getSidebarPanel()?.key === ADMIN_PANEL) {
|
||||
return;
|
||||
}
|
||||
|
||||
api.setSidebarPanel(MAIN_PANEL);
|
||||
}
|
||||
|
|
|
@ -22,4 +22,31 @@ describe "Admin Revamp | Sidebar Navigation | Plugin Links", type: :system do
|
|||
find(".header-sidebar-toggle").click
|
||||
expect(sidebar).to have_section_link("Chat", href: "/admin/plugins/chat", count: 1)
|
||||
end
|
||||
|
||||
describe "admin sidebar respects separated and combined sidebar modes" do
|
||||
it "reverts to always (separated) mode after entering and leaving admin section" do
|
||||
admin.user_option.update!(
|
||||
chat_separate_sidebar_mode: UserOption.chat_separate_sidebar_modes[:always],
|
||||
)
|
||||
visit("/")
|
||||
expect(sidebar).to have_switch_button("chat")
|
||||
sidebar.click_link_in_section("community", "admin")
|
||||
expect(sidebar).to have_no_switch_button("chat")
|
||||
find("#site-logo").click
|
||||
expect(sidebar).to have_switch_button("chat")
|
||||
end
|
||||
|
||||
it "reverts to the never (combined) mode after entering and leaving admin section" do
|
||||
admin.user_option.update!(
|
||||
chat_separate_sidebar_mode: UserOption.chat_separate_sidebar_modes[:never],
|
||||
)
|
||||
visit("/")
|
||||
expect(sidebar).to have_section("chat-channels")
|
||||
expect(sidebar).to have_no_switch_button("chat")
|
||||
sidebar.click_link_in_section("community", "admin")
|
||||
expect(sidebar).to have_no_section("chat-channels")
|
||||
find("#site-logo").click
|
||||
expect(sidebar).to have_section("chat-channels")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue