refactor(quality): Q12 前端巨型组件拆分 — CloudServerImport 699L→404L (-42%), 提取 StepIndicator + 4 个向导步骤组件 + types, any[]→具体接口类型, 移除文件级 eslint-disable

This commit is contained in:
attacker committed 2026-07-07 18:06:45 +08:00
1 parent 76aa8817c0
commit b2e8fbbfc0
10 files changed
+660 -394

No files matched your search

+39
View File
@@ -483,6 +483,7 @@ services/api.ts (1324L)
| Q9 | 前端巨型组件拆分(NamespaceResourcePage 719L→300L,提取 RESOURCE_CONFIG + PodDetailDialog) | P0 | **done** |
| Q10 | 前端巨型组件拆分(ApprovalWorkflowPage 705L→167L,提取 types + UserSelectInline + WorkflowEditorModal + WorkflowCard) | P0 | **done** |
| Q11 | 前端巨型组件拆分(PipelineRunDetail 678L→273L,提取 types + StageProgressBar + RunsTable + LogConsole) | P0 | **done** |
| Q12 | 前端巨型组件拆分(CloudServerImport 699L→404L,提取 StepIndicator + 4 个向导步骤组件 + types,any[]→具体接口) | P0 | **done** |
---
@@ -809,3 +810,41 @@ pending → in_progress → done / blocked
- [x] 17/17 集成回归测试通过(零回归)
- [x] Docker 部署 healthy
- [x] 流水线运行详情页功能不变(阶段进度条/执行记录表/日志 Console/文件浏览器全部正常)
---
## Q12: 前端巨型组件拆分 — CloudServerImport [done]
**问题**: `CloudServerImport.tsx`(699 行)是 Q11 拆分后项目最大的业务组件之一(排除 UI 库 sidebar/data-table),包含云服务器导入 4 步骤向导的全部逻辑:状态管理(17 个 useState)、数据加载/区域同步/主机发现/导入业务逻辑、步骤指示器、4 个步骤的内联 JSX(云厂商选择/账号选择/区域选择表格/发现导入主机列表)、底部导航按钮。单文件过大导致维护困难、代码导航低效。此外文件顶部有 `eslint-disable @typescript-eslint/no-explicit-any`,状态用 `any[]` 类型。
**已完成 (2026-07-07)**:
将步骤指示器、4 个向导步骤的 JSX、类型/常量提取为 `cloud-server-import/` 子目录下的独立文件:
| 新文件 | 行数 | 职责 |
|--------|------|------|
| `types.ts` | 57 | CloudAccount/CloudRegion/CloudServer/ImportResult/StepDef 接口 + CLOUD_PROVIDERS 常量 |
| `StepIndicator.tsx` | 34 | 顶部 4 步骤进度指示器(当前/已完成/未完成三态 + ChevronRight 连接器) |
| `ProviderSelectStep.tsx` | 42 | Step 1 云厂商选择(5 厂商卡片网格 + CloudBrandIcon) |
| `AccountSelectStep.tsx` | 65 | Step 2 云账号选择(账号卡片列表 + 区域数/主机数 Badge + 空状态) |
| `RegionSelectStep.tsx` | 131 | Step 3 区域选择(搜索框 + 全选 + 区域表格 + 同步按钮 + 凭证设置插槽) |
| `DiscoverImportStep.tsx` | 176 | Step 4 发现导入(结果页/发现按钮/区域标签/错误提示/主机列表 + 凭证设置插槽) |
主文件 `CloudServerImport.tsx` 从 **699 行降至 404 行**(-42%),仅保留:17 个状态声明、数据加载/区域同步/主机发现/导入业务逻辑、步骤导航(handleNext/handleBack/handleClose)、派生数据(filteredAccounts/filteredRegions/steps)、importSettingsPanel 条件渲染、Dialog 外壳 + StepIndicator + 4 步骤分发 + Footer 导航按钮。
**类型安全升级**: 顺带移除文件顶部的 `/* eslint-disable @typescript-eslint/no-explicit-any */`,将 `any[]` 状态类型化为具体接口(`CloudAccount[]`/`CloudRegion[]`/`CloudServer[]`/`ImportResult`),消除 API 调用中不必要的 `Record<string, unknown>` 中间转换(直接访问 `.list` 属性)。全局 ESLint any 保持 **0**。
**提取原则**: 每个步骤是自包含的纯展示函数组件,通过 props 接收所需状态 + 回调(ProviderSelectStep 取 2 个、AccountSelectStep 取 3 个、RegionSelectStep 取 10 个、DiscoverImportStep 取 12 个),无共享状态。importSettingsPanel 作为 ReactNode 由父组件渲染后传入(Step 3/4 共用)。零逻辑变更。
**验收标准**:
- [x] CloudServerImport.tsx 从 699 行降至 **404 行**(-42%)
- [x] 6 个提取的文件全部 < 180 行(最大 DiscoverImportStep 176 行)
- [x] `tsc -b` 零错误
- [x] `npm run build` 零错误(✓ built in 16.56s)
- [x] ESLint errors 保持 **0**(拆分文件零 warnings)
- [x] ESLint warnings 保持 **64**(无新增)
- [x] 全局 ESLint any 保持 **0**(移除文件级 eslint-disable)
- [x] `go build` 零错误
- [x] 17/17 集成回归测试通过(零回归)
- [x] Docker 部署 healthy,前端页面正常加载(HTTP 200)
- [x] 云服务器导入向导功能不变(4 步骤切换/厂商选择/账号选择/区域选择/发现导入全部正常)