This commit is contained in:
dengqichen 2024-12-27 18:55:14 +08:00
parent f6e19d7c24
commit 2bc93a5744
3 changed files with 186 additions and 91 deletions

View File

@ -28,11 +28,13 @@
"@logicflow/extension": "^2.0.13",
"@monaco-editor/react": "^4.6.0",
"@radix-ui/react-avatar": "^1.1.2",
"@radix-ui/react-dialog": "^1.1.4",
"@radix-ui/react-label": "^2.1.1",
"@radix-ui/react-progress": "^1.1.1",
"@radix-ui/react-select": "^2.1.4",
"@radix-ui/react-separator": "^1.1.1",
"@radix-ui/react-slot": "^1.1.1",
"@radix-ui/react-switch": "^1.1.2",
"@radix-ui/react-tabs": "^1.1.2",
"@reduxjs/toolkit": "^2.0.1",
"@types/recharts": "^1.8.29",

View File

@ -62,6 +62,9 @@ importers:
'@radix-ui/react-avatar':
specifier: ^1.1.2
version: 1.1.2(@types/react-dom@18.3.5(@types/react@18.3.16))(@types/react@18.3.16)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)
'@radix-ui/react-dialog':
specifier: ^1.1.4
version: 1.1.4(@types/react-dom@18.3.5(@types/react@18.3.16))(@types/react@18.3.16)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)
'@radix-ui/react-label':
specifier: ^2.1.1
version: 2.1.1(@types/react-dom@18.3.5(@types/react@18.3.16))(@types/react@18.3.16)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)
@ -77,6 +80,9 @@ importers:
'@radix-ui/react-slot':
specifier: ^1.1.1
version: 1.1.1(@types/react@18.3.16)(react@18.3.1)
'@radix-ui/react-switch':
specifier: ^1.1.2
version: 1.1.2(@types/react-dom@18.3.5(@types/react@18.3.16))(@types/react@18.3.16)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)
'@radix-ui/react-tabs':
specifier: ^1.1.2
version: 1.1.2(@types/react-dom@18.3.5(@types/react@18.3.16))(@types/react@18.3.16)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)
@ -877,6 +883,19 @@ packages:
'@types/react':
optional: true
'@radix-ui/react-dialog@1.1.4':
resolution: {integrity: sha512-Ur7EV1IwQGCyaAuyDRiOLA5JIUZxELJljF+MbM/2NC0BYwfuRrbpS30BiQBJrVruscgUkieKkqXYDOoByaxIoA==}
peerDependencies:
'@types/react': '*'
'@types/react-dom': '*'
react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc
react-dom: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc
peerDependenciesMeta:
'@types/react':
optional: true
'@types/react-dom':
optional: true
'@radix-ui/react-direction@1.1.0':
resolution: {integrity: sha512-BUuBvgThEiAXh2DWu93XsT+a3aWrGqolGlqqw5VU1kG7p/ZH2cuDlM1sRLNnY3QcBS69UIz2mcKhMxDsdewhjg==}
peerDependencies:
@ -1056,6 +1075,19 @@ packages:
'@types/react':
optional: true
'@radix-ui/react-switch@1.1.2':
resolution: {integrity: sha512-zGukiWHjEdBCRyXvKR6iXAQG6qXm2esuAD6kDOi9Cn+1X6ev3ASo4+CsYaD6Fov9r/AQFekqnD/7+V0Cs6/98g==}
peerDependencies:
'@types/react': '*'
'@types/react-dom': '*'
react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc
react-dom: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc
peerDependenciesMeta:
'@types/react':
optional: true
'@types/react-dom':
optional: true
'@radix-ui/react-tabs@1.1.2':
resolution: {integrity: sha512-9u/tQJMcC2aGq7KXpGivMm1mgq7oRJKXphDwdypPd/j21j/2znamPU8WkXgnhUaTrSFNIt8XhOyCAupg8/GbwQ==}
peerDependencies:
@ -4288,6 +4320,28 @@ snapshots:
optionalDependencies:
'@types/react': 18.3.16
'@radix-ui/react-dialog@1.1.4(@types/react-dom@18.3.5(@types/react@18.3.16))(@types/react@18.3.16)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)':
dependencies:
'@radix-ui/primitive': 1.1.1
'@radix-ui/react-compose-refs': 1.1.1(@types/react@18.3.16)(react@18.3.1)
'@radix-ui/react-context': 1.1.1(@types/react@18.3.16)(react@18.3.1)
'@radix-ui/react-dismissable-layer': 1.1.3(@types/react-dom@18.3.5(@types/react@18.3.16))(@types/react@18.3.16)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)
'@radix-ui/react-focus-guards': 1.1.1(@types/react@18.3.16)(react@18.3.1)
'@radix-ui/react-focus-scope': 1.1.1(@types/react-dom@18.3.5(@types/react@18.3.16))(@types/react@18.3.16)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)
'@radix-ui/react-id': 1.1.0(@types/react@18.3.16)(react@18.3.1)
'@radix-ui/react-portal': 1.1.3(@types/react-dom@18.3.5(@types/react@18.3.16))(@types/react@18.3.16)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)
'@radix-ui/react-presence': 1.1.2(@types/react-dom@18.3.5(@types/react@18.3.16))(@types/react@18.3.16)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)
'@radix-ui/react-primitive': 2.0.1(@types/react-dom@18.3.5(@types/react@18.3.16))(@types/react@18.3.16)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)
'@radix-ui/react-slot': 1.1.1(@types/react@18.3.16)(react@18.3.1)
'@radix-ui/react-use-controllable-state': 1.1.0(@types/react@18.3.16)(react@18.3.1)
aria-hidden: 1.2.4
react: 18.3.1
react-dom: 18.3.1(react@18.3.1)
react-remove-scroll: 2.6.2(@types/react@18.3.16)(react@18.3.1)
optionalDependencies:
'@types/react': 18.3.16
'@types/react-dom': 18.3.5(@types/react@18.3.16)
'@radix-ui/react-direction@1.1.0(@types/react@18.3.16)(react@18.3.1)':
dependencies:
react: 18.3.1
@ -4459,6 +4513,21 @@ snapshots:
optionalDependencies:
'@types/react': 18.3.16
'@radix-ui/react-switch@1.1.2(@types/react-dom@18.3.5(@types/react@18.3.16))(@types/react@18.3.16)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)':
dependencies:
'@radix-ui/primitive': 1.1.1
'@radix-ui/react-compose-refs': 1.1.1(@types/react@18.3.16)(react@18.3.1)
'@radix-ui/react-context': 1.1.1(@types/react@18.3.16)(react@18.3.1)
'@radix-ui/react-primitive': 2.0.1(@types/react-dom@18.3.5(@types/react@18.3.16))(@types/react@18.3.16)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)
'@radix-ui/react-use-controllable-state': 1.1.0(@types/react@18.3.16)(react@18.3.1)
'@radix-ui/react-use-previous': 1.1.0(@types/react@18.3.16)(react@18.3.1)
'@radix-ui/react-use-size': 1.1.0(@types/react@18.3.16)(react@18.3.1)
react: 18.3.1
react-dom: 18.3.1(react@18.3.1)
optionalDependencies:
'@types/react': 18.3.16
'@types/react-dom': 18.3.5(@types/react@18.3.16)
'@radix-ui/react-tabs@1.1.2(@types/react-dom@18.3.5(@types/react@18.3.16))(@types/react@18.3.16)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)':
dependencies:
'@radix-ui/primitive': 1.1.1

View File

@ -1,37 +1,40 @@
import React, { useState, useEffect } from 'react';
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import { Badge } from "@/components/ui/badge";
import { Progress } from "@/components/ui/progress";
import { Button } from "@/components/ui/button";
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
import { Input } from "@/components/ui/input";
import React, {useState, useEffect} from 'react';
import {Card, CardContent, CardHeader, CardTitle} from "@/components/ui/card";
import {Badge} from "@/components/ui/badge";
import {Progress} from "@/components/ui/progress";
import {Button} from "@/components/ui/button";
import {Tabs, TabsContent, TabsList, TabsTrigger} from "@/components/ui/tabs";
import {Input} from "@/components/ui/input";
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from "@/components/ui/select";
import { cn } from "@/lib/utils";
import {
Clock,
Search,
Edit,
ChevronRight,
CheckCircle,
AlertTriangle,
XCircle,
Loader2,
ServerCrash,
Server
import {cn} from "@/lib/utils";
import {
Clock,
Search,
Edit,
Package,
ChevronRight,
CheckCircle,
AlertTriangle,
XCircle,
Loader2,
ServerCrash,
Server
} from "lucide-react";
import { getEnvironmentList } from '@/pages/Deploy/Environment/List/service';
import { getDevelopmentLanguages } from '@/pages/Deploy/Application/List/service';
import { getDeploymentConfigPage } from '@/pages/Deploy/Deployment/List/service';
import type { Environment } from '@/pages/Deploy/Environment/List/types';
import type { DevelopmentLanguageType } from '@/pages/Deploy/Application/List/types';
import type { DeploymentConfig, DeploymentConfigQueryParams } from '@/pages/Deploy/Deployment/List/types';
import type { Page } from '@/types/base';
import {getEnvironmentList} from '@/pages/Deploy/Environment/List/service';
import {getDevelopmentLanguages} from '@/pages/Deploy/Application/List/service';
import {getDeploymentConfigPage} from '@/pages/Deploy/Deployment/List/service';
import type {Environment} from '@/pages/Deploy/Environment/List/types';
import type {DevelopmentLanguageType} from '@/pages/Deploy/Application/List/types';
import type {DeploymentConfig} from '@/pages/Deploy/Deployment/List/types';
import type {Page} from '@/types/base';
import type { JsonNode } from '@/types/common';
import DeploymentFormModal from './components/DeploymentFormModal';
type EnvironmentStatus = 'success' | 'warning' | 'error';
@ -46,10 +49,10 @@ interface EnhancedEnvironment extends Environment {
}
const EmptyState: React.FC<{ title: string; description: string; icon: React.ReactNode }> = ({
title,
description,
icon
}) => (
title,
description,
icon
}) => (
<div className="flex flex-col items-center justify-center p-8 text-center">
<div className="rounded-full bg-muted p-3 mb-4">
{icon}
@ -62,14 +65,14 @@ const EmptyState: React.FC<{ title: string; description: string; icon: React.Rea
const LoadingState = () => (
<div className="flex-1 p-8">
<div className="flex flex-col items-center justify-center min-h-[400px]">
<Loader2 className="h-8 w-8 animate-spin text-primary mb-4" />
<Loader2 className="h-8 w-8 animate-spin text-primary mb-4"/>
<p className="text-sm text-muted-foreground">...</p>
</div>
</div>
);
const Dashboard: React.FC = () => {
const [projectType, setProjectType] = useState("");
const [projectType, setProjectType] = useState("ALL");
const [status, setStatus] = useState("");
const [environments, setEnvironments] = useState<EnhancedEnvironment[]>([]);
const [loading, setLoading] = useState(true);
@ -77,6 +80,8 @@ const Dashboard: React.FC = () => {
const [deployConfigs, setDeployConfigs] = useState<DeploymentConfig[]>([]);
const [searchText, setSearchText] = useState("");
const [currentEnvId, setCurrentEnvId] = useState<number>();
const [deployModalOpen, setDeployModalOpen] = useState(false);
const [selectedConfig, setSelectedConfig] = useState<DeploymentConfig | null>(null);
// 获取环境和语言数据
useEffect(() => {
@ -124,24 +129,23 @@ const Dashboard: React.FC = () => {
useEffect(() => {
const fetchDeployConfigs = async () => {
if (!currentEnvId) return;
try {
const queryParams: DeploymentConfigQueryParams = {
const response = await getDeploymentConfigPage({
pageSize: 100,
pageNum: 1,
environmentId: currentEnvId,
workflowDefinitionId: 0
};
const response = await getDeploymentConfigPage(queryParams);
workflowDefinitionId: 0,
enabled: undefined
});
if (response) {
setDeployConfigs(response.content);
// 更新环境的项目数量
setEnvironments(prevEnvs =>
prevEnvs.map(env =>
env.id === currentEnvId
? { ...env, projectCount: response.totalElements }
setEnvironments(prevEnvs =>
prevEnvs.map(env =>
env.id === currentEnvId
? {...env, projectCount: response.totalElements}
: env
)
);
@ -156,27 +160,24 @@ const Dashboard: React.FC = () => {
const handleSearch = async () => {
if (!currentEnvId) return;
try {
const queryParams: DeploymentConfigQueryParams = {
const params: any = {
pageSize: 100,
pageNum: 1,
environmentId: currentEnvId,
workflowDefinitionId: 0,
enabled: status === 'active' ? true : status === 'paused' ? false : undefined
};
const response = await getDeploymentConfigPage(queryParams);
// 如果选择了具体语言(不是"所有"),添加到查询参数
if (projectType !== 'ALL') {
params.languageType = projectType;
}
const response = await getDeploymentConfigPage(params);
if (response) {
// 在前端过滤开发语言
const filteredConfigs = response.content.filter(config => {
if (projectType && config.languageType !== projectType) {
return false;
}
return true;
});
setDeployConfigs(filteredConfigs);
setDeployConfigs(response.content);
}
} catch (error) {
console.error('Failed to search deployment configs:', error);
@ -185,17 +186,16 @@ const Dashboard: React.FC = () => {
const handleReset = () => {
setSearchText("");
setProjectType("");
setProjectType("ALL");
setStatus("");
if (currentEnvId) {
const queryParams: DeploymentConfigQueryParams = {
getDeploymentConfigPage({
pageSize: 100,
pageNum: 1,
environmentId: currentEnvId,
workflowDefinitionId: 0
};
getDeploymentConfigPage(queryParams).then(response => {
workflowDefinitionId: 0,
enabled: undefined
}).then(response => {
if (response) {
setDeployConfigs(response.content);
}
@ -213,21 +213,21 @@ const Dashboard: React.FC = () => {
const getStatusIcon = (status: string) => {
switch (status) {
case 'success':
return <CheckCircle className="h-5 w-5 text-green-500" />;
return <CheckCircle className="h-5 w-5 text-green-500"/>;
case 'warning':
return <AlertTriangle className="h-5 w-5 text-yellow-500" />;
return <AlertTriangle className="h-5 w-5 text-yellow-500"/>;
case 'error':
return <XCircle className="h-5 w-5 text-red-500" />;
return <XCircle className="h-5 w-5 text-red-500"/>;
default:
return <Clock className="h-5 w-5 text-blue-500" />;
return <Clock className="h-5 w-5 text-blue-500"/>;
}
};
const getBuildStatusBadge = (enabled: boolean) => {
const config = enabled
? { className: "bg-green-100 text-green-800", text: "活跃" }
: { className: "bg-red-100 text-red-800", text: "暂停" };
? {className: "bg-green-100 text-green-800", text: "活跃"}
: {className: "bg-red-100 text-red-800", text: "暂停"};
return (
<Badge className={cn("rounded-full", config.className)}>
{config.text}
@ -235,8 +235,16 @@ const Dashboard: React.FC = () => {
);
};
const handleDeploy = (config: DeploymentConfig) => {
console.log('Deploy config:', config);
console.log('Workflow definition:', config.publishedWorkflowDefinition);
console.log('Form variables:', config.publishedWorkflowDefinition?.formVariables);
setSelectedConfig(config);
setDeployModalOpen(true);
};
if (loading) {
return <LoadingState />;
return <LoadingState/>;
}
const hasEnvironments = environments.length > 0;
@ -245,12 +253,12 @@ const Dashboard: React.FC = () => {
return (
<div className="flex-1 p-8">
<h2 className="text-2xl font-semibold mb-6"></h2>
{!hasEnvironments ? (
<Card>
<CardContent>
<EmptyState
icon={<ServerCrash className="h-8 w-8 text-muted-foreground" />}
icon={<ServerCrash className="h-8 w-8 text-muted-foreground"/>}
title="暂无环境数据"
description="当前系统中还没有配置任何环境。请先添加部署环境,然后开始使用部署功能。"
/>
@ -270,7 +278,7 @@ const Dashboard: React.FC = () => {
<p className="text-xs text-muted-foreground"></p>
<div className="mt-4 space-y-2">
<div className="flex items-center text-sm">
<Clock className="mr-2 h-4 w-4 text-muted-foreground" />
<Clock className="mr-2 h-4 w-4 text-muted-foreground"/>
: {env.lastDeployment}
</div>
<div className="space-y-1">
@ -278,21 +286,21 @@ const Dashboard: React.FC = () => {
<span>CPU</span>
<span>{env.cpu}%</span>
</div>
<Progress value={env.cpu} className="h-1" />
<Progress value={env.cpu} className="h-1"/>
</div>
<div className="space-y-1">
<div className="flex justify-between text-xs">
<span></span>
<span>{env.memory}%</span>
</div>
<Progress value={env.memory} className="h-1" />
<Progress value={env.memory} className="h-1"/>
</div>
<div className="space-y-1">
<div className="flex justify-between text-xs">
<span></span>
<span>{env.storage}%</span>
</div>
<Progress value={env.storage} className="h-1" />
<Progress value={env.storage} className="h-1"/>
</div>
</div>
</CardContent>
@ -301,8 +309,8 @@ const Dashboard: React.FC = () => {
</div>
<div className="bg-white rounded-lg shadow">
<Tabs
defaultValue={environments[0]?.envCode}
<Tabs
defaultValue={environments[0]?.envCode}
className="w-full"
onValueChange={handleTabChange}
>
@ -324,16 +332,17 @@ const Dashboard: React.FC = () => {
<TabsContent key={env.id} value={env.envCode} className="p-6">
<div className="mb-6">
<div className="grid grid-cols-1 md:grid-cols-4 gap-4">
<Input
placeholder="项目名称或代码"
<Input
placeholder="项目名称或代码"
value={searchText}
onChange={(e) => setSearchText(e.target.value)}
/>
<Select value={projectType} onValueChange={setProjectType}>
<SelectTrigger>
<SelectValue placeholder="开发语言" />
<SelectValue placeholder="开发语言"/>
</SelectTrigger>
<SelectContent>
<SelectItem value="ALL"></SelectItem>
{languages.map(lang => (
<SelectItem key={lang.code} value={lang.code}>
{lang.name}
@ -343,7 +352,7 @@ const Dashboard: React.FC = () => {
</Select>
<Select value={status} onValueChange={setStatus}>
<SelectTrigger>
<SelectValue placeholder="项目状态" />
<SelectValue placeholder="项目状态"/>
</SelectTrigger>
<SelectContent>
<SelectItem value="active"></SelectItem>
@ -352,7 +361,7 @@ const Dashboard: React.FC = () => {
</Select>
<div className="flex space-x-2">
<Button className="flex-1" onClick={handleSearch}>
<Search className="w-4 h-4 mr-2" />
<Search className="w-4 h-4 mr-2"/>
</Button>
<Button variant="outline" className="flex-1" onClick={handleReset}>
@ -366,7 +375,7 @@ const Dashboard: React.FC = () => {
<Card>
<CardContent>
<EmptyState
icon={<Server className="h-8 w-8 text-muted-foreground" />}
icon={<Server className="h-8 w-8 text-muted-foreground"/>}
title="暂无项目数据"
description="当前环境中还没有配置任何项目。请先创建项目,然后开始部署。"
/>
@ -403,12 +412,12 @@ const Dashboard: React.FC = () => {
</div>
</div>
<div className="flex justify-end space-x-2">
<Button variant="outline" size="sm">
<Edit className="h-4 w-4 mr-1" />
<Button variant="outline" size="sm" onClick={() => handleDeploy(config)}>
<Package className="h-4 w-4 mr-1"/>
</Button>
<Button variant="outline" size="sm">
<ChevronRight className="h-4 w-4" />
<ChevronRight className="h-4 w-4"/>
</Button>
</div>
@ -423,6 +432,21 @@ const Dashboard: React.FC = () => {
</div>
</>
)}
{selectedConfig && selectedConfig.publishedWorkflowDefinition && (
<>
{console.log('Selected config:', selectedConfig)}
{console.log('Workflow definition:', selectedConfig.publishedWorkflowDefinition)}
{console.log('Form variables:', selectedConfig.publishedWorkflowDefinition.formVariables)}
<DeploymentFormModal
open={deployModalOpen}
onClose={() => {
setDeployModalOpen(false);
setSelectedConfig(null);
}}
formSchema={selectedConfig.publishedWorkflowDefinition.formVariables}
/>
</>
)}
</div>
);
};