DEV: Update sidebar grouping date labels (#1290)

- Add `Today` label
- Make some minor UX changes
- Add specs
This commit is contained in:
Isaac Janzen 2025-04-26 15:31:22 -05:00 committed by GitHub
parent 81ef532268
commit b6630b670f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 26 additions and 12 deletions

View File

@ -87,6 +87,7 @@ export default {
@tracked links = new TrackedArray();
@tracked topics = [];
@tracked hasMore = [];
@tracked loadedTodayLabel = false;
@tracked loadedSevenDayLabel = false;
@tracked loadedThirtyDayLabel = false;
@tracked loadedMonthLabels = new Set();
@ -133,6 +134,7 @@ export default {
addNewPMToSidebar(topic) {
// Reset category labels since we're adding a new topic
this.loadedTodayLabel = false;
this.loadedSevenDayLabel = false;
this.loadedThirtyDayLabel = false;
this.loadedMonthLabels.clear();
@ -225,8 +227,18 @@ export default {
(now - lastPostedAt) / (1000 * 60 * 60 * 24)
);
if (daysDiff <= 1 || !topic.last_posted_at) {
if (!this.loadedTodayLabel) {
this.loadedTodayLabel = true;
return {
text: i18n("discourse_ai.ai_bot.conversations.today"),
classNames: "date-heading",
name: "date-heading-today",
};
}
}
// Last 7 days group
if (daysDiff <= 7) {
else if (daysDiff <= 7) {
if (!this.loadedSevenDayLabel) {
this.loadedSevenDayLabel = true;
return {
@ -273,6 +285,7 @@ export default {
buildSidebarLinks() {
// Reset date header tracking
this.loadedTodayLabel = false;
this.loadedSevenDayLabel = false;
this.loadedThirtyDayLabel = false;
this.loadedMonthLabels.clear();

View File

@ -33,10 +33,7 @@ body.has-ai-conversations-sidebar {
opacity: 0.8;
font-weight: 700;
margin-top: 1em;
&[data-link-name="date-heading-last-7-days"] {
margin-top: 0;
}
font-size: var(--font-down-2);
}
.sidebar-section-link {
@ -236,12 +233,6 @@ body.has-ai-conversations-sidebar {
max-height: 2.5em;
}
.spinner {
margin: 0;
width: 2em;
height: 2em;
}
#ai-bot-conversations-input {
width: 100%;
margin: 0;

View File

@ -727,6 +727,7 @@ en:
new: "New Question"
min_input_length_message: "Message must be longer than 10 characters"
messages_sidebar_title: "Conversations"
today: "Today"
last_7_days: "Last 7 days"
last_30_days: "Last 30 days"
sentiments:

View File

@ -151,11 +151,20 @@ RSpec.describe "AI Bot - Homepage", type: :system do
expect(ai_pm_homepage).to have_homepage
expect(sidebar).to have_section("ai-conversations-history")
expect(sidebar).to have_section_link("Last 7 days")
expect(sidebar).to have_section_link("Today")
expect(sidebar).to have_section_link(pm.title)
expect(sidebar).to have_no_css("button.ai-new-question-button")
end
it "displays last_7_days label in the sidebar" do
pm.update!(last_posted_at: Time.zone.now - 5.days)
visit "/"
header.click_bot_button
expect(ai_pm_homepage).to have_homepage
expect(sidebar).to have_section_link("Last 7 days")
end
it "displays last_30_days label in the sidebar" do
pm.update!(last_posted_at: Time.zone.now - 28.days)
visit "/"