From 9ec7bbdc20c63f72c7c469cf81433aaa1d1f2b45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zhero=20=26=20=E5=8A=A9=E7=90=86?= Date: Thu, 3 Dec 2026 11:54:02 +0800 Subject: [PATCH] =?UTF-8?q?fix(monitoring):=20=E8=AF=A6=E6=83=85=E6=8A=BD?= =?UTF-8?q?=E5=B1=89=E8=83=BD=E7=82=B9=E5=A4=96=E9=83=A8=E4=B8=8E=20Esc=20?= =?UTF-8?q?=E6=94=B6=E5=9B=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 右侧抽屉是原生 ,内容比视口长时「关闭」被滚出可见区,而点抽屉外面 浏览器不会自动关闭,页面看起来就像卡死在打开状态。 - 抽屉 header 吸顶,关闭按钮始终可见 - 两侧抽屉(差异详情、文件处理详情)统一支持点抽屉外部关闭,点内部不误关 --- .../ReconciliationFindings.drawer.test.tsx | 98 +++++++++++++++++++ web/src/ReconciliationFindings.tsx | 3 +- web/src/WeKnoraMonitor.tsx | 3 +- web/src/dialogBackdrop.ts | 20 ++++ web/src/monitorWorkbench.css | 10 +- 5 files changed, 131 insertions(+), 3 deletions(-) create mode 100644 web/src/ReconciliationFindings.drawer.test.tsx create mode 100644 web/src/dialogBackdrop.ts diff --git a/web/src/ReconciliationFindings.drawer.test.tsx b/web/src/ReconciliationFindings.drawer.test.tsx new file mode 100644 index 0000000..e61d3a9 --- /dev/null +++ b/web/src/ReconciliationFindings.drawer.test.tsx @@ -0,0 +1,98 @@ +// @vitest-environment jsdom +// 右侧抽屉(原生 )必须能用三条路收回:关闭按钮、Esc、点抽屉外面。 +// 这条用例专门盯第三条:内容比视口长时按钮会被滚走,只剩点外面能救场; +// 同时要保证点抽屉内部(含内边距)不会误关。 +import { act } from 'react' +import { createRoot } from 'react-dom/client' +import type { Root } from 'react-dom/client' +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' + +import { FindingDetail } from './ReconciliationFindings' +import type { ReconciliationFinding } from './reconciliationApi' + +const finding: ReconciliationFinding = { + id: 'f1', + run_id: 'run-1', + type: 'R3', + publication_id: 'tp-1', + document_id: '', + title: '线总览.md', + path: '产品/说明书', + source: '钉盘', + target_scope: 'internal', + ledger_state: 'completed', + weknora_parse_status: '', + normalized_state: 'completed', + ledger_sha256: 'deadbeef', + declared_sha256: 'deadbeef', + weknora_file_md5: 'deadbeef', + evidence_level: 'none', + confirmation_state: 'confirmed', + detail: '非平台导入条目,仅统计', + suggested_action: 'none', + action_state: 'open', + weknora_url: '', +} + +let container: HTMLDivElement +let root: Root + +beforeEach(() => { + const reactTestGlobal: { IS_REACT_ACT_ENVIRONMENT: boolean } = globalThis as unknown as { + IS_REACT_ACT_ENVIRONMENT: boolean + } + reactTestGlobal.IS_REACT_ACT_ENVIRONMENT = true + // jsdom 没有实现 dialog 的模态方法。 + HTMLDialogElement.prototype.showModal = function showModal(this: HTMLDialogElement) { + this.open = true + } + container = document.createElement('div') + document.body.appendChild(container) + root = createRoot(container) +}) + +afterEach(() => { + act(() => root.unmount()) + container.remove() +}) + +const renderDrawer = async () => { + const onClose = vi.fn() + await act(async () => root.render()) + const dialog = container.querySelector('dialog') + if (!dialog) throw new Error('抽屉没有渲染出来') + // 抽屉贴在视口右侧:x 800–1280、y 0–694。 + dialog.getBoundingClientRect = () => + ({ + left: 800, + right: 1280, + top: 0, + bottom: 694, + width: 480, + height: 694, + x: 800, + y: 0, + toJSON: () => ({}), + }) as DOMRect + return { onClose, dialog } +} + +const click = async (target: Element, clientX: number, clientY: number) => { + await act(async () => { + target.dispatchEvent(new MouseEvent('click', { bubbles: true, clientX, clientY })) + }) +} + +describe('reconciliation finding drawer', () => { + it('closes when the backdrop is clicked', async () => { + const { onClose, dialog } = await renderDrawer() + await click(dialog, 200, 300) + expect(onClose).toHaveBeenCalledTimes(1) + }) + + it('stays open when the drawer body is clicked', async () => { + const { onClose, dialog } = await renderDrawer() + await click(dialog, 1000, 400) + expect(onClose).not.toHaveBeenCalled() + }) +}) diff --git a/web/src/ReconciliationFindings.tsx b/web/src/ReconciliationFindings.tsx index 52da531..550e451 100644 --- a/web/src/ReconciliationFindings.tsx +++ b/web/src/ReconciliationFindings.tsx @@ -9,6 +9,7 @@ import type { } from './reconciliationApi' import { fetchReconciliationProgress } from './reconciliationApi' import { reconciliationErrorText, reconciliationFailureText, reconciliationStageText } from './reconciliationMessages' +import { onBackdropClick } from './dialogBackdrop' import './monitorWorkbench.css' const time = (value: string | null | undefined) => @@ -441,7 +442,7 @@ export function FindingDetail({ finding, onClose }: { finding: ReconciliationFin ref.current?.showModal() }, []) return ( - +

{typeLabels[finding.type]} · 处理详情