From 28655b4ad5fad499ba251a748dd1b4d9f6bc7490 Mon Sep 17 00:00:00 2001 From: attacker Date: Wed, 17 Jun 2026 00:05:38 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E6=8B=86=E5=88=86AppRelease.tsx(65?= =?UTF-8?q?0=E2=86=92339=E8=A1=8C)=E6=8F=90=E5=8F=96ReleaseDetailDialog+Re?= =?UTF-8?q?leaseCreateDialog+releaseHelpers=E5=AD=90=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/components/deploy/AppRelease.tsx | 343 +----------------- .../components/deploy/ReleaseCreateDialog.tsx | 162 +++++++++ .../components/deploy/ReleaseDetailDialog.tsx | 138 +++++++ .../src/components/deploy/releaseHelpers.tsx | 92 +++++ 4 files changed, 408 insertions(+), 327 deletions(-) create mode 100644 frontend/src/components/deploy/ReleaseCreateDialog.tsx create mode 100644 frontend/src/components/deploy/ReleaseDetailDialog.tsx create mode 100644 frontend/src/components/deploy/releaseHelpers.tsx diff --git a/frontend/src/components/deploy/AppRelease.tsx b/frontend/src/components/deploy/AppRelease.tsx index 2975756..aa42a91 100644 --- a/frontend/src/components/deploy/AppRelease.tsx +++ b/frontend/src/components/deploy/AppRelease.tsx @@ -1,12 +1,9 @@ import { useState, useEffect } from 'react'; import { useNavigate } from 'react-router-dom'; -import { cn } from '@/lib/utils'; -import { Card, CardContent, CardHeader, CardTitle, CardDescription } from '@/components/ui/card'; +import { Card, CardContent } from '@/components/ui/card'; import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { Badge } from '@/components/ui/badge'; -import { Progress } from '@/components/ui/progress'; -import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs'; import { Table, TableBody, @@ -15,15 +12,6 @@ import { TableHeader, TableRow, } from '@/components/ui/table'; -import { - Dialog, - DialogContent, - DialogDescription, - DialogFooter, - DialogHeader, - DialogTitle, - DialogTrigger, -} from '@/components/ui/dialog'; import { Select, SelectContent, @@ -31,31 +19,25 @@ import { SelectTrigger, SelectValue, } from '@/components/ui/select'; -import { Textarea } from '@/components/ui/textarea'; -import { Label } from '@/components/ui/label'; import { Rocket, Plus, Search, - Play, RotateCcw, CheckCircle, XCircle, - Clock, GitBranch, GitCommit, - User, - MoreHorizontal, Eye, Settings, History, - Pause, Loader2, - ArrowLeft, - ArrowRight, } from 'lucide-react'; import { releaseApi } from '@/services/api'; import { toast } from 'sonner'; +import { getStatusBadge, getEnvBadge } from './releaseHelpers'; +import { ReleaseDetailDialog } from './ReleaseDetailDialog'; +import { ReleaseCreateDialog } from './ReleaseCreateDialog'; export function AppReleaseManager() { const navigate = useNavigate(); @@ -66,15 +48,6 @@ export function AppReleaseManager() { const [loading, setLoading] = useState(true); const [selectedRelease, setSelectedRelease] = useState(null); const [isCreateDialogOpen, setIsCreateDialogOpen] = useState(false); - const [submitting, setSubmitting] = useState(false); - const [newRelease, setNewRelease] = useState({ - appName: '', - version: '', - environment: 'dev', - commitId: '', - commitMsg: '', - description: '', - }); const loadData = async () => { try { @@ -101,75 +74,7 @@ export function AppReleaseManager() { return matchesSearch && matchesEnv && matchesStatus; }); - const getStatusBadge = (status: any) => { - switch (status) { - case 'success': - return ( - - - 成功 - - ); - case 'failed': - return ( - - - 失败 - - ); - case 'deploying': - return ( - - - 发布中 - - ); - case 'building': - return ( - - - 构建中 - - ); - case 'rolled_back': - return ( - - - 已回滚 - - ); - case 'pending': - return ( - - - 待发布 - - ); - default: - return null; - } - }; - - const getEnvBadge = (env: any) => { - const colors: Record = { - dev: 'border-slate-500/30 text-slate-400 bg-slate-500/10', - test: 'border-blue-500/30 text-blue-400 bg-blue-500/10', - staging: 'border-amber-500/30 text-amber-400 bg-amber-500/10', - prod: 'border-emerald-500/30 text-emerald-400 bg-emerald-500/10', - }; - const labels: Record = { - dev: '开发环境', - test: '测试环境', - staging: '预发布', - prod: '生产环境', - }; - return ( - - {labels[env] || env} - - ); - }; - + // 回滚发布 // Logan.Li const handleRollback = async (id: any) => { try { await releaseApi.rollbackRelease(id); @@ -179,45 +84,6 @@ export function AppReleaseManager() { } }; - // 新建发布提交(复用 releaseApi.createRelease) // Logan.Li - const handleCreateRelease = async () => { - if (!newRelease.appName.trim() || !newRelease.version.trim()) { - toast.error('请填写应用名称和版本号'); - return; - } - setSubmitting(true); - try { - await releaseApi.createRelease({ - app_name: newRelease.appName.trim(), - version: newRelease.version.trim(), - environment: newRelease.environment, - commit_id: newRelease.commitId.trim(), - commit_msg: newRelease.commitMsg.trim(), - description: newRelease.description.trim(), - }); - toast.success('发布申请已提交'); - setIsCreateDialogOpen(false); - setNewRelease({ appName: '', version: '', environment: 'dev', commitId: '', commitMsg: '', description: '' }); - loadData(); - } catch { - toast.error('创建失败'); - } finally { - setSubmitting(false); - } - }; - - // 模拟流水线步骤 - const pipelineSteps = [ - { name: '代码检出', status: 'success', duration: '15s' }, - { name: '依赖安装', status: 'success', duration: '45s' }, - { name: '代码检查', status: 'success', duration: '30s' }, - { name: '单元测试', status: 'success', duration: '2m 15s' }, - { name: '构建镜像', status: 'success', duration: '3m 30s' }, - { name: '推送镜像', status: 'success', duration: '1m 20s' }, - { name: '部署到K8s', status: 'running', duration: '--' }, - { name: '健康检查', status: 'pending', duration: '--' }, - ]; - return (
{/* Page Header */} @@ -455,196 +321,19 @@ export function AppReleaseManager() { {/* Release Detail Dialog */} - setSelectedRelease(null)}> - - - - - {selectedRelease?.app_name} - - {selectedRelease?.version} - - - - 环境: {selectedRelease?.environment} - - - -
- {/* Pipeline Steps */} -
-

发布进度

-
- {pipelineSteps.map((step, index) => ( -
-
- {step.status === 'success' ? ( - - ) : step.status === 'running' ? ( - - ) : ( - {index + 1} - )} -
- {step.name} - {step.duration} -
- ))} -
-
- - {/* Build Logs */} -
-

构建日志

-
-
-

[10:00:00] Starting pipeline for {selectedRelease?.app_name}...

-

[10:00:15] Checkout code from branch {selectedRelease?.branch}

-

[10:00:30] Installing dependencies...

-

[10:01:15] Dependencies installed successfully

-

[10:01:15] Running code analysis...

-

[10:01:45] Code analysis passed

-

[10:01:45] Running unit tests...

-

[10:04:00] All tests passed (156/156)

-

[10:04:00] Building Docker image...

-

[10:07:30] Image built successfully

-

[10:07:30] Pushing image to registry...

-

[10:08:50] Image pushed successfully

-

[10:08:50] Deploying to Kubernetes...

-

[10:10:00] Deployment in progress...

-
-
-
-
- - - {selectedRelease?.status === 'failed' && ( - - )} - -
-
+ { if (!open) setSelectedRelease(null); }} + onSuccess={loadData} + /> {/* Create Release Dialog */} - - - - 新建发布 - 创建新的应用版本发布申请 - -
-
- - setNewRelease({ ...newRelease, appName: e.target.value })} - placeholder="如:用户中心服务" - className="mt-1 bg-slate-800/50 border-slate-700 text-slate-200 placeholder:text-slate-500" - /> -
-
-
- - setNewRelease({ ...newRelease, version: e.target.value })} - placeholder="v1.0.0" - className="mt-1 bg-slate-800/50 border-slate-700 text-slate-200 placeholder:text-slate-500" - /> -
-
- - -
-
-
-
- - setNewRelease({ ...newRelease, commitId: e.target.value })} - placeholder="abc1234" - className="mt-1 bg-slate-800/50 border-slate-700 text-slate-200 placeholder:text-slate-500" - /> -
-
- - setNewRelease({ ...newRelease, commitMsg: e.target.value })} - placeholder="feat: 新增功能" - className="mt-1 bg-slate-800/50 border-slate-700 text-slate-200 placeholder:text-slate-500" - /> -
-
-
- -