'use client'; import { useState } from 'react'; import { X, Link2, ChevronRight } from 'lucide-react'; import { BugStatusBadge } from './BugStatusBadge'; import { useBugStore } from '@/stores/useBugStore'; import { useTestCaseStore } from '@/stores/useTestCaseStore'; import { useRequirementStore } from '@/stores/useRequirementStore'; import { BUG_ALLOWED_TRANSITIONS, BUG_STATUS_LABEL, BUG_SEVERITY_LABEL, BUG_SEVERITY_COLOR } from '@/lib/bug'; import type { BugStatus } from '@/lib/bug'; interface Props { bugId: string; onClose: () => void; } export function BugDetailDrawer({ bugId, onClose }: Props) { const { bugs, changeStatus } = useBugStore(); const { testCases } = useTestCaseStore(); const { requirements } = useRequirementStore(); const bug = bugs.find((b) => b.id === bugId); if (!bug) return null; const tc = testCases.find((c) => c.id === bug.testCaseId); const requirement = tc ? requirements.find((r) => r.id === tc.requirementId) : null; const nextStatuses = BUG_ALLOWED_TRANSITIONS[bug.status]; const [resolution, setResolution] = useState(bug.resolution || ''); const [showResolutionInput, setShowResolutionInput] = useState(false); const handleTransition = (to: BugStatus) => { if (to === 'fixed') { setShowResolutionInput(true); return; } changeStatus(bug.id, to); }; const confirmFix = () => { changeStatus(bug.id, 'fixed', { resolution: resolution.trim() || undefined }); setShowResolutionInput(false); }; return (
e.stopPropagation()}>
{bug.bugNo} {bug.title}
{/* 关联链路 */}
关联链路
{tc && (
{tc.caseNo} {tc.title}
)} {requirement && (
{requirement.code} {requirement.title}
)}
{/* 状态 & 操作 */}
状态 & 操作
{BUG_SEVERITY_LABEL[bug.severity]} {bug.priority}
{nextStatuses.length > 0 && !showResolutionInput && (
{nextStatuses.map((s) => ( ))}
)} {showResolutionInput && (
setResolution(e.target.value)} placeholder="修复说明" className="h-8 w-full rounded-lg border border-[var(--line)] px-3 text-[12px] focus:border-[var(--accent)] focus:outline-none" autoFocus />
)}
{/* 基本信息 */}
基本信息
提交人:{bug.reportedBy}
修复人:{bug.assigneeId}
提交:{bug.createdAt.slice(0, 10)}
{bug.resolvedAt &&
修复:{bug.resolvedAt}
} {bug.closedAt &&
关闭:{bug.closedAt}
}
{/* 描述 */}
Bug 描述

{bug.description}

{/* 修复说明 */} {bug.resolution && (
修复说明

{bug.resolution}

)}
); }