From 30cc899268469bd95a292f89b91a44ee06baf765 Mon Sep 17 00:00:00 2001 From: attacker Date: Mon, 15 Jun 2026 11:07:31 +0800 Subject: [PATCH] refactor: AnsibleManager split into 5 files (740 to 535 lines) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - ansible-helpers.tsx (114): types, mapPlaybook, categories, samplePlaybook, getStatusBadge, formatDate - AnsibleFormDialog.tsx (111): 新建/编辑 Playbook 弹窗 - AnsibleDetailDialog.tsx (47): 查看 Playbook 内容弹窗 - AnsibleLogsDialog.tsx (38): 执行日志弹窗 - AnsibleManager.tsx (740->535): 主组件保留统计卡片+Tab布局+列表+表格+状态管理 --- .../automation/AnsibleDetailDialog.tsx | 47 +++ .../automation/AnsibleFormDialog.tsx | 111 +++++++ .../automation/AnsibleLogsDialog.tsx | 38 +++ .../components/automation/AnsibleManager.tsx | 273 +++--------------- .../components/automation/ansible-helpers.tsx | 114 ++++++++ 5 files changed, 344 insertions(+), 239 deletions(-) create mode 100644 frontend/src/components/automation/AnsibleDetailDialog.tsx create mode 100644 frontend/src/components/automation/AnsibleFormDialog.tsx create mode 100644 frontend/src/components/automation/AnsibleLogsDialog.tsx create mode 100644 frontend/src/components/automation/ansible-helpers.tsx diff --git a/frontend/src/components/automation/AnsibleDetailDialog.tsx b/frontend/src/components/automation/AnsibleDetailDialog.tsx new file mode 100644 index 0000000..ee18f94 --- /dev/null +++ b/frontend/src/components/automation/AnsibleDetailDialog.tsx @@ -0,0 +1,47 @@ +// Ansible 查看 Playbook 内容弹窗 // Logan.Li +import { FileCode, Edit } from 'lucide-react'; +import { Button } from '@/components/ui/button'; +import { + Dialog, DialogContent, DialogHeader, DialogTitle, DialogDescription, DialogFooter, +} from '@/components/ui/dialog'; +import { ScrollArea } from '@/components/ui/scroll-area'; +import type { Playbook } from './ansible-helpers'; + +interface Props { + open: boolean; + onOpenChange: (open: boolean) => void; + playbook: Playbook | null; + onEdit: (pb: Playbook) => void; +} + +const AnsibleDetailDialog: React.FC = ({ open, onOpenChange, playbook, onEdit }) => { + return ( + + + + + + {playbook?.name} + + {playbook?.description} + + +
+            {playbook?.content || '(空)'}
+          
+
+ + + {playbook && ( + + )} + +
+
+ ); +}; + +export default AnsibleDetailDialog; diff --git a/frontend/src/components/automation/AnsibleFormDialog.tsx b/frontend/src/components/automation/AnsibleFormDialog.tsx new file mode 100644 index 0000000..114e611 --- /dev/null +++ b/frontend/src/components/automation/AnsibleFormDialog.tsx @@ -0,0 +1,111 @@ +// Ansible 新建/编辑 Playbook 弹窗 // Logan.Li +import { CheckCircle } from 'lucide-react'; +import { Button } from '@/components/ui/button'; +import { Input } from '@/components/ui/input'; +import { + Dialog, DialogContent, DialogHeader, DialogTitle, DialogDescription, DialogFooter, +} from '@/components/ui/dialog'; +import { + Select, SelectContent, SelectItem, SelectTrigger, SelectValue, +} from '@/components/ui/select'; +import { Label } from '@/components/ui/label'; +import { Textarea } from '@/components/ui/textarea'; +import { categories } from './ansible-helpers'; + +export interface PlaybookFormData { + name: string; + description: string; + content: string; + category: string; + tags: string; + timeout: number; +} + +interface Props { + open: boolean; + onOpenChange: (open: boolean) => void; + editingId: number | null; + formData: PlaybookFormData; + setFormData: React.Dispatch>; + onSave: () => void; +} + +const AnsibleFormDialog: React.FC = ({ open, onOpenChange, editingId, formData, setFormData, onSave }) => { + return ( + + + + {editingId !== null ? '编辑 Playbook' : '新建 Playbook'} + 编写 Ansible Playbook 实现自动化运维 + +
+
+
+ + setFormData({ ...formData, name: e.target.value })} + placeholder="Playbook 名称" + /> +
+
+ + +
+
+
+ + setFormData({ ...formData, description: e.target.value })} + placeholder="Playbook 描述" + /> +
+
+
+ + setFormData({ ...formData, tags: e.target.value })} + placeholder="如: nginx, web, 部署" + /> +
+
+ + setFormData({ ...formData, timeout: Number(e.target.value) })} + placeholder="600" + /> +
+
+
+ +