Files
UHD_Media_Tool/apps/web/app/components/library/identity-pool-sheet.tsx
T
rootandClaude Opus 5.5 52402864d6 style(copy): punctuation rules and site-wide fix with a CI check (QA U11)
- glossary: 10 punctuation rules (full-width in Chinese, CJK/Latin spacing,
  full-width parens around Chinese, single ellipsis, 「」 quotes, period rules)
- scripts/check-copy-punctuation.mjs: checks string literals, templates and JSX
  text (not comments, types, keys, match/compare strings); --fix, --strict,
  --by-file; wired into deno task ci as check:copy in warn mode
- --fix applied to web, server and contracts; files other lanes were editing
  (subscriptions, sites, browser, agent, auth/account, inventory) left for them
- tests updated for the changed messages

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-09-28 20:09:29 +08:00

163 lines
6.5 KiB
TypeScript

import type { IdentityPoolItem, PoolCandidate } from "@umt/contracts";
import { ArrowRight, ExternalLink, LoaderCircle, RotateCw } from "lucide-react";
import { Link } from "react-router";
import { toast } from "sonner";
import { useRetryPool } from "~/api/identity.ts";
import { DetailSection, DetailSheet } from "~/components/console/detail-sheet.tsx";
import { JsonView } from "~/components/console/json-view.tsx";
import { KvList } from "~/components/console/kv-list.tsx";
import { consolePath } from "~/components/console/nav.ts";
import { Button } from "~/components/ui/button.tsx";
import { errorMessage } from "~/lib/api.ts";
import { formatDateTime } from "~/lib/utils.ts";
import { EVIDENCE_LEVEL, POOL_REASON, POOL_STATUS } from "./labels.ts";
import { Chip, Tone } from "./parts.tsx";
// 待识别资源详情(只读):候选证据 + 重新识别。选候选、忽略在待处理里做(判定只在待处理与作品详情)。
/** 多个候选 / 待确认的资源开"待确认身份"事项;没有候选的(无结果、复查耗尽)开"待识别"事项 */
export function inInbox(item: Pick<IdentityPoolItem, "status" | "reason" | "candidates" | "decisionId">): boolean {
return item.status === "pending" && (item.decisionId !== null || hasCandidates(item));
}
function hasCandidates(item: Pick<IdentityPoolItem, "reason" | "candidates">): boolean {
return (item.reason === "ambiguous" || item.reason === "proposed") && item.candidates.length > 0;
}
export const INBOX_IDENTITY = `${consolePath("inbox")}?kind=identity_ambiguous`;
export const INBOX_UNRESOLVED = `${consolePath("inbox")}?kind=identity_unresolved`;
/** 条目对应的待处理筛选链接 */
export function inboxLink(item: Pick<IdentityPoolItem, "reason" | "candidates">): string {
return hasCandidates(item) ? INBOX_IDENTITY : INBOX_UNRESOLVED;
}
/** query 摘要:标题 / 年份 / 季集 */
export function querySummary(q: Record<string, unknown>): string {
const parts: string[] = [];
if (q.title) parts.push(String(q.title));
if (q.year) parts.push(String(q.year));
if (q.season !== undefined && q.season !== null) parts.push(`S${String(q.season).padStart(2, "0")}`);
if (q.episode !== undefined && q.episode !== null) parts.push(`E${String(q.episode).padStart(2, "0")}`);
if (q.segment) parts.push(String(q.segment));
if (q.cut) parts.push(String(q.cut));
return parts.join(" · ") || "—";
}
function CandidateRow({ c, index }: { c: PoolCandidate; index: number }) {
return (
<li className="min-w-0 rounded-lg border border-border/80 p-3">
<div className="flex flex-wrap items-start justify-between gap-2">
<div className="min-w-0">
<p className="font-medium break-words text-foreground">
{index + 1}. {c.title}
{c.year ? ` (${c.year})` : ""}
</p>
<p className="font-mono text-meta break-all text-muted-foreground">
{c.provider}:{c.entityType}:{c.externalId}
</p>
</div>
</div>
<div className="mt-2 flex flex-wrap items-center gap-1.5">
<Chip>{EVIDENCE_LEVEL[c.level] ?? c.level}</Chip>
{c.localEntityId ? (
<Link
to={consolePath("library", c.localEntityId)}
className="inline-flex items-center gap-1 text-meta text-muted-foreground underline-offset-4 hover:text-foreground hover:underline"
>
本地作品
<ExternalLink className="h-3 w-3" />
</Link>
) : (
<span className="text-meta text-muted-foreground">本地未建档</span>
)}
</div>
{c.evidence.length ? (
<ul className="mt-2 list-disc space-y-0.5 pl-5 text-meta text-muted-foreground">
{c.evidence.map((e) => (
<li key={e} className="break-words">
{e}
</li>
))}
</ul>
) : null}
</li>
);
}
export function PoolSheet({ item, onClose }: { item: IdentityPoolItem | null; onClose: () => void }) {
const retry = useRetryPool();
if (!item) return null;
const queued = inInbox(item);
return (
<DetailSheet
open
width="lg"
onOpenChange={(o) => !o && onClose()}
title={item.release.title}
description={item.release.subtitle ?? undefined}
footer={
<>
<Button
variant="outline"
disabled={retry.isPending}
onClick={async () => {
try {
await retry.mutateAsync(item.id);
toast.success("已重新识别");
} catch (err) {
toast.error(errorMessage(err));
}
}}
>
{retry.isPending ? <LoaderCircle className="animate-spin" /> : <RotateCw />}
重新识别
</Button>
{queued ? (
<Button asChild>
<Link to={inboxLink(item)}>
去待处理
<ArrowRight />
</Link>
</Button>
) : null}
</>
}
>
{queued ? (
<p className="rounded-lg border border-warning/40 bg-warning/10 px-3 py-2 text-caption text-warning">
已进待处理,在那里选择候选或忽略。
</p>
) : null}
<KvList
items={[
{ label: "状态", value: <Tone v={POOL_STATUS[item.status]} /> },
{ label: "原因", value: <Tone v={POOL_REASON[item.reason]} /> },
{ label: "解析结果", value: querySummary(item.query), wide: true },
{ label: "站点分类", value: item.release.categoryRaw },
{ label: "首次发现", value: formatDateTime(item.release.firstSeenAt) },
{ label: "尝试次数", value: String(item.attempts) },
{ label: "上次尝试", value: formatDateTime(item.lastAttemptAt) },
{ label: "下次复查", value: item.nextReviewAt ? formatDateTime(item.nextReviewAt) : "不再自动复查" },
{ label: "证据版本", value: item.evidenceVersion, mono: true },
]}
/>
<DetailSection title={`候选(${item.candidates.length})`}>
{item.candidates.length ? (
<ul className="space-y-2">
{item.candidates.map((c, i) => (
<CandidateRow key={`${c.provider}:${c.entityType}:${c.externalId}`} c={c} index={i} />
))}
</ul>
) : (
<p className="text-caption text-muted-foreground">没有候选。有新证据时自动重试。</p>
)}
</DetailSection>
<JsonView label="解析条件(原始)" value={item.query} defaultOpen={false} />
</DetailSheet>
);
}