refactor: 拆分 DuplicationResults 页面(275→67行,-76%) #1022

Closed
xiaoxia wants to merge 4 commits from refactor/duplication-results-split into develop
Owner

变更说明

按三阶段标准模式拆分 DuplicationResults 页面,主文件从 275 行精简到 67 行(-76%)。

拆分内容

Phase 1: 类型/常量/工具

  • types.ts - RiskFilter、ToastState 类型
  • constants.ts - STATUS_CONFIG、RISK_LABELS、FILTER_OPTIONS
  • utils.ts - getRiskLevel、formatSize、formatDuration

Phase 2: UI 组件

  • components/FilterBar.tsx - 风险等级筛选胶囊
  • components/EmptyState.tsx - 加载/空状态展示
  • components/ResultCard.tsx - 查重结果卡片

Phase 3: 业务 Hook

  • hooks/useDuplicationResults.ts - 数据获取、删除/重试 mutation、筛选逻辑、toast、导航

兼容性

  • 主文件路径 @/pages/duplication/DuplicationResults 保持不变
  • 路由导入无需修改
## 变更说明 按三阶段标准模式拆分 DuplicationResults 页面,主文件从 275 行精简到 67 行(-76%)。 ## 拆分内容 ### Phase 1: 类型/常量/工具 - `types.ts` - RiskFilter、ToastState 类型 - `constants.ts` - STATUS_CONFIG、RISK_LABELS、FILTER_OPTIONS - `utils.ts` - getRiskLevel、formatSize、formatDuration ### Phase 2: UI 组件 - `components/FilterBar.tsx` - 风险等级筛选胶囊 - `components/EmptyState.tsx` - 加载/空状态展示 - `components/ResultCard.tsx` - 查重结果卡片 ### Phase 3: 业务 Hook - `hooks/useDuplicationResults.ts` - 数据获取、删除/重试 mutation、筛选逻辑、toast、导航 ## 兼容性 - 主文件路径 `@/pages/duplication/DuplicationResults` 保持不变 - 路由导入无需修改
xiaoxia added 1 commit 2026-07-27 09:40:07 +08:00
refactor: 拆分 DuplicationResults 页面(275→67行,-76%)
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 1m12s
CI/CD Pipeline / Validate - Type Check (mypy) (pull_request) Successful in 2m16s
CI/CD Pipeline / Frontend Lint (pull_request) Failing after 1m3s
CI/CD Pipeline / Validate - Migration (alembic) (pull_request) Successful in 1m29s
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 / Validate - Code Quality (pull_request) Failing after 2m44s
CI/CD Pipeline / Build Staging Worker Image (pull_request) Has been skipped
CI/CD Pipeline / PR Build Worker Image (pull_request) Successful in 44s
PR Automation / Auto Approve on CI Green (pull_request) Successful in 1m24s
PR Automation / Auto Merge on CI Green + Approved (pull_request) Successful in 1m18s
AI Code Review / AI Code Review (pull_request) Successful in 1m46s
Preview Deploy / Deploy Preview Environment (pull_request) Failing after 43s
CI/CD Pipeline / PR Build Web Image (pull_request) Failing after 2m47s
CI/CD Pipeline / PR Build API Image (pull_request) Successful in 7m23s
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 / Integration Tests (pull_request) Has been skipped
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Has been skipped
CI/CD Pipeline / Frontend Unit Tests (pull_request) Failing after 24s
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
abc5877bf6
- 抽 types/constants/utils 为独立文件
- 抽 3 个 UI 组件:FilterBar / EmptyState / ResultCard
- 抽业务 Hook:useDuplicationResults
- 主文件精简为纯组合层,保持导入路径向后兼容
xiaoxia added 1 commit 2026-07-27 12:33:37 +08:00
Merge branch 'develop' into refactor/duplication-results-split
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 20s
CI/CD Pipeline / Validate - Migration (alembic) (pull_request) Successful in 1m43s
CI/CD Pipeline / Validate - Type Check (mypy) (pull_request) Successful in 2m2s
CI/CD Pipeline / Build Staging API Image (pull_request) Has been skipped
CI/CD Pipeline / Frontend Lint (pull_request) Failing after 1m55s
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 43s
CI/CD Pipeline / Validate - Code Quality (pull_request) Failing after 2m34s
CI/CD Pipeline / PR Build Web Image (pull_request) Failing after 2m48s
PR Automation / Auto Approve on CI Green (pull_request) Successful in 1m3s
Preview Deploy / Deploy Preview Environment (pull_request) Failing after 37s
PR Automation / Auto Merge on CI Green + Approved (pull_request) Successful in 58s
AI Code Review / AI Code Review (pull_request) Successful in 2m0s
CI/CD Pipeline / PR Build API Image (pull_request) Successful in 6m14s
CI/CD Pipeline / Unit Tests (pull_request) Has been cancelled
CI/CD Pipeline / Integration Tests (pull_request) Has been cancelled
CI/CD Pipeline / Frontend Unit Tests (pull_request) Has been cancelled
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Has been cancelled
CI/CD Pipeline / Staging E2E Tests (pull_request) Has been cancelled
CI/CD Pipeline / Staging API Integration Tests (pull_request) Has been cancelled
CI/CD Pipeline / Build Production API Image (pull_request) Has been cancelled
CI/CD Pipeline / Build Production Web Image (pull_request) Has been cancelled
CI/CD Pipeline / Build Production Worker Image (pull_request) Has been cancelled
CI/CD Pipeline / Deploy Production (pull_request) Has been cancelled
CI/CD Pipeline / Production Browser E2E (pull_request) Has been cancelled
CI/CD Pipeline / ACR Image Cleanup (pull_request) Has been cancelled
CI/CD Pipeline / Canary Release to Production (pull_request) Has been cancelled
12770b397f
xiaoxia added 1 commit 2026-07-27 12:42:59 +08:00
fix: 统一 id 参数类型为 string,修复 TS2345 类型不兼容
CI/CD Pipeline / Check if frontend-only change (pull_request) Has been cancelled
CI/CD Pipeline / Validate - Code Quality (pull_request) Has been cancelled
CI/CD Pipeline / Validate - Type Check (mypy) (pull_request) Has been cancelled
CI/CD Pipeline / Validate - Migration (alembic) (pull_request) Has been cancelled
CI/CD Pipeline / Unit Tests (pull_request) Has been cancelled
CI/CD Pipeline / Integration Tests (pull_request) Has been cancelled
CI/CD Pipeline / Frontend Lint (pull_request) Has been cancelled
CI/CD Pipeline / Frontend Unit Tests (pull_request) Has been cancelled
CI/CD Pipeline / PR Build API Image (pull_request) Has been cancelled
CI/CD Pipeline / PR Build Web Image (pull_request) Has been cancelled
CI/CD Pipeline / PR Build Worker Image (pull_request) Has been cancelled
CI/CD Pipeline / Build Staging API Image (pull_request) Has been cancelled
CI/CD Pipeline / Build Staging Web Image (pull_request) Has been cancelled
CI/CD Pipeline / Build Staging Worker Image (pull_request) Has been cancelled
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Has been cancelled
CI/CD Pipeline / Staging E2E Tests (pull_request) Has been cancelled
CI/CD Pipeline / Staging API Integration Tests (pull_request) Has been cancelled
CI/CD Pipeline / Build Production API Image (pull_request) Has been cancelled
CI/CD Pipeline / Build Production Web Image (pull_request) Has been cancelled
CI/CD Pipeline / Build Production Worker Image (pull_request) Has been cancelled
CI/CD Pipeline / Deploy Production (pull_request) Has been cancelled
CI/CD Pipeline / Production Browser E2E (pull_request) Has been cancelled
CI/CD Pipeline / ACR Image Cleanup (pull_request) Has been cancelled
CI/CD Pipeline / Canary Release to Production (pull_request) Has been cancelled
AI Code Review / AI Code Review (pull_request) Has been cancelled
Preview Deploy / Deploy Preview Environment (pull_request) Has been cancelled
PR Automation / Auto Approve on CI Green (pull_request) Successful in 37s
PR Automation / Auto Merge on CI Green + Approved (pull_request) Successful in 39s
aa9a44b7b8
xiaoxia added 1 commit 2026-07-27 12:42:59 +08:00
fix: 统一 ResultCard id 参数类型为 string
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 7s
CI/CD Pipeline / Validate - Type Check (mypy) (pull_request) Successful in 1m14s
CI/CD Pipeline / Validate - Code Quality (pull_request) Failing after 1m57s
CI/CD Pipeline / Frontend Lint (pull_request) Successful in 47s
CI/CD Pipeline / Validate - Migration (alembic) (pull_request) Successful in 1m3s
CI/CD Pipeline / PR Build API Image (pull_request) Successful in 1m46s
CI/CD Pipeline / PR Build Web Image (pull_request) Successful in 1m39s
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 9s
PR Automation / Auto Approve on CI Green (pull_request) Successful in 39s
AI Code Review / AI Code Review (pull_request) Successful in 1m25s
Preview Deploy / Deploy Preview Environment (pull_request) Successful in 37s
PR Automation / Auto Merge on CI Green + Approved (pull_request) Successful in 15m11s
ACR Cleanup / ACR Image Cleanup (pull_request_target) Has been cancelled
CI/CD Pipeline / Unit Tests (pull_request) Has been skipped
CI/CD Pipeline / Frontend Unit Tests (pull_request) Failing after 38s
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 / Integration Tests (pull_request) Has been skipped
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Has been skipped
Preview Cleanup / Cleanup Preview Environment (pull_request) Successful in 14s
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
e82071f98e
auto-approve-bot approved these changes 2026-07-27 15:25:42 +08:00
auto-approve-bot left a comment
Collaborator

CI全绿,自动审批通过。

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

CI全绿,自动审批通过。

CI全绿,自动审批通过。
Collaborator

代码审查结果 - PR #1022

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

  1. apps/web/src/pages/duplication/DuplicationResults.tsx 第 42 行toast 状态未在 UI 中渲染。

    • 问题描述:从 useDuplicationResults hook 中解构出了 toast 状态,但在组件的 JSX 返回中并未使用该状态来渲染提示框。这导致用户在执行删除、重试等操作后无法看到成功或失败的反馈信息。
    • 修改建议:在页面中添加 Toast 组件的渲染逻辑,例如 <Toast message={toast?.message} type={toast?.type} />,或者如果不需要此功能,应从 hook 中移除相关逻辑。
  2. apps/web/src/pages/duplication/hooks/useDuplicationResults.ts 第 23 行showToast 函数存在内存泄漏风险。

    • 问题描述:在 showToast 中直接使用 setTimeout 更新 state。如果在定时器触发前组件卸载,将会尝试在未挂载的组件上执行 state 更新,导致 React 控制台报错 "Can't perform a React state update on an unmounted component"。
    • 修改建议:使用 useEffect 来管理定时器的副作用,并在 cleanup 函数中清除定时器,确保组件卸载时取消更新。

💡 建议(2个可选)

  1. apps/web/src/pages/duplication/components/ResultCard.tsx 第 48 行:日期解析缺乏容错处理。

    • 具体内容:直接使用 new Date(record.created_at) 解析日期,如果 created_at 为空或格式无效,将显示 "Invalid Date"。建议增加空值检查或使用 dayjs/date-fns 等库进行安全解析。
  2. apps/web/src/pages/duplication/components/ResultCard.tsx 第 38 行:冗余的 key 属性。

    • 具体内容:在 ResultCard 组件内部的根 div 上设置了 key={record.id},而父组件 DuplicationResults.tsx 在使用该组件时已经设置了 key。React 会忽略组件内部的 key 属性,建议移除组件内部的 key 定义以保持代码整洁。

格式检查通过 | 逻辑审查需修改 | ⚠️ 建议关注性能


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

## 代码审查结果 - PR #1022 ### ⚠️ 问题(2个需要修改) 1. **apps/web/src/pages/duplication/DuplicationResults.tsx 第 42 行**:`toast` 状态未在 UI 中渲染。 - 问题描述:从 `useDuplicationResults` hook 中解构出了 `toast` 状态,但在组件的 JSX 返回中并未使用该状态来渲染提示框。这导致用户在执行删除、重试等操作后无法看到成功或失败的反馈信息。 - 修改建议:在页面中添加 Toast 组件的渲染逻辑,例如 `<Toast message={toast?.message} type={toast?.type} />`,或者如果不需要此功能,应从 hook 中移除相关逻辑。 2. **apps/web/src/pages/duplication/hooks/useDuplicationResults.ts 第 23 行**:`showToast` 函数存在内存泄漏风险。 - 问题描述:在 `showToast` 中直接使用 `setTimeout` 更新 state。如果在定时器触发前组件卸载,将会尝试在未挂载的组件上执行 state 更新,导致 React 控制台报错 "Can't perform a React state update on an unmounted component"。 - 修改建议:使用 `useEffect` 来管理定时器的副作用,并在 cleanup 函数中清除定时器,确保组件卸载时取消更新。 ### 💡 建议(2个可选) 1. **apps/web/src/pages/duplication/components/ResultCard.tsx 第 48 行**:日期解析缺乏容错处理。 - 具体内容:直接使用 `new Date(record.created_at)` 解析日期,如果 `created_at` 为空或格式无效,将显示 "Invalid Date"。建议增加空值检查或使用 dayjs/date-fns 等库进行安全解析。 2. **apps/web/src/pages/duplication/components/ResultCard.tsx 第 38 行**:冗余的 `key` 属性。 - 具体内容:在 `ResultCard` 组件内部的根 `div` 上设置了 `key={record.id}`,而父组件 `DuplicationResults.tsx` 在使用该组件时已经设置了 `key`。React 会忽略组件内部的 `key` 属性,建议移除组件内部的 `key` 定义以保持代码整洁。 --- ✅ 格式检查通过 | ❌ 逻辑审查需修改 | ⚠️ 建议关注性能 --- <sub>🤖 由 AI 代码审查机器人自动生成 | 2026-07-27 07:26:24 | 模型: </sub> <!-- AI_CODE_REVIEW_AUTO_COMMENT -->

🚀 预览环境已部署

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

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

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

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

🚀 **预览环境已部署** | 项目 | 详情 | |------|------| | PR号 | #1022 | | 预览链接 | [https://pr-1022.preview.xiaoxiajianji.com](https://pr-1022.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 closed this pull request 2026-07-27 15:53:59 +08:00

🗑️ 预览环境已清理

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

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

🗑️ **预览环境已清理** PR #1022 已关闭或合并,对应的预览环境已被清理。 > 如有需要,可以重新打开 PR 来重新生成预览环境。
Some checks are pending
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 7s
CI/CD Pipeline / Validate - Type Check (mypy) (pull_request) Successful in 1m14s
CI/CD Pipeline / Validate - Code Quality (pull_request) Failing after 1m57s
CI/CD Pipeline / Frontend Lint (pull_request) Successful in 47s
CI/CD Pipeline / Validate - Migration (alembic) (pull_request) Successful in 1m3s
CI/CD Pipeline / PR Build API Image (pull_request) Successful in 1m46s
CI/CD Pipeline / PR Build Web Image (pull_request) Successful in 1m39s
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 9s
PR Automation / Auto Approve on CI Green (pull_request) Successful in 39s
AI Code Review / AI Code Review (pull_request) Successful in 1m25s
Preview Deploy / Deploy Preview Environment (pull_request) Successful in 37s
PR Automation / Auto Merge on CI Green + Approved (pull_request) Successful in 15m11s
ACR Cleanup / ACR Image Cleanup (pull_request_target) Has been cancelled
CI/CD Pipeline / Unit Tests (pull_request) Has been skipped
CI/CD Pipeline / Frontend Unit Tests (pull_request) Failing after 38s
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 / Integration Tests (pull_request) Has been skipped
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Has been skipped
Preview Cleanup / Cleanup Preview Environment (pull_request) Successful in 14s
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.