π OpenHands: AI-Driven Development
fix: sort full visible list when ordering by Created (#573)
Hiep Le42a7a2967a08
diff --git a/__tests__/components/features/conversation-panel/conversation-panel.test.tsx b/__tests__/components/features/conversation-panel/conversation-panel.test.tsxindex c014ebfde6..4d08b5e1f7 100644--- a/__tests__/components/features/conversation-panel/conversation-panel.test.tsx+++ b/__tests__/components/features/conversation-panel/conversation-panel.test.tsx@@ -17,6 +17,7 @@ import { createRoutesStub } from "react-router";import React from "react";import { renderWithProviders } from "test-utils";import { ConversationPanel } from "#/components/features/conversation-panel/conversation-panel";+import { useConversationPanelPreferencesStore } from "#/stores/conversation-panel-preferences-store";import AgentServerConversationService from "#/api/conversation-service/agent-server-conversation-service.api";import { AppConversation } from "#/api/conversation-service/agent-server-conversation-service.types";import { ExecutionStatus } from "#/types/agent-server/core";@@ -534,6 +535,75 @@ describe("ConversationPanel", () => {expect(await screen.findByText("Paged Conversation")).toBeInTheDocument();});+ it("orders the entire visible list by created_at when Created sort is selected, across the recent/older partition", async () => {+ // Arrange: three conversations whose `created_at` ordering diverges+ // from `updated_at` across the 1-hour partition cutoff. If the panel+ // honored only the within-bucket sort, "Old Touched" (created 10d ago+ // but touched 30m ago) would render in the recent bucket *above* the+ // "Mid Stale" / "Newest Stale" entries that live in the older bucket+ // but were created more recently. Created-sort must order the whole+ // visible list by `created_at`, not just within each partition.+ const now = Date.now();+ const isoMinutesAgo = (m: number) =>+ new Date(now - m * 60 * 1000).toISOString();+ const isoDaysAgo = (d: number) =>+ new Date(now - d * 24 * 60 * 60 * 1000).toISOString();++ useConversationPanelPreferencesStore.setState({+ conversationSort: "updated",+ organizeMode: "chronological",+ showOlderConversations: true,+ });++ vi.spyOn(+ AgentServerConversationService,+ "searchConversations",+ ).mockResolvedValue({+ items: [+ createMockConversation({+ id: "old-touched",+ title: "Old Touched",+ created_at: isoDaysAgo(10),+ updated_at: isoMinutesAgo(30),+ }),+ createMockConversation({+ id: "newest-stale",+ title: "Newest Stale",+ created_at: isoDaysAgo(1),+ updated_at: isoDaysAgo(1),+ }),+ createMockConversation({+ id: "mid-stale",+ title: "Mid Stale",+ created_at: isoDaysAgo(3),+ updated_at: isoDaysAgo(3),+ }),+ ],+ next_page_id: null,+ });++ const user = userEvent.setup();+ renderConversationPanel();+ await screen.findByText("Old Touched");++ // Act: open the filter menu and switch sort to Created.+ await user.click(screen.getByTestId("older-conversations-filter-toggle"));+ await user.click(+ screen.getByRole("menuitemradio", {+ name: /CONVERSATION_PANEL\$SORT_CREATED/,+ }),+ );++ // Assert: rendered cards are in strict created_at desc order across+ // the full visible list, regardless of which partition they came from.+ const cards = await screen.findAllByTestId("conversation-card");+ expect(cards.map((card) => card.textContent ?? "")).toEqual([+ expect.stringContaining("Newest Stale"),+ expect.stringContaining("Mid Stale"),+ expect.stringContaining("Old Touched"),+ ]);+ });+it("should cancel stopping a conversation", async () => {const user = userEvent.setup();diff --git a/src/components/features/conversation-panel/conversation-panel.tsx b/src/components/features/conversation-panel/conversation-panel.tsxindex 804501e24c..9306049b3b 100644--- a/src/components/features/conversation-panel/conversation-panel.tsx+++ b/src/components/features/conversation-panel/conversation-panel.tsx@@ -191,15 +191,18 @@ export function ConversationPanel({[scopedConversations],);- const sortedRecent = React.useMemo(- () => sortConversationsByField(recentScoped, conversationSort),- [recentScoped, conversationSort],- );-- const sortedOlder = React.useMemo(- () => sortConversationsByField(olderScoped, conversationSort),- [olderScoped, conversationSort],- );+ // Sort the full visible set as one list. The recent/older partition is+ // still computed (it gates the "Show older" toggle and "Load more"+ // visibility), but the rendering must not use it as a visual boundary β+ // when sorting by `created`, a stale-but-recently-touched conversation+ // would otherwise land in `recent` and render above an actually-newer-+ // by-`created_at` conversation sitting in `older`.+ const sortedVisibleConversations = React.useMemo(() => {+ const visible = showOlderConversations+ ? [...recentScoped, ...olderScoped]+ : recentScoped;+ return sortConversationsByField(visible, conversationSort);+ }, [recentScoped, olderScoped, showOlderConversations, conversationSort]);const groupLabels = React.useMemo(() => ({@@ -248,9 +251,7 @@ export function ConversationPanel({[conversationSort, recentScoped],);- const visibleFlatCount =- sortedRecent.length +- (!compact && showOlderConversations ? sortedOlder.length : 0);+ const visibleFlatCount = sortedVisibleConversations.length;const visibleGroupedCount = React.useMemo(() => {if (!conversationGroups) {@@ -631,12 +632,7 @@ export function ConversationPanel({{!showInitialSkeleton &&!compact &&organizeMode === "chronological" ? (- <>- {sortedRecent.map(renderConversationCard)}- {showOlderConversations- ? sortedOlder.map(renderConversationCard)- : null}- </>+ <>{sortedVisibleConversations.map(renderConversationCard)}</>) : null}{/* Explicit "Load more" trigger. Only shown when more pages exist