From cd14b0c0bee0cf63c59b64b6f7213e31a37f11a7 Mon Sep 17 00:00:00 2001 From: Mark VanLandingham Date: Wed, 18 Jun 2025 17:34:08 -0500 Subject: [PATCH] FIX: Bring back empty state message when appropriate (#1446) The Today section was added always, but a side-effect was that we hid the empty state component. This commit brings back the empty state --- .../services/ai-conversations-sidebar-manager.js | 10 ++++++++++ .../modules/ai-bot-conversations/common.scss | 16 ++++++++++++++-- spec/system/ai_bot/homepage_spec.rb | 16 ++++++++++++++++ 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/assets/javascripts/discourse/services/ai-conversations-sidebar-manager.js b/assets/javascripts/discourse/services/ai-conversations-sidebar-manager.js index 6c15d5a3..c7260b58 100644 --- a/assets/javascripts/discourse/services/ai-conversations-sidebar-manager.js +++ b/assets/javascripts/discourse/services/ai-conversations-sidebar-manager.js @@ -84,6 +84,13 @@ export default class AiConversationsSidebarManager extends Service { ); } + addEmptyStateClass() { + document.body.classList.toggle( + "has-empty-ai-conversations-sidebar", + !this.topics.length + ); + } + forceCustomSidebar() { document.body.classList.add("has-ai-conversations-sidebar"); if (!this.sidebarState.isForcingSidebar) { @@ -100,6 +107,7 @@ export default class AiConversationsSidebarManager extends Service { // don't render sidebar multiple times if (this._didInit) { + this.addEmptyStateClass(); return true; } @@ -107,6 +115,7 @@ export default class AiConversationsSidebarManager extends Service { this.fetchMessages().then(() => { this.sidebarState.setPanel(AI_CONVERSATIONS_PANEL); + this.addEmptyStateClass(); }); return true; @@ -140,6 +149,7 @@ export default class AiConversationsSidebarManager extends Service { stopForcingCustomSidebar() { 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) { diff --git a/assets/stylesheets/modules/ai-bot-conversations/common.scss b/assets/stylesheets/modules/ai-bot-conversations/common.scss index 2b4b6fd8..27275aa4 100644 --- a/assets/stylesheets/modules/ai-bot-conversations/common.scss +++ b/assets/stylesheets/modules/ai-bot-conversations/common.scss @@ -23,8 +23,20 @@ body.has-ai-conversations-sidebar { } } - // we always have the "today" section rendered at the top of the sidebar but hide it when empty - .sidebar-section[data-section-name="today"]:has(.ai-bot-sidebar-empty-state) { + // When the sidebar is empty, we want to hide the "Today" header + // and only show the empty state component + &.has-empty-ai-conversations-sidebar + .sidebar-section[data-section-name="today"] + .sidebar-section-header-wrapper { + display: none; + } + + // When the sidebar isn't empty, BUT "today" is empty, hide + // the entire section + &:not(.has-empty-ai-conversations-sidebar) + .sidebar-section[data-section-name="today"]:has( + .ai-bot-sidebar-empty-state + ) { display: none; } diff --git a/spec/system/ai_bot/homepage_spec.rb b/spec/system/ai_bot/homepage_spec.rb index f2b0bab1..ef4ea912 100644 --- a/spec/system/ai_bot/homepage_spec.rb +++ b/spec/system/ai_bot/homepage_spec.rb @@ -226,6 +226,22 @@ RSpec.describe "AI Bot - Homepage", type: :system do expect(sidebar).to have_section_link(pm.title) end + it "shows empty state when no PMs exist" do + pm.destroy! + + visit "/" + header.click_bot_button + + expect(page).to have_css(".sidebar-section .ai-bot-sidebar-empty-state", visible: true) + end + + it "doesn't show empty state when a PM exists" do + visit "/" + header.click_bot_button + + expect(page).to have_no_css(".sidebar-section .ai-bot-sidebar-empty-state") + end + it "displays last_7_days label in the sidebar" do pm.update!(last_posted_at: Time.zone.now - 5.days) visit "/"