Quellcode durchsuchen

fix(paas): harden inbox mounting and read state

241880436@seecoder.cn vor 4 Tagen
Ursprung
Commit
60f30ada95

+ 1 - 1
PAAS_RESEARCH_INBOX_PLAN.zh-CN.md

@@ -827,7 +827,7 @@ git commit -m "docs(paas): document research inbox"
 - [ ] 完成未读打开一次后消失,刷新后仍保持已读。
 - [ ] 完成未读打开一次后消失,刷新后仍保持已读。
 - [ ] 同一 run 不会同时因会话和任务索引重复出现。
 - [ ] 同一 run 不会同时因会话和任务索引重复出现。
 - [ ] 任务索引不匹配当前项目 `thread_id` 时不进入 Inbox。
 - [ ] 任务索引不匹配当前项目 `thread_id` 时不进入 Inbox。
-- [ ] Escape 关闭面板并将焦点还给入口;点击外部也关闭。
+- [ ] 焦点在 Inbox 内时,Escape 关闭面板并将焦点还给入口;焦点在 Inbox 外时 Escape 由所在菜单或控件处理;点击外部也关闭。
 - [ ] 旧顶栏“进行中 · 待确认”重复计数已移除。
 - [ ] 旧顶栏“进行中 · 待确认”重复计数已移除。
 - [ ] 1280/600 宽度、亮暗主题无横向溢出。
 - [ ] 1280/600 宽度、亮暗主题无横向溢出。
 - [ ] 单测、完整 E2E、App/Desktop 类型检查和构建通过。
 - [ ] 单测、完整 E2E、App/Desktop 类型检查和构建通过。

+ 28 - 0
packages/app/e2e/paas/inbox.spec.ts

@@ -62,3 +62,31 @@ test("opening an approval keeps it listed in inbox", async ({ page }) => {
   await expect(page.getByRole("dialog", { name: "待处理" })).toHaveCount(0)
   await expect(page.getByRole("dialog", { name: "待处理" })).toHaveCount(0)
   await expect(page.getByRole("button", { name: "待处理 1 项", exact: true })).toBeVisible()
   await expect(page.getByRole("button", { name: "待处理 1 项", exact: true })).toBeVisible()
 })
 })
+
+test("completed unread stays read after a reload", async ({ page }) => {
+  await page.goto("/e2e/paas/index.html?completed")
+  await page.getByLabel("API Key", { exact: true }).fill("inbox-reload")
+  await page.getByRole("button", { name: "连接平台", exact: true }).click()
+  await page
+    .getByRole("button", { name: /已有研究/ })
+    .first()
+    .click()
+  const inbox = page.getByRole("button", { name: "待处理 1 项", exact: true })
+  await expect(inbox).toBeVisible()
+  await inbox.click()
+  await page
+    .getByRole("dialog", { name: "待处理" })
+    .getByRole("button", { name: /已有研究/ })
+    .click()
+  await expect(page.getByRole("button", { name: /待处理/ })).toHaveCount(0)
+
+  await page.reload()
+  await page.getByLabel("API Key", { exact: true }).fill("inbox-reload")
+  await page.getByRole("button", { name: "连接平台", exact: true }).click()
+  await page
+    .getByRole("button", { name: /已有研究/ })
+    .first()
+    .click()
+  await expect(page.getByRole("heading", { name: "研究计划", exact: true })).toBeVisible()
+  await expect(page.getByRole("button", { name: /待处理/ })).toHaveCount(0)
+})

+ 1 - 1
packages/app/src/pages/paas/chat.tsx

@@ -669,7 +669,7 @@ export function PaasChat(props: {
           </Portal>
           </Portal>
         )}
         )}
       </Show>
       </Show>
-      <Show when={props.inboxMount}>
+      <Show when={inbox().length ? props.inboxMount : undefined}>
         {(mount) => (
         {(mount) => (
           <Portal mount={mount()}>
           <Portal mount={mount()}>
             <InboxPanel items={inbox()} onOpen={openInboxItem} />
             <InboxPanel items={inbox()} onOpen={openInboxItem} />

+ 12 - 0
packages/app/src/pages/paas/inbox-panel-state.ts

@@ -0,0 +1,12 @@
+import { createEffect, createSignal } from "solid-js"
+import type { InboxItem } from "./inbox"
+
+// The list can empty out while the panel stays mounted; clear the open state so a
+// recreated details element cannot remount expanded from a stale signal.
+export function createInboxOpenState(items: () => InboxItem[]) {
+  const [open, setOpen] = createSignal(false)
+  createEffect(() => {
+    if (!items().length) setOpen(false)
+  })
+  return { open, setOpen }
+}

+ 3 - 7
packages/app/src/pages/paas/inbox-panel.tsx

@@ -1,18 +1,14 @@
-import { For, Show, createEffect, createSignal, onCleanup, onMount } from "solid-js"
+import { For, Show, onCleanup, onMount } from "solid-js"
 import { ResearchIcon } from "./research-icon"
 import { ResearchIcon } from "./research-icon"
+import { createInboxOpenState } from "./inbox-panel-state"
 import type { InboxItem } from "./inbox"
 import type { InboxItem } from "./inbox"
 
 
 const labels = { approval: "待确认", failed: "失败", unread: "未读结果" }
 const labels = { approval: "待确认", failed: "失败", unread: "未读结果" }
 
 
 export function InboxPanel(props: { items: InboxItem[]; onOpen: (item: InboxItem) => void }) {
 export function InboxPanel(props: { items: InboxItem[]; onOpen: (item: InboxItem) => void }) {
-  const [open, setOpen] = createSignal(false)
+  const { open, setOpen } = createInboxOpenState(() => props.items)
   let root: HTMLDetailsElement | undefined
   let root: HTMLDetailsElement | undefined
 
 
-  createEffect(() => {
-    // A recreated panel must not mount open when the previous item list emptied out.
-    if (!props.items.length) setOpen(false)
-  })
-
   onMount(() => {
   onMount(() => {
     const close = (event: KeyboardEvent) => {
     const close = (event: KeyboardEvent) => {
       if (event.key !== "Escape" || !open()) return
       if (event.key !== "Escape" || !open()) return

+ 0 - 3
packages/app/src/pages/paas/studio.css

@@ -826,9 +826,6 @@
   align-items: center;
   align-items: center;
   flex-shrink: 0;
   flex-shrink: 0;
 }
 }
-.paas-topbar-inbox:empty {
-  display: none;
-}
 .paas-inbox {
 .paas-inbox {
   position: relative;
   position: relative;
 }
 }

+ 38 - 0
packages/app/test-browser/paas-inbox-panel.test.ts

@@ -0,0 +1,38 @@
+import { expect, test } from "bun:test"
+import { createRoot, createSignal } from "solid-js"
+import type { InboxItem } from "@/pages/paas/inbox"
+import { createInboxOpenState } from "@/pages/paas/inbox-panel-state"
+
+// Bun cannot compile Solid JSX here and the unit suite resolves the server Solid build,
+// where effects are inert, so the panel state is covered by the browser-condition suite.
+
+const item: InboxItem = {
+  id: "unread:run_1",
+  kind: "unread",
+  title: "研究计划",
+  detail: "科研助手",
+  projectID: "project_1",
+  chatID: "chat_1",
+  runID: "run_1",
+  at: 1,
+}
+
+test("an emptied inbox list resets open so a recreated panel stays closed", () => {
+  const [items, setItems] = createSignal([item])
+  const mounted = createRoot((dispose) => ({
+    panel: createInboxOpenState(items),
+    dispose,
+  }))
+
+  expect(mounted.panel.open()).toBe(false)
+  mounted.panel.setOpen(true)
+  expect(mounted.panel.open()).toBe(true)
+
+  setItems([])
+  expect(mounted.panel.open()).toBe(false)
+
+  setItems([item])
+  expect(mounted.panel.open()).toBe(false)
+
+  mounted.dispose()
+})