✨ Align discard selection with the slice dictionary

This commit is contained in:
d-robotics 2026-09-21 19:34:07 +08:00
parent f647ec1670
commit b62d1f1e3a
4 changed files with 90 additions and 28 deletions

View File

@ -2904,22 +2904,35 @@ export function CaptureAnnotationWorkbench({
placeholder="请从项目切片字典选择"
className="flex-1 rounded-md border border-slate-300 bg-[color:var(--app-panel)] px-3 py-1.5 text-xs font-semibold text-slate-900 shadow-sm transition placeholder:text-slate-400 focus:border-orange-500 focus:outline-none focus:ring-1 focus:ring-orange-500 dark:border-[#34363b] dark:bg-[#1a1b1e] dark:text-white"
/>
{!readOnly && !isQualityReview && (
<SliceNameDictionaryPicker
inline={focusedLayout}
portal={adaptiveLayout && phase === "slice" && !focusedLayout}
triggerRef={sliceDictionaryTriggerRef}
key={`${taskId}:${selectedSlice.id}`}
items={sliceDictionary}
value={selectedSlice.name || ""}
disabled={saving}
loading={sliceDictionaryLoading}
error={sliceDictionaryError}
onRefresh={onRefreshSliceDictionary}
onSelect={(name) => onSliceNameChange?.(selectedSlice.id, name)}
onCloseFocus={focusWorkbench}
/>
)}
<div className="capture-slice-dictionary-actions flex flex-wrap items-center gap-2">
{!readOnly && !isQualityReview && (
<SliceNameDictionaryPicker
inline={focusedLayout}
portal={adaptiveLayout && phase === "slice" && !focusedLayout}
triggerRef={sliceDictionaryTriggerRef}
key={`${taskId}:${selectedSlice.id}`}
items={sliceDictionary}
value={selectedSlice.name || ""}
disabled={saving}
loading={sliceDictionaryLoading}
error={sliceDictionaryError}
onRefresh={onRefreshSliceDictionary}
onSelect={(name) => onSliceNameChange?.(selectedSlice.id, name)}
onCloseFocus={focusWorkbench}
/>
)}
{!readOnly && !isQualityReview && onSliceDispositionChange && !selectedDiscarded && (
<button
type="button"
disabled={saving}
aria-keyshortcuts="G"
onClick={() => openDisposition(false)}
className="inline-flex items-center gap-1.5 rounded-md border border-orange-400 bg-[color:var(--app-panel)] px-3 py-1.5 text-xs font-semibold text-orange-700 disabled:opacity-40 dark:text-orange-300"
>
舍弃片段
</button>
)}
</div>
</div>
</div>
) : null}
@ -2934,14 +2947,14 @@ export function CaptureAnnotationWorkbench({
)}
</div>
{!mediaOnly && (phase === "slice" || selectedDiscarded) && (
{!mediaOnly && (selectedDiscarded || dispositionOpen) && (
<div
className="mx-5 my-2 rounded-lg border border-slate-200 p-3 text-sm"
data-testid="slice-disposition-panel"
>
<div className="flex flex-wrap items-center justify-between gap-2">
<span className="font-semibold">{selectedDiscarded ? "已舍弃 · 保留审核证据" : ""}</span>
{!readOnly && !isQualityReview && onSliceDispositionChange && (
{!readOnly && !isQualityReview && onSliceDispositionChange && selectedDiscarded && (
<button
type="button"
disabled={saving}
@ -3005,14 +3018,19 @@ export function CaptureAnnotationWorkbench({
}
}}
>
<h3 className="text-lg font-semibold">{dispositionDraft.discard ? "舍弃片段" : "恢复为保留"}</h3>
<p className="my-3 text-sm">
{dispositionDraft.discard
? "将保存当前切片划分;本片无需标注,不进入交付,原视频与历史描述保留供审核。"
: "恢复后请核对原有描述,再按现有流程提交审核。"}
</p>
<div className="workspace-dictionary-heading">
<strong>{dispositionDraft.discard ? "选择舍弃原因" : "恢复为保留"}</strong>
<button type="button" disabled={saving} onClick={closeDisposition}>
返回编辑
</button>
</div>
{!dispositionDraft.discard && (
<p className="my-3 text-sm">恢复后请核对原有描述,再按现有流程提交审核。</p>
)}
{dispositionDraft.discard && (
<DiscardReasonFields
workspace
onClose={closeDisposition}
items={discardReasons}
allowManual={discardReasonsAllowManual}
loading={discardReasonsLoading}

View File

@ -1,3 +1,4 @@
import { WorkspaceDictionaryPanel } from "./WorkspaceDictionaryPanel";
import { useEffect, useRef, useState } from "react";
import type { AnnotationLabelRecord } from "../types";
export type DiscardReasonChoice = {
@ -7,6 +8,8 @@ export type DiscardReasonChoice = {
reasonNote?: string;
};
export function DiscardReasonFields({
workspace = false,
onClose = () => {},
items,
loading,
allowManual = false,
@ -15,6 +18,8 @@ export function DiscardReasonFields({
value,
onChange,
}: {
workspace?: boolean;
onClose?: () => void;
items: AnnotationLabelRecord[];
loading: boolean;
allowManual?: boolean;
@ -50,7 +55,7 @@ export function DiscardReasonFields({
aria-busy={loading}
className="discard-reason-fields space-y-3"
onKeyDown={(event) => {
if (loading || error) return;
if (workspace || loading || error) return;
if (event.nativeEvent.isComposing || event.ctrlKey || event.metaKey || event.altKey || event.shiftKey) return;
const target = event.target as HTMLElement;
if (target.matches("textarea")) return;
@ -81,7 +86,23 @@ export function DiscardReasonFields({
}
}}
>
{!manual && (
{!manual && workspace && (
<WorkspaceDictionaryPanel
embedded
title="选择舍弃原因"
searchLabel="搜索舍弃字典"
items={items.map((item) => ({ id: item.id, text: item.name }))}
value={selected?.name}
status={loading ? <p role="status">正在加载舍弃原因…</p> : error ? <p role="alert">{error}</p> : undefined}
onSelect={(id) => {
const item = items.find((item) => item.id === id);
if (item && !loading && !error) onChange({ ...value, reasonLabelId: item.id, reasonVersion: item.version });
}}
onClose={onClose}
onDismiss={() => {}}
/>
)}
{!manual && !workspace && (
<>
<label className="block text-sm">
舍弃原因(必选)

View File

@ -12,7 +12,9 @@ export function WorkspaceDictionaryPanel({
onSelect,
onClose,
onDismiss,
embedded = false,
}: {
embedded?: boolean;
title: string;
searchLabel: string;
items: { id: string; text: string; searchText?: string }[];
@ -70,8 +72,10 @@ export function WorkspaceDictionaryPanel({
<div
role="dialog"
aria-label={title}
className="workspace-dictionary-panel"
className={`workspace-dictionary-panel${embedded ? " workspace-dictionary-embedded" : ""}`}
onKeyDown={(event) => {
// Embedded discard selection leaves save shortcuts to its owning form.
if (embedded && (event.ctrlKey || event.metaKey || event.altKey || event.shiftKey)) return;
dictionaryKeyDown(event, onClose);
if (
event.nativeEvent.isComposing ||
@ -93,7 +97,7 @@ export function WorkspaceDictionaryPanel({
if (!event.currentTarget.contains(event.relatedTarget as Node)) onDismiss();
}}
>
<div className="workspace-dictionary-heading">
<div className="workspace-dictionary-heading" hidden={embedded}>
<strong>{title}</strong>
<button type="button" onClick={onClose}>
返回编辑

View File

@ -1596,3 +1596,22 @@
.capture-annotation-heading > div > span {
line-height: 1.5;
}
/* Discard selection shares the slice dictionary's search, paging and result rows. */
.capture-disposition-panel .discard-reason-fields > .workspace-dictionary-embedded {
position: relative;
inset: auto;
flex: 1 1 0;
min-height: 120px;
padding: 0;
border: 0;
}
.workspace-dictionary-heading[hidden] {
display: none;
}
.capture-disposition-panel .workspace-dictionary-heading button {
border: 1px solid var(--app-border);
border-radius: 4px;
padding: 4px 8px;
background: var(--app-panel);
}