Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 9eeb4c7206 | |||
| 5c2ba3e06f | |||
| efa26813dd |
@@ -128,6 +128,21 @@ SET publication_id = EXCLUDED.publication_id,
|
|||||||
resolution_reason = '',
|
resolution_reason = '',
|
||||||
created_at = EXCLUDED.created_at
|
created_at = EXCLUDED.created_at
|
||||||
RETURNING job_id
|
RETURNING job_id
|
||||||
|
), parked_publication AS (
|
||||||
|
-- 上传重试耗尽时把对账面同步成失败:否则 publication 停在
|
||||||
|
-- pending/uploading,重试入口(要求 failed/stalled)永远 409,
|
||||||
|
-- 页面上的「重试」看起来点了没反应。
|
||||||
|
UPDATE test_publications p
|
||||||
|
SET ingest_state = CASE WHEN p.ingest_state = 'uploading' THEN 'failed' ELSE p.ingest_state END,
|
||||||
|
processing_state = 'failed',
|
||||||
|
last_error = $3,
|
||||||
|
updated_at = $4
|
||||||
|
FROM updated
|
||||||
|
WHERE updated.state = 'failed'
|
||||||
|
AND updated.type = 'test.upload'
|
||||||
|
AND updated.payload->>'publication_id' = p.id
|
||||||
|
AND p.knowledge_id = ''
|
||||||
|
RETURNING p.id
|
||||||
)
|
)
|
||||||
SELECT id FROM updated
|
SELECT id FROM updated
|
||||||
`
|
`
|
||||||
|
|||||||
@@ -273,8 +273,8 @@ WITH updated AS (
|
|||||||
max_attempts, idempotency_key, created_at, updated_at
|
max_attempts, idempotency_key, created_at, updated_at
|
||||||
)
|
)
|
||||||
SELECT 'job-' || substring(md5($1 || '#test.poll#' || updated.retry_count || '#1') from 1 for 32),
|
SELECT 'job-' || substring(md5($1 || '#test.poll#' || updated.retry_count || '#1') from 1 for 32),
|
||||||
'test.poll', $4::jsonb, 'pending', $5, $6, $7,
|
'test.poll', $5::jsonb, 'pending', $6, $7, $8,
|
||||||
'test-poll:' || $1 || ':' || updated.retry_count || ':1', $3, $3
|
'test-poll:' || $1 || ':' || updated.retry_count || ':1', $4, $4
|
||||||
FROM updated
|
FROM updated
|
||||||
ON CONFLICT (idempotency_key) DO NOTHING
|
ON CONFLICT (idempotency_key) DO NOTHING
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -232,6 +232,13 @@ func (c *Client) UploadFile(ctx context.Context, request UploadRequest) (Knowled
|
|||||||
req.Header.Set("Accept", "application/json")
|
req.Header.Set("Accept", "application/json")
|
||||||
req.Header.Set("Content-Type", writer.FormDataContentType())
|
req.Header.Set("Content-Type", writer.FormDataContentType())
|
||||||
req.Header.Set("X-API-Key", c.apiKey)
|
req.Header.Set("X-API-Key", c.apiKey)
|
||||||
|
// A platform-scoped key is refused with 409 TENANT_REQUIRED until it names a
|
||||||
|
// workspace, and a multipart body cannot be replayed: the workspace has to be
|
||||||
|
// attached here, from the one BeginTask already discovered. Leaving it off
|
||||||
|
// turned every upload into a "conflict" that the handler read as a duplicate.
|
||||||
|
if tenant := c.currentTenant(); tenant != "" {
|
||||||
|
req.Header.Set("X-Tenant-ID", tenant)
|
||||||
|
}
|
||||||
resp, err := c.httpClient.Do(req)
|
resp, err := c.httpClient.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
_ = pipeReader.CloseWithError(err)
|
_ = pipeReader.CloseWithError(err)
|
||||||
@@ -245,8 +252,19 @@ func (c *Client) UploadFile(ctx context.Context, request UploadRequest) (Knowled
|
|||||||
|
|
||||||
var response knowledgeResponse
|
var response knowledgeResponse
|
||||||
if resp.StatusCode == http.StatusConflict {
|
if resp.StatusCode == http.StatusConflict {
|
||||||
if err := c.decodeBody(resp, &response); err != nil {
|
payload, readErr := io.ReadAll(io.LimitReader(resp.Body, c.maxResponseBytes+1))
|
||||||
return Knowledge{}, err
|
resp.Body.Close()
|
||||||
|
if readErr != nil {
|
||||||
|
return Knowledge{}, errors.New("read WeKnora response")
|
||||||
|
}
|
||||||
|
// TENANT_REQUIRED shares the 409 status with a real duplicate. Reading it
|
||||||
|
// as ErrConflict made the caller adopt a "duplicate" that never existed,
|
||||||
|
// so it is reported as a bare 409 and dead-letters with a clear reason.
|
||||||
|
if bytes.Contains(payload, []byte(`"TENANT_REQUIRED"`)) {
|
||||||
|
return Knowledge{}, &HTTPError{StatusCode: http.StatusConflict}
|
||||||
|
}
|
||||||
|
if err := json.Unmarshal(payload, &response); err != nil {
|
||||||
|
return Knowledge{}, errors.New("decode WeKnora response")
|
||||||
}
|
}
|
||||||
return response.Data, ErrConflict
|
return response.Data, ErrConflict
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -555,6 +555,106 @@ func TestClientTenantKeyNeverSendsWorkspaceHeader(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// A multipart upload cannot be replayed, so the workspace that BeginTask
|
||||||
|
// discovered has to ride on the upload request itself. Without it a 0.9
|
||||||
|
// platform key gets 409 TENANT_REQUIRED and the caller reads that as a
|
||||||
|
// duplicate document.
|
||||||
|
func TestUploadFileSendsDiscoveredWorkspace(t *testing.T) {
|
||||||
|
const apiKey = "platform" + "-key"
|
||||||
|
var uploadTenant atomic.Value
|
||||||
|
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
switch r.URL.Path {
|
||||||
|
case "/api/v1/tenants/all":
|
||||||
|
_, _ = w.Write([]byte(`{"success":true,"data":{"items":[{"id":10000}]}}`))
|
||||||
|
case "/api/v1/knowledge-bases/kb-1":
|
||||||
|
if r.Header.Get("X-Tenant-ID") != "10000" {
|
||||||
|
w.WriteHeader(http.StatusConflict)
|
||||||
|
_, _ = w.Write([]byte(`{"code":"TENANT_REQUIRED","error":"Workspace required"}`))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
_, _ = w.Write([]byte(`{"success":true,"data":{"id":"kb-1","tenant_id":10000}}`))
|
||||||
|
case "/api/v1/knowledge-bases/kb-1/knowledge/file":
|
||||||
|
uploadTenant.Store(r.Header.Get("X-Tenant-ID"))
|
||||||
|
if r.Header.Get("X-Tenant-ID") != "10000" {
|
||||||
|
w.WriteHeader(http.StatusConflict)
|
||||||
|
_, _ = w.Write([]byte(`{"code":"TENANT_REQUIRED","error":"Workspace required"}`))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
_, _ = w.Write([]byte(`{"success":true,"data":{"id":"knowledge-1","knowledge_base_id":"kb-1","parse_status":"processing"}}`))
|
||||||
|
default:
|
||||||
|
t.Fatalf("unexpected path %s", r.URL.Path)
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
defer server.Close()
|
||||||
|
|
||||||
|
client, err := NewClient(ClientConfig{BaseURL: server.URL, APIKey: apiKey, Timeout: time.Second})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if _, err := client.GetKnowledgeBase(context.Background(), "kb-1"); err != nil {
|
||||||
|
t.Fatalf("GetKnowledgeBase() error = %v", err)
|
||||||
|
}
|
||||||
|
knowledge, err := client.UploadFile(context.Background(), UploadRequest{
|
||||||
|
KnowledgeBaseID: "kb-1",
|
||||||
|
FileName: "doc.pdf",
|
||||||
|
Content: strings.NewReader("%PDF-1.4"),
|
||||||
|
})
|
||||||
|
if err != nil || knowledge.ID != "knowledge-1" {
|
||||||
|
t.Fatalf("UploadFile() = %#v, %v", knowledge, err)
|
||||||
|
}
|
||||||
|
if got, _ := uploadTenant.Load().(string); got != "10000" {
|
||||||
|
t.Fatalf("upload X-Tenant-ID = %q, want 10000", got)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// A workspace refusal on the upload is not a duplicate: it must surface as a
|
||||||
|
// plain 409 so the handler dead-letters it with a readable reason.
|
||||||
|
func TestUploadFileTenantRequiredIsNotDuplicate(t *testing.T) {
|
||||||
|
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
w.WriteHeader(http.StatusConflict)
|
||||||
|
_, _ = w.Write([]byte(`{"code":"TENANT_REQUIRED","error":"Workspace required"}`))
|
||||||
|
}))
|
||||||
|
defer server.Close()
|
||||||
|
client, err := NewClient(ClientConfig{BaseURL: server.URL, APIKey: "platform-key", Timeout: time.Second})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
_, err = client.UploadFile(context.Background(), UploadRequest{
|
||||||
|
KnowledgeBaseID: "kb-1",
|
||||||
|
FileName: "doc.pdf",
|
||||||
|
Content: strings.NewReader("%PDF-1.4"),
|
||||||
|
})
|
||||||
|
if errors.Is(err, ErrConflict) {
|
||||||
|
t.Fatalf("TENANT_REQUIRED was reported as a duplicate conflict: %v", err)
|
||||||
|
}
|
||||||
|
var httpErr *HTTPError
|
||||||
|
if !errors.As(err, &httpErr) || httpErr.StatusCode != http.StatusConflict {
|
||||||
|
t.Fatalf("UploadFile() error = %v, want HTTPError 409", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// A real duplicate still reports ErrConflict so the handler can adopt the
|
||||||
|
// existing knowledge instead of dead-lettering.
|
||||||
|
func TestUploadFileKeepsDuplicateConflict(t *testing.T) {
|
||||||
|
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
w.WriteHeader(http.StatusConflict)
|
||||||
|
_, _ = w.Write([]byte(`{"success":false,"data":{"id":"knowledge-9","knowledge_base_id":"kb-1","file_hash":"abc"}}`))
|
||||||
|
}))
|
||||||
|
defer server.Close()
|
||||||
|
client, err := NewClient(ClientConfig{BaseURL: server.URL, APIKey: "tenant-key", Timeout: time.Second})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
knowledge, err := client.UploadFile(context.Background(), UploadRequest{
|
||||||
|
KnowledgeBaseID: "kb-1",
|
||||||
|
FileName: "doc.pdf",
|
||||||
|
Content: strings.NewReader("%PDF-1.4"),
|
||||||
|
})
|
||||||
|
if !errors.Is(err, ErrConflict) || knowledge.ID != "knowledge-9" {
|
||||||
|
t.Fatalf("UploadFile() = %#v, %v want duplicate conflict", knowledge, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// An upload conflict keeps its own meaning: 409 without TENANT_REQUIRED is not
|
// An upload conflict keeps its own meaning: 409 without TENANT_REQUIRED is not
|
||||||
// treated as a workspace refusal.
|
// treated as a workspace refusal.
|
||||||
func TestTenantRequiredIgnoresPlainConflict(t *testing.T) {
|
func TestTenantRequiredIgnoresPlainConflict(t *testing.T) {
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import (
|
|||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -123,7 +124,7 @@ func (handler *UploadHandler) Handle(ctx context.Context, job jobs.Job) error {
|
|||||||
uploadMD5, _ := handler.hashSpool(candidate)
|
uploadMD5, _ := handler.hashSpool(candidate)
|
||||||
now := handler.now()
|
now := handler.now()
|
||||||
if _, err := handler.store.RecordUploadAndSchedulePoll(ctx, candidate.ID, knowledge.ID, uploadMD5, now, now.Add(handler.firstPollDelay)); err != nil {
|
if _, err := handler.store.RecordUploadAndSchedulePoll(ctx, candidate.ID, knowledge.ID, uploadMD5, now, now.Add(handler.firstPollDelay)); err != nil {
|
||||||
return ErrUploadStateConflict
|
return fmt.Errorf("%w: %v", ErrUploadStateConflict, err)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -194,7 +195,7 @@ func (handler *UploadHandler) Handle(ctx context.Context, job jobs.Job) error {
|
|||||||
}
|
}
|
||||||
now := handler.now()
|
now := handler.now()
|
||||||
if _, err := handler.store.RecordUploadAndSchedulePoll(ctx, candidate.ID, knowledge.ID, uploadMD5, now, now.Add(handler.firstPollDelay)); err != nil {
|
if _, err := handler.store.RecordUploadAndSchedulePoll(ctx, candidate.ID, knowledge.ID, uploadMD5, now, now.Add(handler.firstPollDelay)); err != nil {
|
||||||
return ErrUploadStateConflict
|
return fmt.Errorf("%w: %v", ErrUploadStateConflict, err)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -404,7 +404,12 @@ def dingtalk_live_raw_key(manifest):
|
|||||||
for index in range(len(parts)):
|
for index in range(len(parts)):
|
||||||
drive = space_id.isdigit()
|
drive = space_id.isdigit()
|
||||||
args = ['drive', '+list', '--space-id', space_id] if drive else ['wiki', '+node-list', '--workspace', space_id]
|
args = ['drive', '+list', '--space-id', space_id] if drive else ['wiki', '+node-list', '--workspace', space_id]
|
||||||
args += ['--page-all', '--limit', '50', '--max-items', '10000', '--page-limit', '200']
|
# 翻页上限开关按命令族不同:wiki 叫 --page-limit,drive +list 叫 --max-pages。
|
||||||
|
# 混用会得到 `unknown flag: --page-limit`,被分类成 unknown 而成为终态失败。
|
||||||
|
if drive:
|
||||||
|
args += ['--page-all', '--limit', '50', '--max-items', '10000', '--max-pages', '200']
|
||||||
|
else:
|
||||||
|
args += ['--page-all', '--limit', '50', '--max-items', '10000', '--page-limit', '200']
|
||||||
if folder:
|
if folder:
|
||||||
args += ['--folder', folder]
|
args += ['--folder', folder]
|
||||||
payload, verdict = dws_run(args, timeout=180)
|
payload, verdict = dws_run(args, timeout=180)
|
||||||
@@ -412,7 +417,13 @@ def dingtalk_live_raw_key(manifest):
|
|||||||
raise _dws_error(verdict)
|
raise _dws_error(verdict)
|
||||||
data = payload.get('data', {}) if isinstance(payload, dict) else {}
|
data = payload.get('data', {}) if isinstance(payload, dict) else {}
|
||||||
entries = data.get('files' if drive else 'nodes')
|
entries = data.get('files' if drive else 'nodes')
|
||||||
if not isinstance(entries, list) or data.get('hasMore') is not False or data.get('autoPageComplete') is not True:
|
# 两族命令的“翻完了”证据不同:wiki 给 data.autoPageComplete,drive +list 只在
|
||||||
|
# meta.pagination.endpoint_exhausted 里给。缺这一条会被当成目录读不全而永远可重试。
|
||||||
|
meta = payload.get('meta') if isinstance(payload, dict) else None
|
||||||
|
pagination = meta.get('pagination') if isinstance(meta, dict) else None
|
||||||
|
exhausted = (data.get('autoPageComplete') is True
|
||||||
|
or (isinstance(pagination, dict) and pagination.get('endpoint_exhausted') is True))
|
||||||
|
if not isinstance(entries, list) or data.get('hasMore') is not False or not exhausted:
|
||||||
raise FetchError('DingTalk directory response is incomplete', retryable=True, code='source_lookup_incomplete')
|
raise FetchError('DingTalk directory response is incomplete', retryable=True, code='source_lookup_incomplete')
|
||||||
matches = []
|
matches = []
|
||||||
for entry in entries:
|
for entry in entries:
|
||||||
|
|||||||
@@ -1,98 +0,0 @@
|
|||||||
// @vitest-environment jsdom
|
|
||||||
// 右侧抽屉(原生 <dialog>)必须能用三条路收回:关闭按钮、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(<FindingDetail finding={finding} onClose={onClose} />))
|
|
||||||
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()
|
|
||||||
})
|
|
||||||
})
|
|
||||||
@@ -9,7 +9,6 @@ import type {
|
|||||||
} from './reconciliationApi'
|
} from './reconciliationApi'
|
||||||
import { fetchReconciliationProgress } from './reconciliationApi'
|
import { fetchReconciliationProgress } from './reconciliationApi'
|
||||||
import { reconciliationErrorText, reconciliationFailureText, reconciliationStageText } from './reconciliationMessages'
|
import { reconciliationErrorText, reconciliationFailureText, reconciliationStageText } from './reconciliationMessages'
|
||||||
import { onBackdropClick } from './dialogBackdrop'
|
|
||||||
import './monitorWorkbench.css'
|
import './monitorWorkbench.css'
|
||||||
|
|
||||||
const time = (value: string | null | undefined) =>
|
const time = (value: string | null | undefined) =>
|
||||||
@@ -442,7 +441,7 @@ export function FindingDetail({ finding, onClose }: { finding: ReconciliationFin
|
|||||||
ref.current?.showModal()
|
ref.current?.showModal()
|
||||||
}, [])
|
}, [])
|
||||||
return (
|
return (
|
||||||
<dialog className="monitor-drawer" ref={ref} onCancel={onClose} onClick={onBackdropClick(ref, onClose)}>
|
<dialog className="monitor-drawer" ref={ref} onCancel={onClose}>
|
||||||
<header>
|
<header>
|
||||||
<h2>{typeLabels[finding.type]} · 处理详情</h2>
|
<h2>{typeLabels[finding.type]} · 处理详情</h2>
|
||||||
<button onClick={onClose} autoFocus>
|
<button onClick={onClose} autoFocus>
|
||||||
|
|||||||
@@ -29,7 +29,6 @@ import {
|
|||||||
} from './reconciliationApi'
|
} from './reconciliationApi'
|
||||||
import type { ReconciliationFinding, ReconciliationFindingPage, ReconciliationRunPage } from './reconciliationApi'
|
import type { ReconciliationFinding, ReconciliationFindingPage, ReconciliationRunPage } from './reconciliationApi'
|
||||||
import { isTestBindingMissing, reconciliationErrorText, reconciliationMessages } from './reconciliationMessages'
|
import { isTestBindingMissing, reconciliationErrorText, reconciliationMessages } from './reconciliationMessages'
|
||||||
import { onBackdropClick } from './dialogBackdrop'
|
|
||||||
import './monitorWorkbench.css'
|
import './monitorWorkbench.css'
|
||||||
|
|
||||||
const emptyRuns: ReconciliationRunPage = { items: [], total: 0, limit: 20, offset: 0 }
|
const emptyRuns: ReconciliationRunPage = { items: [], total: 0, limit: 20, offset: 0 }
|
||||||
@@ -523,7 +522,7 @@ export function TaskDetail({
|
|||||||
ref.current?.showModal()
|
ref.current?.showModal()
|
||||||
}, [])
|
}, [])
|
||||||
return (
|
return (
|
||||||
<dialog className="monitor-drawer" ref={ref} onCancel={onClose} onClick={onBackdropClick(ref, onClose)}>
|
<dialog className="monitor-drawer" ref={ref} onCancel={onClose}>
|
||||||
<header>
|
<header>
|
||||||
<h2>文件处理详情</h2>
|
<h2>文件处理详情</h2>
|
||||||
<button onClick={onClose} autoFocus>
|
<button onClick={onClose} autoFocus>
|
||||||
|
|||||||
@@ -1,20 +0,0 @@
|
|||||||
// 原生 <dialog> 的 ::backdrop 点击会派发到 dialog 元素本身,但浏览器不会自动关闭它,
|
|
||||||
// 于是右侧抽屉一打开就只能靠「关闭」按钮或 Esc 收回;内容比视口长时按钮还会被滚走。
|
|
||||||
// 这里按坐标判断:落在 dialog 矩形外的点击才关闭(dialog 自己的内边距仍算内部,
|
|
||||||
// 不能因为点在内边距上就把抽屉关掉)。
|
|
||||||
export function onBackdropClick(
|
|
||||||
ref: { current: HTMLDialogElement | null },
|
|
||||||
close: () => void
|
|
||||||
): (event: { clientX: number; clientY: number }) => void {
|
|
||||||
return (event) => {
|
|
||||||
const dialog = ref.current
|
|
||||||
if (!dialog) return
|
|
||||||
const rect = dialog.getBoundingClientRect()
|
|
||||||
const inside =
|
|
||||||
event.clientX >= rect.left &&
|
|
||||||
event.clientX <= rect.right &&
|
|
||||||
event.clientY >= rect.top &&
|
|
||||||
event.clientY <= rect.bottom
|
|
||||||
if (!inside) close()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -434,9 +434,7 @@
|
|||||||
margin: 0;
|
margin: 0;
|
||||||
border: 0;
|
border: 0;
|
||||||
border-left: 1px solid var(--border-base);
|
border-left: 1px solid var(--border-base);
|
||||||
/* 顶部的内边距交给 sticky 的 header:抽屉内容比视口长时,
|
padding: 25px;
|
||||||
「关闭」必须一直留在可见区,不能被滚走。 */
|
|
||||||
padding: 0 25px 25px;
|
|
||||||
background: var(--bg-panel);
|
background: var(--bg-panel);
|
||||||
color: var(--ink-base);
|
color: var(--ink-base);
|
||||||
overflow: auto;
|
overflow: auto;
|
||||||
@@ -450,12 +448,6 @@
|
|||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
gap: 10px;
|
gap: 10px;
|
||||||
/* 长内容滚动时「关闭」不离屏:吸顶 + 盖住底下滚过的行 */
|
|
||||||
position: sticky;
|
|
||||||
top: 0;
|
|
||||||
z-index: 1;
|
|
||||||
padding: 25px 0 12px;
|
|
||||||
background: var(--bg-panel);
|
|
||||||
}
|
}
|
||||||
.monitor-drawer h2 {
|
.monitor-drawer h2 {
|
||||||
font-size: 19px;
|
font-size: 19px;
|
||||||
|
|||||||
Reference in New Issue
Block a user