refactor(templates): 拆分 MyTemplates 页面,抽离数据 Hook + 卡片组件 #1019

Closed
xiaoxia wants to merge 1 commits from refactor/my-templates-split into develop
Owner

变更说明

拆分 MyTemplates 页面(254 行),按职责拆分为:

  • useMyTemplates - 模板列表查询、筛选、删除、复制等数据操作
  • TemplateCard - 单个模板卡片组件
  • MyTemplates - 页面入口 + 布局

主文件 254 → 130 行(-49%)

导入路径保持不变,向后兼容。

## 变更说明 拆分 MyTemplates 页面(254 行),按职责拆分为: - **useMyTemplates** - 模板列表查询、筛选、删除、复制等数据操作 - **TemplateCard** - 单个模板卡片组件 - **MyTemplates** - 页面入口 + 布局 主文件 254 → 130 行(-49%) 导入路径保持不变,向后兼容。
xiaoxia added 1 commit 2026-07-27 09:25:59 +08:00
refactor(templates): 拆分 MyTemplates 页面,抽离数据 Hook + 卡片组件
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 26s
CI/CD Pipeline / Validate - Type Check (mypy) (pull_request) Successful in 1m8s
CI/CD Pipeline / Validate - Migration (alembic) (pull_request) Successful in 1m15s
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 / Frontend Lint (pull_request) Failing after 56s
CI/CD Pipeline / PR Build Worker Image (pull_request) Successful in 50s
PR Automation / Auto Approve on CI Green (pull_request) Successful in 1m26s
CI/CD Pipeline / Validate - Code Quality (pull_request) Failing after 2m53s
PR Automation / Auto Merge on CI Green + Approved (pull_request) Successful in 1m11s
Preview Deploy / Deploy Preview Environment (pull_request) Successful in 1m9s
CI/CD Pipeline / PR Build Web Image (pull_request) Successful in 2m19s
AI Code Review / AI Code Review (pull_request) Successful in 4m1s
CI/CD Pipeline / PR Build API Image (pull_request) Successful in 7m3s
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 / Deploy Staging (Watchtower auto-deploy) (pull_request) Has been skipped
CI/CD Pipeline / Integration Tests (pull_request) Has been skipped
CI/CD Pipeline / Frontend Unit Tests (pull_request) Failing after 39s
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 / Deploy Production (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
ACR Cleanup / ACR Image Cleanup (pull_request_target) Has been cancelled
Preview Cleanup / Cleanup Preview Environment (pull_request) Successful in 19s
f02ea7207f
主文件 254→130 行(-49%),拆分为:
- useMyTemplates: 模板列表查询、筛选、删除、复制等数据操作
- TemplateCard: 单个模板卡片组件
- MyTemplates: 页面入口 + 布局

导入路径保持向后兼容

🚀 预览环境已部署

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

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

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

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

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

代码审查结果 - PR #1019

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

  1. apps/web/src/pages/my-templates/hooks/useMyTemplates.ts 第84-89行handleCopyhandleDelete 函数未使用 useCallback 包裹。
    • 问题描述:这两个函数在 Hook 每次执行时都会重新创建,导致引用地址变化。当父组件 MyTemplates 因搜索或筛选状态更新而重渲染时,传递给所有 TemplateCardonCopyonDelete props 都会变化,导致所有卡片组件发生不必要的重渲染,在模板数量较多时会造成明显的性能卡顿。
    • 修改建议:使用 useCallback 包裹这两个函数,并将 copyMutation.mutatedeleteMutation.mutate 加入依赖数组。

💡 建议(1个可选)

  1. apps/web/src/pages/my-templates/MyTemplates.tsx 第17行:Hook 返回的加载状态未被使用。
    • 问题描述useMyTemplates Hook 中计算并返回了 isDeletingisCopying 状态,但在 MyTemplates.tsx 中解构时未接收这两个值,也没有传递给 TemplateCard。这导致用户点击删除或复制时,按钮没有 loading 状态,可能引起重复点击或用户困惑。
    • 修改建议:在父组件接收这两个状态,并透传给 TemplateCard 组件,以便在按钮上展示 loading 效果。

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


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

## 代码审查结果 - PR #1019 ### ⚠️ 问题(1个需要修改) 1. **apps/web/src/pages/my-templates/hooks/useMyTemplates.ts 第84-89行**:`handleCopy` 和 `handleDelete` 函数未使用 `useCallback` 包裹。 - **问题描述**:这两个函数在 Hook 每次执行时都会重新创建,导致引用地址变化。当父组件 `MyTemplates` 因搜索或筛选状态更新而重渲染时,传递给所有 `TemplateCard` 的 `onCopy` 和 `onDelete` props 都会变化,导致所有卡片组件发生不必要的重渲染,在模板数量较多时会造成明显的性能卡顿。 - **修改建议**:使用 `useCallback` 包裹这两个函数,并将 `copyMutation.mutate` 和 `deleteMutation.mutate` 加入依赖数组。 ### 💡 建议(1个可选) 1. **apps/web/src/pages/my-templates/MyTemplates.tsx 第17行**:Hook 返回的加载状态未被使用。 - **问题描述**:`useMyTemplates` Hook 中计算并返回了 `isDeleting` 和 `isCopying` 状态,但在 `MyTemplates.tsx` 中解构时未接收这两个值,也没有传递给 `TemplateCard`。这导致用户点击删除或复制时,按钮没有 loading 状态,可能引起重复点击或用户困惑。 - **修改建议**:在父组件接收这两个状态,并透传给 `TemplateCard` 组件,以便在按钮上展示 loading 效果。 --- ✅ 格式检查通过 | ✅ 逻辑审查通过 | ⚠️ 建议关注性能 --- <sub>🤖 由 AI 代码审查机器人自动生成 | 2026-07-27 01:49:29 | 模型: </sub> <!-- AI_CODE_REVIEW_AUTO_COMMENT -->
xiaoxia closed this pull request 2026-07-27 12:50:15 +08:00

🗑️ 预览环境已清理

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

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

🗑️ **预览环境已清理** PR #1019 已关闭或合并,对应的预览环境已被清理。 > 如有需要,可以重新打开 PR 来重新生成预览环境。
Some checks are pending
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 26s
CI/CD Pipeline / Validate - Type Check (mypy) (pull_request) Successful in 1m8s
CI/CD Pipeline / Validate - Migration (alembic) (pull_request) Successful in 1m15s
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 / Frontend Lint (pull_request) Failing after 56s
CI/CD Pipeline / PR Build Worker Image (pull_request) Successful in 50s
PR Automation / Auto Approve on CI Green (pull_request) Successful in 1m26s
CI/CD Pipeline / Validate - Code Quality (pull_request) Failing after 2m53s
PR Automation / Auto Merge on CI Green + Approved (pull_request) Successful in 1m11s
Preview Deploy / Deploy Preview Environment (pull_request) Successful in 1m9s
CI/CD Pipeline / PR Build Web Image (pull_request) Successful in 2m19s
AI Code Review / AI Code Review (pull_request) Successful in 4m1s
CI/CD Pipeline / PR Build API Image (pull_request) Successful in 7m3s
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 / Deploy Staging (Watchtower auto-deploy) (pull_request) Has been skipped
CI/CD Pipeline / Integration Tests (pull_request) Has been skipped
CI/CD Pipeline / Frontend Unit Tests (pull_request) Failing after 39s
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 / Deploy Production (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
ACR Cleanup / ACR Image Cleanup (pull_request_target) Has been cancelled
Preview Cleanup / Cleanup Preview Environment (pull_request) Successful in 19s

Pull request closed

Sign in to join this conversation.