refactor(duplication-detail): 三阶段重构 DuplicationDetail(323→110行, -66%) #968

Closed
xiaoxia wants to merge 1 commits from refactor/duplication-detail into develop
Owner

变更说明

DuplicationDetail 查重详情页三阶段重构,主文件 323→110 行(-66%)

Phase 1: 常量/工具

  • constants.ts: RISK_DESC / RISK_TAG_VARIANT / RISK_LABEL / ToastState
  • utils.ts: formatTime / formatSize / formatDuration / getRiskLevel

Phase 2: UI 组件

  • components/RiskCard.tsx: 风险评估卡片(圆环 + 查重率 + 描述)
  • components/InfoCard.tsx: 基本信息卡片(6 行元数据)
  • components/SegmentsSection.tsx: 重复片段列表区域
  • components/SegmentCard.tsx: 单个重复片段卡片

Phase 3: 业务 Hook

  • hooks/useDuplicationDetail.ts: 查询 + 重试 + Toast + 导航

说明

  • 页面功能完全不变,纯结构重构
  • SegmentCard 与 SegmentsSection 可复用于其他查重相关页面
## 变更说明 DuplicationDetail 查重详情页三阶段重构,主文件 323→110 行(-66%) ### Phase 1: 常量/工具 - `constants.ts`: RISK_DESC / RISK_TAG_VARIANT / RISK_LABEL / ToastState - `utils.ts`: formatTime / formatSize / formatDuration / getRiskLevel ### Phase 2: UI 组件 - `components/RiskCard.tsx`: 风险评估卡片(圆环 + 查重率 + 描述) - `components/InfoCard.tsx`: 基本信息卡片(6 行元数据) - `components/SegmentsSection.tsx`: 重复片段列表区域 - `components/SegmentCard.tsx`: 单个重复片段卡片 ### Phase 3: 业务 Hook - `hooks/useDuplicationDetail.ts`: 查询 + 重试 + Toast + 导航 ### 说明 - 页面功能完全不变,纯结构重构 - SegmentCard 与 SegmentsSection 可复用于其他查重相关页面
auto-approve-bot approved these changes 2026-07-27 13:46:31 +08:00
auto-approve-bot left a comment
Collaborator

CI全绿,自动审批通过。

CI全绿,自动审批通过。
auto-approve-bot approved these changes 2026-07-27 13:46:31 +08:00
auto-approve-bot left a comment
Collaborator

CI全绿,自动审批通过。

CI全绿,自动审批通过。

🚀 预览环境已部署

项目 详情
PR号 #968
预览链接 https://pr-968.preview.xiaoxiajianji.com
API环境 staging

💡 预览环境使用 staging API 数据,请勿在预览环境中操作重要数据。

🔄 每次提交新代码后预览环境会自动更新。

🗑️ PR 关闭或合并后,预览环境会自动清理。

🚀 **预览环境已部署** | 项目 | 详情 | |------|------| | PR号 | #968 | | 预览链接 | [https://pr-968.preview.xiaoxiajianji.com](https://pr-968.preview.xiaoxiajianji.com) | | API环境 | staging | > 💡 预览环境使用 staging API 数据,请勿在预览环境中操作重要数据。 > > 🔄 每次提交新代码后预览环境会自动更新。 > > 🗑️ PR 关闭或合并后,预览环境会自动清理。
Collaborator

Auto merge skipped after multiple 405 errors: PR may have conflicts or unresolved checks. Please review manually. This is not a CI failure.

Auto merge skipped after multiple 405 errors: PR may have conflicts or unresolved checks. Please review manually. This is not a CI failure.
xiaoxia added 1 commit 2026-07-27 16:08:18 +08:00
refactor(duplication-detail): 三阶段重构 DuplicationDetail(323→110行, -66%)
CI/CD Pipeline / CI Gate (pull_request) CI运行中 [frontend-only]
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 9s
CI/CD Pipeline / Frontend Lint (pull_request) Successful in 35s
CI/CD Pipeline / Validate - Type Check (mypy) (pull_request) Successful in 1m17s
CI/CD Pipeline / Validate - Migration (alembic) (pull_request) Successful in 1m21s
CI/CD Pipeline / Build Staging API Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Web Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Worker Image (pull_request) Has been skipped
CI/CD Pipeline / PR Build Worker Image (pull_request) Successful in 49s
PR Automation / Auto Approve on CI Green (pull_request) Successful in 1m2s
CI/CD Pipeline / PR Build Web Image (pull_request) Successful in 1m49s
Preview Deploy / Deploy Preview Environment (pull_request) Successful in 45s
AI Code Review / AI Code Review (pull_request) Successful in 1m23s
CI/CD Pipeline / Validate - Code Quality (pull_request) Successful in 4m4s
CI/CD Pipeline / PR Build API Image (pull_request) Successful in 4m51s
PR Automation / Auto Merge on CI Green + Approved (pull_request) Successful in 15m46s
CI/CD Pipeline / Unit Tests (pull_request) Has been skipped
CI/CD Pipeline / Build Production API Image (pull_request) Has been skipped
CI/CD Pipeline / Build Production Web Image (pull_request) Has been skipped
CI/CD Pipeline / Build Production Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Frontend Unit Tests (pull_request) Failing after 22s
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Has been skipped
ACR Cleanup / ACR Image Cleanup (pull_request_target) Has been cancelled
CI/CD Pipeline / Integration Tests (pull_request) Has been skipped
Preview Cleanup / Cleanup Preview Environment (pull_request) Successful in 7s
CI/CD Pipeline / Deploy Production (pull_request) Has been skipped
CI/CD Pipeline / Staging E2E Tests (pull_request) Has been skipped
CI/CD Pipeline / Staging API Integration Tests (pull_request) Has been skipped
CI/CD Pipeline / ACR Image Cleanup (pull_request) Has been skipped
CI/CD Pipeline / Canary Release to Production (pull_request) Has been cancelled
CI/CD Pipeline / Production Browser E2E (pull_request) Has been skipped
078569cf6c
- Phase 1: 抽 constants(RISK_DESC/RISK_LABEL/ToastState)+ utils(formatTime/formatSize/formatDuration/getRiskLevel)
- Phase 2: 抽 4 个 UI 组件(RiskCard/InfoCard/SegmentsSection/SegmentCard)
- Phase 3: 抽 useDuplicationDetail 业务 Hook
- 主文件 323→110 行,职责清晰
xiaoxia force-pushed refactor/duplication-detail from c05d6d02af to 078569cf6c 2026-07-27 16:08:18 +08:00 Compare
Collaborator

代码审查结果 - PR #968

⚠️ 问题(3个需要修改)

  1. apps/web/src/pages/duplication/hooks/useDuplicationDetail.ts 第20行:内存泄漏风险。setTimeout 在组件卸载后仍会触发 setToast,导致 React 警告且可能引起内存泄漏。应使用 useEffect 清理定时器或使用 useRef 追踪组件挂载状态。
  2. apps/web/src/pages/duplication/components/SegmentCard.tsx 第19行:空指针异常风险。直接使用 segment.similarity 进行数值运算和 toFixed(1),如果 API 返回的数据中 similaritynullundefined,将导致页面崩溃。需增加非空校验或默认值。
  3. apps/web/src/pages/duplication/components/InfoCard.tsx 第60行:类型断言错误。status.variant 可能是 "info"(如 pending 状态),但代码强制断言为 "success"。这会导致 UI 组件接收到错误的 variant 类型,可能渲染出错误的样式(如 pending 状态显示为 success 颜色)。

💡 建议(2个可选)

  1. apps/web/src/pages/duplication/utils.ts 第14行:建议增加对负数或非数字的校验。formatTime 函数目前假设输入为正整数,如果传入负数或 NaN,结果可能不符合预期(如 "-01:-20")。
  2. apps/web/src/pages/duplication/components/InfoCard.tsx 第66行:日期解析鲁棒性。new Date(detail.created_at) 如果遇到无效的日期字符串,会返回 "Invalid Date"。建议增加日期有效性检查或使用专门的日期库处理。

格式检查通过 | 逻辑审查需修改 | 性能无明显问题


🤖 由 AI 代码审查机器人自动生成 | 2026-07-27 10:08:58 | 模型:

## 代码审查结果 - PR #968 ### ⚠️ 问题(3个需要修改) 1. **apps/web/src/pages/duplication/hooks/useDuplicationDetail.ts 第20行**:内存泄漏风险。`setTimeout` 在组件卸载后仍会触发 `setToast`,导致 React 警告且可能引起内存泄漏。应使用 `useEffect` 清理定时器或使用 `useRef` 追踪组件挂载状态。 2. **apps/web/src/pages/duplication/components/SegmentCard.tsx 第19行**:空指针异常风险。直接使用 `segment.similarity` 进行数值运算和 `toFixed(1)`,如果 API 返回的数据中 `similarity` 为 `null` 或 `undefined`,将导致页面崩溃。需增加非空校验或默认值。 3. **apps/web/src/pages/duplication/components/InfoCard.tsx 第60行**:类型断言错误。`status.variant` 可能是 "info"(如 pending 状态),但代码强制断言为 `"success"`。这会导致 UI 组件接收到错误的 variant 类型,可能渲染出错误的样式(如 pending 状态显示为 success 颜色)。 ### 💡 建议(2个可选) 1. **apps/web/src/pages/duplication/utils.ts 第14行**:建议增加对负数或非数字的校验。`formatTime` 函数目前假设输入为正整数,如果传入负数或 NaN,结果可能不符合预期(如 "-01:-20")。 2. **apps/web/src/pages/duplication/components/InfoCard.tsx 第66行**:日期解析鲁棒性。`new Date(detail.created_at)` 如果遇到无效的日期字符串,会返回 "Invalid Date"。建议增加日期有效性检查或使用专门的日期库处理。 --- ✅ 格式检查通过 | ❌ 逻辑审查需修改 | ✅ 性能无明显问题 --- <sub>🤖 由 AI 代码审查机器人自动生成 | 2026-07-27 10:08:58 | 模型: </sub> <!-- AI_CODE_REVIEW_AUTO_COMMENT -->
xiaoxia closed this pull request 2026-07-27 18:22:05 +08:00

🗑️ 预览环境已清理

PR #968 已关闭或合并,对应的预览环境已被清理。

如有需要,可以重新打开 PR 来重新生成预览环境。

🗑️ **预览环境已清理** PR #968 已关闭或合并,对应的预览环境已被清理。 > 如有需要,可以重新打开 PR 来重新生成预览环境。
Some checks are pending
CI/CD Pipeline / CI Gate (pull_request) CI运行中 [frontend-only]
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 9s
CI/CD Pipeline / Frontend Lint (pull_request) Successful in 35s
CI/CD Pipeline / Validate - Type Check (mypy) (pull_request) Successful in 1m17s
CI/CD Pipeline / Validate - Migration (alembic) (pull_request) Successful in 1m21s
CI/CD Pipeline / Build Staging API Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Web Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Worker Image (pull_request) Has been skipped
CI/CD Pipeline / PR Build Worker Image (pull_request) Successful in 49s
PR Automation / Auto Approve on CI Green (pull_request) Successful in 1m2s
CI/CD Pipeline / PR Build Web Image (pull_request) Successful in 1m49s
Preview Deploy / Deploy Preview Environment (pull_request) Successful in 45s
AI Code Review / AI Code Review (pull_request) Successful in 1m23s
CI/CD Pipeline / Validate - Code Quality (pull_request) Successful in 4m4s
CI/CD Pipeline / PR Build API Image (pull_request) Successful in 4m51s
PR Automation / Auto Merge on CI Green + Approved (pull_request) Successful in 15m46s
CI/CD Pipeline / Unit Tests (pull_request) Has been skipped
CI/CD Pipeline / Build Production API Image (pull_request) Has been skipped
CI/CD Pipeline / Build Production Web Image (pull_request) Has been skipped
CI/CD Pipeline / Build Production Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Frontend Unit Tests (pull_request) Failing after 22s
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Has been skipped
ACR Cleanup / ACR Image Cleanup (pull_request_target) Has been cancelled
CI/CD Pipeline / Integration Tests (pull_request) Has been skipped
Preview Cleanup / Cleanup Preview Environment (pull_request) Successful in 7s
CI/CD Pipeline / Deploy Production (pull_request) Has been skipped
CI/CD Pipeline / Staging E2E Tests (pull_request) Has been skipped
CI/CD Pipeline / Staging API Integration Tests (pull_request) Has been skipped
CI/CD Pipeline / ACR Image Cleanup (pull_request) Has been skipped
CI/CD Pipeline / Canary Release to Production (pull_request) Has been cancelled
CI/CD Pipeline / Production Browser E2E (pull_request) Has been skipped

Pull request closed

Sign in to join this conversation.