refactor(quality): Q17 前端巨型组件拆分 — DeploymentEditService 627L→394L (-37%), 提取 types + ServiceCreateForm + IngressCreateForm + ServiceListItem + IngressListItem 5 个独立文件, 端口增删改逻辑下沉到 ServiceCreateForm, 移除文件级 eslint-disable, 零逻辑变更, ESLint errors=0/warnings=64/any=0, tsc -b=0, npm build✓, 17/17 测试通过
This commit is contained in:
1 parent
4905724338
commit
6f1c79fd51
8 files changed
+495
-305
No files matched your search
+36
@@ -488,6 +488,42 @@ services/api.ts (1324L)
|
||||
| Q14 | 前端巨型组件拆分(ServerManager 652L→442L,提取 ServerTableSection + server-export-utils) | P0 | **done** |
|
||||
| Q15 | 前端巨型组件拆分(PipelineEditor 676L→406L,提取 types + TaskCard + TaskEditorPanel + PipelineLogDialog + RunsHistoryTab + PipelineMembersTab) | P0 | **done** |
|
||||
| Q16 | 前端巨型组件拆分(RdpDialog 642L→442L,提取 types + rdpp-utils + RdpDialogHeader) | P0 | **done** |
|
||||
| Q17 | 前端巨型组件拆分(DeploymentEditService 627L→394L,提取 types + ServiceCreateForm + IngressCreateForm + ServiceListItem + IngressListItem) | P0 | **done** |
|
||||
|
||||
---
|
||||
|
||||
## Q17: 前端巨型组件拆分 — DeploymentEditService [done]
|
||||
|
||||
**问题**: `DeploymentEditService.tsx`(627 行)是 Q16 拆分后项目最大的核心业务组件之一(排除 UI 库 sidebar/data-table),包含 Deployment 编辑器「服务/应用路由」Tab 的全部逻辑:类型定义 + 端口预设常量、多端口 Service 创建表单(端口增删改 + 快速预设 + NodePort/ClusterIP 类型切换 + selector 预览)、Ingress 创建表单、Service/Ingress 列表卡片渲染(selector 关联高亮 + 端口/路由规则展示)、数据加载(Promise.all 拉取关联 Service/Ingress 并解析为摘要)、manifest 构建(createService/createIngress)、删除确认、以及可视化编辑器挂载。单文件过大导致维护困难。
|
||||
|
||||
**已完成 (2026-07-08)**:
|
||||
|
||||
将类型/常量、创建表单、列表卡片提取为 `deployment-edit-service/` 子目录下的独立文件:
|
||||
|
||||
| 新文件 | 行数 | 职责 |
|
||||
|--------|------|------|
|
||||
| `types.ts` | 78 | SvcPort/SvcSummary/IngBackend/IngPath/IngRule/IngSummary 接口 + SvcPortFormItem/SvcFormState/IngFormState 表单状态类型 + PORT_PRESETS 端口预设常量 + toArray 后端响应归一化辅助 |
|
||||
| `ServiceCreateForm.tsx` | 147 | 创建 Service 表单(基本信息 + 快速预设按钮 + 多端口配置行 + selector 预览),受控组件接收 svcForm/setSvcForm,内部管理 addPort/updatePort/removePort 端口操作 |
|
||||
| `IngressCreateForm.tsx` | 61 | 创建 Ingress 表单(名称/ingressClass/host/path/svcPort),受控组件接收 ingForm/setIngForm |
|
||||
| `ServiceListItem.tsx` | 52 | 单个 Service 卡片(关联高亮 + ClusterIP + 端口标签 + selector),纯展示组件接收 svc + matched + onEdit/onDelete |
|
||||
| `IngressListItem.tsx` | 49 | 单个 Ingress 卡片(关联高亮 + 路由规则 host→path→backend),纯展示组件接收 ing + matched + onEdit/onDelete |
|
||||
|
||||
主文件 `DeploymentEditService.tsx` 从 **627 行降至 394 行**(-37%),仅保留:状态管理(loading/services/ingresses/selectorLabels/visualEditor/showCreate/svcForm/ingForm)、数据加载(load + Promise.all + 摘要解析)、selectorMatches 关联判定、派生数据(matchedSvcs/matchedSvcNames/matchedIngs)、manifest 构建与 API 调用(createService/createIngress/deleteResource)、loading 骨架、Selector 提示卡片、Services/Ingresses 卡片外壳(header + 空状态 + 列表编排 + 表单挂载)、ResourceVisualEditor 挂载、取消按钮。
|
||||
|
||||
**提取原则**: types 为纯数据/类型(零 React 依赖);ServiceCreateForm 为受控表单组件(接收 svcForm + setSvcForm,内部封装端口增删改逻辑);IngressCreateForm 为受控表单组件;ServiceListItem/IngressListItem 为纯展示组件(接收数据 + matched 状态 + 回调)。零逻辑变更。类型安全方面,SvcPort.targetPort 和 IngBackend.port 保持 `unknown` 类型(与后端动态值一致),列表渲染处用 `String()` 包裹(与原 `any` 渲染结果一致),移除了原文件顶部的文件级 `eslint-disable @typescript-eslint/no-explicit-any`。
|
||||
|
||||
**验收标准**:
|
||||
- [x] DeploymentEditService.tsx 从 627 行降至 **394 行**(-37%)
|
||||
- [x] 5 个提取的文件全部 < 150 行(最大 ServiceCreateForm 147 行)
|
||||
- [x] `tsc -b` 零错误
|
||||
- [x] `npm run build` 零错误(✓ built in 16.86s)
|
||||
- [x] ESLint errors 保持 **0**(拆分目录零 errors/warnings,清理 1 个冗余 disable 指令)
|
||||
- [x] ESLint warnings 保持 **64**(无新增)
|
||||
- [x] 全局 ESLint any 保持 **0**
|
||||
- [x] `go build` 零错误
|
||||
- [x] 17/17 集成回归测试通过(零回归)
|
||||
- [x] Docker 部署 healthy
|
||||
- [x] Deployment 服务/路由编辑 Tab 功能不变(Service/Ingress 列表关联高亮、创建表单多端口配置、编辑/删除、可视化编辑器全部正常)
|
||||
|
||||
---
|
||||
|
||||
|
||||
Reference in new issue
Block a user