mirror of
https://github.com/discourse/discourse-ai.git
synced 2025-06-29 19:12:15 +00:00
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
This commit is contained in:
parent
cea8fd423e
commit
cd14b0c0be
@ -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) {
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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 "/"
|
||||
|
Loading…
x
Reference in New Issue
Block a user