A platform for community discussion. Free, open, simple.
FIX: Clear forced sidebar when leaving AI bot from another panel (#37490)
Keegan George1280021430c5
diff --git a/frontend/discourse/admin/services/admin-sidebar-state-manager.js b/frontend/discourse/admin/services/admin-sidebar-state-manager.jsindex aec30af7ca7..fb34553aeaa 100644--- a/frontend/discourse/admin/services/admin-sidebar-state-manager.js+++ b/frontend/discourse/admin/services/admin-sidebar-state-manager.js@@ -46,6 +46,7 @@ export default class AdminSidebarStateManager extends Service {stopForcingAdminSidebar() {this.sidebarState.setPanel(MAIN_PANEL);this.sidebarState.isForcingSidebar = false;+ this.sidebarState.forcingSidebarPanel = null;}get modals() {@@ -57,6 +58,7 @@ export default class AdminSidebarStateManager extends Service {this.sidebarState.setSeparatedMode();this.sidebarState.hideSwitchPanelButtons();this.sidebarState.isForcingSidebar = true;+ this.sidebarState.forcingSidebarPanel = ADMIN_PANEL;// we may navigate to admin from the header dropdown// and when we do, we have to close itdiff --git a/frontend/discourse/app/services/sidebar-state.js b/frontend/discourse/app/services/sidebar-state.jsindex 2683c824237..3c5341932b2 100644--- a/frontend/discourse/app/services/sidebar-state.js+++ b/frontend/discourse/app/services/sidebar-state.js@@ -24,6 +24,7 @@ export default class SidebarState extends Service {@tracked displaySwitchPanelButtons = false;@tracked filter = "";@tracked isForcingSidebar = false;+ @tracked forcingSidebarPanel = null;panels = panels;activeExpandedSections = new TrackedSet();diff --git a/plugins/discourse-ai/assets/javascripts/discourse/services/ai-conversations-sidebar-manager.js b/plugins/discourse-ai/assets/javascripts/discourse/services/ai-conversations-sidebar-manager.jsindex 0bc7b25c617..f157b962333 100644--- a/plugins/discourse-ai/assets/javascripts/discourse/services/ai-conversations-sidebar-manager.js+++ b/plugins/discourse-ai/assets/javascripts/discourse/services/ai-conversations-sidebar-manager.js@@ -106,6 +106,7 @@ export default class AiConversationsSidebarManager extends Service {}this.sidebarState.isForcingSidebar = true;+ this.sidebarState.forcingSidebarPanel = AI_CONVERSATIONS_PANEL;// calling this before fetching data// helps avoid flash of main sidebar mode@@ -159,13 +160,21 @@ export default class AiConversationsSidebarManager extends Service {document.body.classList.remove("has-ai-conversations-sidebar");document.body.classList.remove("has-empty-ai-conversations-sidebar");- // Only reset if no other route has claimed the sidebar in its activate() hookconst isStillAiPanel =this.sidebarState.currentPanel?.key === AI_CONVERSATIONS_PANEL;- if (this.sidebarState.isForcingSidebar && isStillAiPanel) {- this.sidebarState.setPanel(MAIN_PANEL);+ // Only clear forcing if we were the ones who set it+ const weSetForcing =+ this.sidebarState.forcingSidebarPanel === AI_CONVERSATIONS_PANEL;++ if (this.sidebarState.isForcingSidebar && weSetForcing) {+ if (isStillAiPanel) {+ // No other route claimed the sidebar, reset to main panel+ this.sidebarState.setPanel(MAIN_PANEL);+ }+ // Clear the forcing flag since we set it and we're leavingthis.sidebarState.isForcingSidebar = false;+ this.sidebarState.forcingSidebarPanel = null;this.appEvents.trigger("discourse-ai:stop-forcing-conversations-sidebar");}diff --git a/plugins/discourse-ai/spec/system/ai_bot/ai_bot_sidebar_navigation_spec.rb b/plugins/discourse-ai/spec/system/ai_bot/ai_bot_sidebar_navigation_spec.rbindex c06356d463c..7de6a66abe2 100644--- a/plugins/discourse-ai/spec/system/ai_bot/ai_bot_sidebar_navigation_spec.rb+++ b/plugins/discourse-ai/spec/system/ai_bot/ai_bot_sidebar_navigation_spec.rb@@ -41,4 +41,36 @@ RSpec.describe "AI Bot sidebar navigation" doexpect(page).to have_no_css(".sidebar-sections.ai-conversations-panel")expect(page).to have_no_css(".sidebar-sections.chat-panel")end++ context "with header dropdown navigation menu" do+ before { SiteSetting.navigation_menu = "header dropdown" }++ it "clears forced sidebar when navigating from AI bot to chat and then away" do+ chat_page.prefers_full_page++ ai_pm_homepage.visit++ expect(page).to have_css(".sidebar-sections.ai-conversations-panel")++ find(".chat-header-icon").click++ expect(page).to have_css(".channels-list")+ expect(page).to have_no_css("#sidebar-section-content-categories")++ find("#site-logo").click++ expect(page).to have_no_css(".sidebar-sections")+ expect(page).to have_no_css(".channels-list")+ end++ it "preserves admin sidebar when navigating from AI bot to admin" do+ ai_pm_homepage.visit++ expect(page).to have_css(".sidebar-sections.ai-conversations-panel")++ visit("/admin")++ expect(page).to have_css(".sidebar-sections.admin-panel")+ end+ endend