09b2c1dce5
build / build (push) Successful in 1m17s
修正筛选入口位置:五项条件在表头就地选择,保持完整集筛选与无感续载。 统一固定规则:未覆盖一律待确认,原问答/人工模型证据不改写,已覆盖仍保留点踩优先。 验证:行为红绿、前端/Go全套及隔离PostgreSQL全mirror竞态通过;完整本地门禁与原生备份真实恢复通过。
173 lines
6.1 KiB
TypeScript
173 lines
6.1 KiB
TypeScript
import { useEffect, useRef, useState } from 'react'
|
||
import './qaPeriodInput.css'
|
||
import type { QARecord } from './qaOps'
|
||
import { qaColumns } from './qaOps'
|
||
import {
|
||
editableFieldKeys,
|
||
editableFieldValue,
|
||
fieldChoices,
|
||
fetchFieldOptions,
|
||
saveInlineField,
|
||
} from './qaInlineFields'
|
||
import type { EditableField, FieldOptions } from './qaInlineFields'
|
||
import { newOperationID } from './operationKey'
|
||
import { qaFieldColors } from './qaFieldColors'
|
||
export function QAInlineFields({
|
||
record,
|
||
onSaved,
|
||
onReload,
|
||
}: {
|
||
record: QARecord
|
||
onSaved: (record: QARecord) => void
|
||
onReload: () => void
|
||
}) {
|
||
const [options, setOptions] = useState<FieldOptions | null>(null),
|
||
[error, setError] = useState(''),
|
||
[notice, setNotice] = useState(''),
|
||
[saving, setSaving] = useState(false),
|
||
[reloadOptions, setReloadOptions] = useState(0)
|
||
const [pending, setPending] = useState<{
|
||
record: QARecord
|
||
field: EditableField
|
||
value: string
|
||
nonce: string
|
||
} | null>(null)
|
||
const writing = useRef<AbortController | null>(null)
|
||
useEffect(() => {
|
||
const c = new AbortController()
|
||
setError('')
|
||
void fetchFieldOptions(c.signal)
|
||
.then(setOptions)
|
||
.catch((e) => {
|
||
if (!c.signal.aborted) setError(e instanceof Error ? e.message : '主表选项读取失败')
|
||
})
|
||
return () => c.abort()
|
||
}, [reloadOptions])
|
||
useEffect(() => () => writing.current?.abort(), [])
|
||
const save = async (p: NonNullable<typeof pending>) => {
|
||
if (writing.current) return
|
||
const c = new AbortController()
|
||
writing.current = c
|
||
setSaving(true)
|
||
setError('')
|
||
setNotice('')
|
||
try {
|
||
const fresh = await saveInlineField(p.record, p.field, p.value, p.nonce, c.signal)
|
||
if (!c.signal.aborted) {
|
||
setPending(null)
|
||
onSaved(fresh)
|
||
setNotice('已保存')
|
||
}
|
||
} catch (e) {
|
||
if (!c.signal.aborted) setError(e instanceof Error ? e.message : '字段保存失败,选择尚未确认')
|
||
} finally {
|
||
writing.current = null
|
||
if (!c.signal.aborted) setSaving(false)
|
||
}
|
||
}
|
||
return (
|
||
<div className="qa-inline-fields">
|
||
<div className="qa-detail-quality" aria-label="固定质量字段">
|
||
{editableFieldKeys.map((field) => {
|
||
const value = pending?.field === field ? pending.value : editableFieldValue(record, field)
|
||
const choices = fieldChoices(field, options?.[field] ?? [], editableFieldValue(record, 'coverage'))
|
||
const rootNotNeeded = field === 'root_cause' && editableFieldValue(record, 'is_correct') === '是'
|
||
const uncoveredLocked = field === 'is_correct' && editableFieldValue(record, 'coverage') === '否'
|
||
const downvoteLocked = field === 'is_correct' && record.quality?.feedback_rule === 'downvote-is-incorrect-v1'
|
||
return (
|
||
<div key={field} data-quality-field={field}>
|
||
<label>
|
||
<span>{qaColumns.find((c) => c.key === field)!.label}</span>
|
||
<select
|
||
aria-label={`修改${qaColumns.find((c) => c.key === field)!.label}`}
|
||
title={
|
||
uncoveredLocked
|
||
? '未覆盖,是否正确固定为待确认'
|
||
: downvoteLocked
|
||
? '已点踩,是否正确固定为否'
|
||
: '选择后自动保存'
|
||
}
|
||
value={rootNotNeeded ? '' : value}
|
||
disabled={
|
||
saving ||
|
||
!!pending ||
|
||
!options ||
|
||
!record.record_origin ||
|
||
!record.quality ||
|
||
rootNotNeeded ||
|
||
downvoteLocked ||
|
||
uncoveredLocked
|
||
}
|
||
style={qaFieldColors(field, value || '—')}
|
||
onChange={(e) => {
|
||
if (e.target.value === editableFieldValue(record, field)) return
|
||
try {
|
||
const next = { record, field, value: e.target.value, nonce: newOperationID() }
|
||
setPending(next)
|
||
void save(next)
|
||
} catch (e) {
|
||
setError(e instanceof Error ? e.message : '无法生成保存标识')
|
||
}
|
||
}}
|
||
>
|
||
<option value="" disabled>
|
||
{rootNotNeeded ? '无需根因' : '未设置'}
|
||
</option>
|
||
{value && !choices.includes(value) ? (
|
||
<option value={value} disabled>
|
||
{value}
|
||
</option>
|
||
) : null}
|
||
{choices.map((v) => (
|
||
<option key={v} value={v}>
|
||
{v}
|
||
</option>
|
||
))}
|
||
</select>
|
||
</label>
|
||
</div>
|
||
)
|
||
})}
|
||
</div>
|
||
{editableFieldValue(record, 'coverage') === '否' ? (
|
||
<p className="qa-inline-save">未覆盖,是否正确固定为待确认</p>
|
||
) : null}
|
||
{record.quality?.feedback_rule === 'downvote-is-incorrect-v1' ? (
|
||
<p className="qa-inline-save">已点踩,是否正确固定为否</p>
|
||
) : null}
|
||
{saving || notice ? (
|
||
<p className="qa-inline-save" role="status" aria-live="polite">
|
||
{saving ? '保存中…' : notice}
|
||
</p>
|
||
) : null}
|
||
{error ? (
|
||
<p role="alert" className="error-banner">
|
||
{error}{' '}
|
||
{pending ? (
|
||
<>
|
||
<button type="button" disabled={saving} onClick={() => void save(pending)}>
|
||
重试保存
|
||
</button>
|
||
<button
|
||
type="button"
|
||
disabled={saving}
|
||
onClick={() => {
|
||
setPending(null)
|
||
setError('')
|
||
onReload()
|
||
}}
|
||
>
|
||
放弃并重读
|
||
</button>
|
||
</>
|
||
) : (
|
||
<button type="button" onClick={() => setReloadOptions((v) => v + 1)}>
|
||
重试读取选项
|
||
</button>
|
||
)}
|
||
</p>
|
||
) : null}
|
||
</div>
|
||
)
|
||
}
|