From cdb6210b45d436bbf2e19fd080041994c885cd02 Mon Sep 17 00:00:00 2001 From: chengyongru <61816729+chengyongru@users.noreply.github.com> Date: Wed, 14 Oct 2026 14:41:52 +0800 Subject: [PATCH] refactor(webui): remove session list previews and timestamps (#6189) * refactor(webui): remove session list previews and timestamps * test(webui): limit legacy coverage to persisted sidebar files * refactor(webui): simplify chat rows and fix gallery states * refactor(webui): flatten chat row title wrapper --- nanobot/webui/sidebar_state.py | 4 -- tests/utils/test_webui_sidebar_state.py | 15 +++--- webui/src/components/ChatList.tsx | 63 ++++------------------ webui/src/components/Sidebar.tsx | 2 - webui/src/dev/gallery/standalone.tsx | 8 +-- webui/src/hooks/useSidebarState.ts | 4 -- webui/src/lib/types.ts | 2 - webui/src/tests/api.test.ts | 2 - webui/src/tests/app-layout.test.tsx | 7 +-- webui/src/tests/chat-list.test.tsx | 18 +++---- webui/src/tests/component-gallery.test.tsx | 30 +++++++++++ webui/src/tests/nanobot-client.test.ts | 4 -- 12 files changed, 62 insertions(+), 97 deletions(-) diff --git a/nanobot/webui/sidebar_state.py b/nanobot/webui/sidebar_state.py index c28b95610..5248898ff 100644 --- a/nanobot/webui/sidebar_state.py +++ b/nanobot/webui/sidebar_state.py @@ -50,8 +50,6 @@ def default_webui_sidebar_state() -> dict[str, Any]: "workbench": {"version": 1, "tabs": {}}, "view": { "density": "comfortable", - "show_previews": False, - "show_timestamps": False, "show_archived": False, "sort": "updated_desc", }, @@ -144,8 +142,6 @@ def _clean_view(value: Any) -> dict[str, Any]: sort = view.get("sort") return { "density": density if density in _ALLOWED_DENSITIES else default["density"], - "show_previews": bool(view.get("show_previews", default["show_previews"])), - "show_timestamps": bool(view.get("show_timestamps", default["show_timestamps"])), "show_archived": bool(view.get("show_archived", default["show_archived"])), "sort": sort if sort in _ALLOWED_SORTS else default["sort"], } diff --git a/tests/utils/test_webui_sidebar_state.py b/tests/utils/test_webui_sidebar_state.py index c61ff52a2..25b4b0a10 100644 --- a/tests/utils/test_webui_sidebar_state.py +++ b/tests/utils/test_webui_sidebar_state.py @@ -52,7 +52,13 @@ def test_sidebar_state_normalizes_partial_payload(tmp_path, monkeypatch) -> None }, }, }, - "view": {"density": "tiny", "show_archived": True, "sort": "nope"}, + "view": { + "density": "tiny", + "show_archived": True, + "sort": "nope", + "show_previews": True, + "show_timestamps": True, + }, } ), encoding="utf-8", @@ -83,8 +89,6 @@ def test_sidebar_state_normalizes_partial_payload(tmp_path, monkeypatch) -> None } assert state["view"] == { "density": "comfortable", - "show_previews": False, - "show_timestamps": False, "show_archived": True, "sort": "updated_desc", } @@ -100,7 +104,7 @@ def test_sidebar_state_write_is_scoped_to_config_data_dir(tmp_path, monkeypatch) "session_order": ["websocket:b", "websocket:a"], "title_overrides": {"websocket:a": "Release"}, "project_name_overrides": {"/repo": "Core"}, - "view": {"density": "compact", "show_previews": True, "sort": "manual"}, + "view": {"density": "compact", "sort": "manual"}, } ) @@ -110,10 +114,9 @@ def test_sidebar_state_write_is_scoped_to_config_data_dir(tmp_path, monkeypatch) assert state["title_overrides"] == {"websocket:a": "Release"} assert state["project_name_overrides"] == {"/repo": "Core"} assert state["view"]["density"] == "compact" - assert state["view"]["show_previews"] is True assert state["view"]["sort"] == "manual" assert webui_sidebar_state_path().is_file() - assert read_webui_sidebar_state()["pinned_keys"] == ["websocket:a"] + assert read_webui_sidebar_state() == state def test_sidebar_state_persists_only_visible_workbench_groups(tmp_path, monkeypatch) -> None: diff --git a/webui/src/components/ChatList.tsx b/webui/src/components/ChatList.tsx index 2aa499b51..843f28d08 100644 --- a/webui/src/components/ChatList.tsx +++ b/webui/src/components/ChatList.tsx @@ -51,8 +51,6 @@ import { SIDEBAR_SELECTION_ITEM_CLASS, SidebarSelectionHighlight, } from "@/components/SidebarSelectionHighlight"; -import { visibleSessionPreview } from "@/lib/format"; -import { relativeTime } from "@/lib/format-time"; import { COLLAPSED_CHATS_VISIBLE_COUNT, displayTitle, @@ -254,8 +252,6 @@ interface ChatListProps { updatedChatIds?: string[]; recoveryChatIds?: string[]; density?: SidebarDensity; - showPreviews?: boolean; - showTimestamps?: boolean; sort?: SidebarSortMode; showArchived?: boolean; defaultWorkspacePath?: string | null; @@ -297,8 +293,6 @@ export const ChatList = memo(function ChatList({ updatedChatIds = [], recoveryChatIds = [], density = "comfortable", - showPreviews = false, - showTimestamps = false, sort = "updated_desc", showArchived = false, defaultWorkspacePath, @@ -767,7 +761,6 @@ export const ChatList = memo(function ChatList({ : undefined } actionMenuPortalContainer={actionMenuPortalContainer} - updatedAt={showTimestamps ? group.updatedAt : null} /> ) : ( @@ -935,11 +928,6 @@ export const ChatList = memo(function ChatList({ const isPinned = pinned.has(s.key); const isArchived = archived.has(s.key); - const preview = visibleSessionPreview(s.preview); - const showPreview = showPreviews && preview && preview !== title; - const timestamp = showTimestamps - ? relativeTime(s.updatedAt ?? s.createdAt) - : ""; const activityState = running.has(s.chatId) ? "running" : recovery.has(s.chatId) @@ -1013,41 +1001,15 @@ export const ChatList = memo(function ChatList({ partial={tabPartiallySelected} /> ) : null} - - {projectMode ? ( - - - - {title} - - {isPinned ? : null} - {timestamp ? ( - - {timestamp} - - ) : null} - - - ) : ( - - - - {title} - - {isPinned ? : null} - - - )} - {showPreview ? ( - - {preview} - - ) : null} - {timestamp && !projectMode ? ( - - {timestamp} - - ) : null} + + + + {title} + + {isPinned ? : null} @@ -1710,7 +1672,6 @@ function ProjectGroupHeader({ onRequestRename, onNewChat, actionMenuPortalContainer, - updatedAt, }: { active: boolean; label: string; @@ -1722,7 +1683,6 @@ function ProjectGroupHeader({ onRequestRename?: () => void; onNewChat?: () => void; actionMenuPortalContainer?: HTMLElement | null; - updatedAt?: string | null; }) { const { t } = useTranslation(); const projectButton = ( @@ -1776,11 +1736,6 @@ function ProjectGroupHeader({ {projectButton} ) : projectButton} - {updatedAt ? ( - - {relativeTime(updatedAt)} - - ) : null} {onRequestRename || onNewChat ? ( (initialSessions[0].key); const [pinned, setPinned] = useState([]); - const [archived, setArchived] = useState([]); + const [archived, setArchived] = useState(["websocket:gallery-history"]); const [mode, setMode] = useState<"ready" | "loading" | "empty" | "archived">("ready"); const [action, setAction] = useState(""); const toggle = (keys: string[], key: string) => keys.includes(key) ? keys.filter((value) => value !== key) : [...keys, key]; return <> -
setPinned(toggle(pinned, key))} onToggleArchive={(key) => setArchived(toggle(archived, key))} onRequestDelete={(key) => setSessions((items) => items.filter((item) => item.key !== key))} onRequestRename={(_, label) => setAction(`选择重命名:${label}`)} />
diff --git a/webui/src/hooks/useSidebarState.ts b/webui/src/hooks/useSidebarState.ts index c83d45845..e615d07d6 100644 --- a/webui/src/hooks/useSidebarState.ts +++ b/webui/src/hooks/useSidebarState.ts @@ -17,8 +17,6 @@ const DEFAULT_SIDEBAR_STATE: SidebarStatePayload = { workbench: { version: 1, tabs: {} }, view: { density: "comfortable", - show_previews: false, - show_timestamps: false, show_archived: false, sort: "updated_desc", }, @@ -98,8 +96,6 @@ function normalizeSidebarState(raw: unknown): SidebarStatePayload { workbench: normalizeWorkbenchState(value.workbench), view: { density, - show_previews: Boolean(view.show_previews), - show_timestamps: Boolean(view.show_timestamps), show_archived: Boolean(view.show_archived), sort, }, diff --git a/webui/src/lib/types.ts b/webui/src/lib/types.ts index d68ba0986..e64c08262 100644 --- a/webui/src/lib/types.ts +++ b/webui/src/lib/types.ts @@ -523,8 +523,6 @@ export interface WorkbenchState { export interface SidebarViewState { density: SidebarDensity; - show_previews: boolean; - show_timestamps: boolean; show_archived: boolean; sort: SidebarSortMode; } diff --git a/webui/src/tests/api.test.ts b/webui/src/tests/api.test.ts index 1f0b71c39..fe9cb8ee2 100644 --- a/webui/src/tests/api.test.ts +++ b/webui/src/tests/api.test.ts @@ -1185,8 +1185,6 @@ describe("webui API helpers", () => { collapsed_groups: {}, view: { density: "compact" as const, - show_previews: false, - show_timestamps: false, show_archived: true, sort: "updated_desc" as const, }, diff --git a/webui/src/tests/app-layout.test.tsx b/webui/src/tests/app-layout.test.tsx index 084080b14..12d7d1087 100644 --- a/webui/src/tests/app-layout.test.tsx +++ b/webui/src/tests/app-layout.test.tsx @@ -1855,8 +1855,7 @@ describe("App layout", () => { schema_version: 1, pinned_keys: [], archived_keys: [], session_order: [], title_overrides: { [key]: "推特大战场" }, project_name_overrides: {}, tags_by_key: {}, collapsed_groups: {}, workbench: { version: 1, tabs: {} }, - view: { density: "comfortable", show_previews: false, show_timestamps: false, - show_archived: false, sort: "updated_desc" }, + view: { density: "comfortable", show_archived: false, sort: "updated_desc" }, }; mockFetchRoutes({ "/api/settings": baseSettingsPayload(), @@ -2591,8 +2590,6 @@ describe("App layout", () => { collapsed_groups: {}, view: { density: "comfortable", - show_previews: false, - show_timestamps: false, show_archived: false, sort: "updated_desc", }, @@ -2674,8 +2671,6 @@ describe("App layout", () => { collapsed_groups: {}, view: { density: "comfortable", - show_previews: false, - show_timestamps: false, show_archived: false, sort: "title_asc", }, diff --git a/webui/src/tests/chat-list.test.tsx b/webui/src/tests/chat-list.test.tsx index 6573cb03c..58a4789eb 100644 --- a/webui/src/tests/chat-list.test.tsx +++ b/webui/src/tests/chat-list.test.tsx @@ -946,16 +946,19 @@ describe("ChatList", () => { onTogglePin={vi.fn()} onRequestRename={vi.fn()} onToggleArchive={vi.fn()} - showPreviews />, ); const chatsSection = screen.getAllByRole("region")[0]; - const text = chatsSection.textContent ?? ""; + const chats = within(chatsSection).getAllByRole("button", { + name: /^(Newest|Middle|Older) chat$/, + }); - expect(text.indexOf("Newest chat")).toBeLessThan(text.indexOf("Middle chat")); - expect(text.indexOf("Middle chat")).toBeLessThan(text.indexOf("Older chat")); - expect(screen.queryByText("/model fast")).not.toBeInTheDocument(); + expect(chats.map((chat) => chat.textContent)).toEqual([ + "Newest chat", + "Middle chat", + "Older chat", + ]); }); it("shows a pin indicator for pinned chats", () => { @@ -1032,7 +1035,6 @@ describe("ChatList", () => { onRequestRename={vi.fn()} onToggleArchive={vi.fn()} sort="title_asc" - showTimestamps runningChatIds={["zeta"]} />, ); @@ -1092,7 +1094,6 @@ describe("ChatList", () => { onRequestRename={vi.fn()} onToggleArchive={vi.fn()} defaultWorkspacePath="/Users/me/.nanobot/workspace" - showTimestamps />, ); @@ -1444,7 +1445,6 @@ describe("ChatList", () => { onTogglePin={vi.fn()} onRequestRename={vi.fn()} onToggleArchive={vi.fn()} - showTimestamps />, ); @@ -1500,7 +1500,6 @@ describe("ChatList", () => { onTogglePin={vi.fn()} onRequestRename={vi.fn()} onToggleArchive={vi.fn()} - showTimestamps />, ); @@ -1550,7 +1549,6 @@ describe("ChatList", () => { onTogglePin={vi.fn()} onRequestRename={vi.fn()} onToggleArchive={vi.fn()} - showTimestamps />, ); diff --git a/webui/src/tests/component-gallery.test.tsx b/webui/src/tests/component-gallery.test.tsx index 9570118b4..c49a7630e 100644 --- a/webui/src/tests/component-gallery.test.tsx +++ b/webui/src/tests/component-gallery.test.tsx @@ -125,6 +125,36 @@ it("submits a message through the actual composer using only local preview state expect(fetch.mock.calls[0][0]).toBe("/__nanobot_components"); }); +it("switches the chat list preview between ready, loading, empty and archived states", async () => { + const source = "webui/src/components/SidebarSelectionHighlight.tsx"; + window.history.replaceState({}, "", `/gallery.html#${new URLSearchParams({ component: source })}`); + vi.stubGlobal("fetch", vi.fn().mockResolvedValue({ ok: true, json: async () => inventory })); + render(); + await screen.findByRole("heading", { name: "ChatList · 会话列表" }); + const preview = within(screen.getByRole("region", { name: "Component preview" })); + const setMode = async (mode: string) => { + await userEvent.click(preview.getByRole("combobox", { name: "会话列表状态" })); + await userEvent.click(screen.getByRole("option", { name: mode, exact: true })); + }; + + expect(preview.getByRole("button", { name: "@design 组件设计" })).toBeVisible(); + expect(preview.getByRole("button", { name: "@tests 验证交互" })).toBeVisible(); + expect(preview.getAllByRole("button", { name: /^@/ })).toHaveLength(2); + + await setMode("loading"); + expect(preview.getByText("Loading…")).toBeVisible(); + await setMode("empty"); + expect(preview.getByText("No sessions yet.")).toBeVisible(); + await setMode("archived"); + const archived = within(preview.getByRole("region", { name: "Archived" })); + expect(archived.getByRole("button", { name: "@history 历史方案" })).toBeVisible(); + expect(preview.getAllByRole("button", { name: /^@/ })).toHaveLength(3); + + await setMode("ready"); + expect(preview.getByRole("button", { name: "@design 组件设计" })).toHaveAttribute("aria-current", "page"); + expect(preview.getAllByRole("button", { name: /^@/ })).toHaveLength(2); +}); + it("edits a pairing route without mounting a client or making a gateway mutation", async () => { const source = "webui/src/components/remote/PairRouteSettingsView.tsx"; window.history.replaceState({}, "", `/gallery.html#${new URLSearchParams({ component: source })}`); diff --git a/webui/src/tests/nanobot-client.test.ts b/webui/src/tests/nanobot-client.test.ts index 5883fa5c5..c6a254b74 100644 --- a/webui/src/tests/nanobot-client.test.ts +++ b/webui/src/tests/nanobot-client.test.ts @@ -1328,8 +1328,6 @@ describe("NanobotClient", () => { workbench: { version: 1, tabs: {} }, view: { density: "comfortable", - show_previews: false, - show_timestamps: false, show_archived: false, sort: "manual", }, @@ -1392,8 +1390,6 @@ describe("NanobotClient", () => { }, view: { density: "comfortable", - show_previews: false, - show_timestamps: false, show_archived: false, sort: "updated_desc", },