Skip to content

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

FIX: Respect sidebar panel set by destination route when leaving AI Bot (#36868)

Régis Hanol8dc1d77e010f
diff --git a/plugins/chat/spec/system/message_notifications_with_sidebar_spec.rb b/plugins/chat/spec/system/message_notifications_with_sidebar_spec.rb
index 5852e6924ad..edca2827d32 100644
--- a/plugins/chat/spec/system/message_notifications_with_sidebar_spec.rb
+++ b/plugins/chat/spec/system/message_notifications_with_sidebar_spec.rb
@@ -186,7 +186,7 @@ RSpec.describe "Message notifications - with sidebar", type: :system do
create_message(channel: dm_channel, creator: other_user)
- expect(chat_sidebar).to have_direct_message_channel(dm_channel)
+ expect(chat_sidebar).to have_direct_message_channel(dm_channel, mention: true)
expect(chat_sidebar).to have_no_start_new_dm
end
end
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.js
index fdd4e7be553..0bc7b25c617 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
@@ -6,7 +6,7 @@ import { TrackedArray } from "@ember-compat/tracked-built-ins";
import { ajax } from "discourse/lib/ajax";
import discourseDebounce from "discourse/lib/debounce";
import { autoUpdatingRelativeAge } from "discourse/lib/formatter";
-import { ADMIN_PANEL, MAIN_PANEL } from "discourse/lib/sidebar/panels";
+import { MAIN_PANEL } from "discourse/lib/sidebar/panels";
import { defaultHomepage } from "discourse/lib/utilities";
import { i18n } from "discourse-i18n";
import AiBotSidebarEmptyState from "../components/ai-bot-sidebar-empty-state";
@@ -159,8 +159,11 @@ export default class AiConversationsSidebarManager extends Service {
document.body.classList.remove("has-ai-conversations-sidebar");
document.body.classList.remove("has-empty-ai-conversations-sidebar");
- const isAdmin = this.sidebarState.currentPanel?.key === ADMIN_PANEL;
- if (this.sidebarState.isForcingSidebar && !isAdmin) {
+ // Only reset if no other route has claimed the sidebar in its activate() hook
+ const isStillAiPanel =
+ this.sidebarState.currentPanel?.key === AI_CONVERSATIONS_PANEL;
+
+ if (this.sidebarState.isForcingSidebar && isStillAiPanel) {
this.sidebarState.setPanel(MAIN_PANEL);
this.sidebarState.isForcingSidebar = false;
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.rb
new file mode 100644
index 00000000000..c06356d463c
--- /dev/null
+++ b/plugins/discourse-ai/spec/system/ai_bot/ai_bot_sidebar_navigation_spec.rb
@@ -0,0 +1,44 @@
+# frozen_string_literal: true
+
+RSpec.describe "AI Bot sidebar navigation" do
+ fab!(:admin)
+ fab!(:gpt_4) { Fabricate(:llm_model, name: "gpt-4") }
+ fab!(:channel, :category_channel)
+
+ let(:ai_pm_homepage) { PageObjects::Components::AiPmHomepage.new }
+ let(:chat_page) { PageObjects::Pages::Chat.new }
+
+ before do
+ enable_current_plugin
+ SiteSetting.ai_bot_enabled = true
+ toggle_enabled_bots(bots: [gpt_4])
+ SiteSetting.navigation_menu = "sidebar"
+ SiteSetting.chat_separate_sidebar_mode = "always"
+ chat_system_bootstrap
+ channel.add(admin)
+ sign_in(admin)
+ end
+
+ it "respects sidebar panel set by destination route" 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(".sidebar-sections.chat-panel")
+ end
+
+ it "resets to main panel when destination route has no panel" do
+ ai_pm_homepage.visit
+
+ expect(page).to have_css(".sidebar-sections.ai-conversations-panel")
+
+ find(".sidebar-sections__back-to-forum").click
+
+ expect(page).to have_no_css(".sidebar-sections.ai-conversations-panel")
+ expect(page).to have_no_css(".sidebar-sections.chat-panel")
+ end
+end