1
This commit is contained in:
parent
8e4a9bb695
commit
20da0c0bc1
@ -17,8 +17,7 @@ import { Badge } from "@/components/ui/badge";
|
||||
import { useToast } from "@/components/ui/use-toast";
|
||||
import { Separator } from "@/components/ui/separator";
|
||||
import type { JenkinsInstance, JenkinsView, SyncType } from './types';
|
||||
import { getJenkinsInstances, getJenkinsViews, syncJenkinsData } from './service';
|
||||
import { SyncStatus } from '@/pages/Deploy/External/types';
|
||||
import { getJenkinsInstances, getJenkinsViews, syncViews, syncJobs, syncBuilds } from './service';
|
||||
|
||||
const JenkinsManagerList: React.FC = () => {
|
||||
const [jenkinsList, setJenkinsList] = useState<JenkinsInstance[]>([]);
|
||||
@ -83,11 +82,19 @@ const JenkinsManagerList: React.FC = () => {
|
||||
if (!currentJenkinsId) return;
|
||||
setSyncing(prev => ({ ...prev, [type]: true }));
|
||||
try {
|
||||
await syncJenkinsData(currentJenkinsId, type);
|
||||
await loadJenkinsList();
|
||||
if (type === 'views') {
|
||||
await loadViews();
|
||||
switch (type) {
|
||||
case 'views':
|
||||
await syncViews(currentJenkinsId);
|
||||
await loadViews(); // 重新加载视图数据
|
||||
break;
|
||||
case 'jobs':
|
||||
await syncJobs(currentJenkinsId);
|
||||
break;
|
||||
case 'builds':
|
||||
await syncBuilds(currentJenkinsId);
|
||||
break;
|
||||
}
|
||||
await loadJenkinsList(); // 重新加载实例<E5AE9E><E4BE8B>据以更新同步时间
|
||||
toast({
|
||||
title: "同步成功",
|
||||
duration: 3000,
|
||||
@ -134,16 +141,12 @@ const JenkinsManagerList: React.FC = () => {
|
||||
onValueChange={handleJenkinsChange}
|
||||
>
|
||||
<SelectTrigger className="w-[300px]">
|
||||
<SelectValue placeholder="Select a Jenkins instance"/>
|
||||
<SelectValue placeholder="选择 Jenkins 实例"/>
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{jenkinsList.map(jenkins => (
|
||||
<SelectItem key={jenkins.id} value={String(jenkins.id)}>
|
||||
<div className="flex items-center gap-2">
|
||||
<Badge variant={jenkins.syncStatus === SyncStatus.SUCCESS ? "outline" : "secondary"}>
|
||||
{jenkins.name}
|
||||
</Badge>
|
||||
</div>
|
||||
{jenkins.name}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
|
||||
@ -1,10 +1,8 @@
|
||||
import request from '@/utils/request';
|
||||
import type { JenkinsInstance, JenkinsView, SyncType } from './types';
|
||||
import type { JenkinsInstance, JenkinsView } from './types';
|
||||
import { getExternalSystems } from '@/pages/Deploy/External/service';
|
||||
import { SystemType } from '@/pages/Deploy/External/types';
|
||||
|
||||
const BASE_URL = '/api/v1/jenkins-manager';
|
||||
|
||||
// 获取 Jenkins 实例列表
|
||||
export const getJenkinsInstances = () =>
|
||||
getExternalSystems({
|
||||
@ -61,6 +59,14 @@ export const getJenkinsViews = (jenkinsId: string) =>
|
||||
}
|
||||
]);
|
||||
|
||||
// 同步 Jenkins 数据
|
||||
export const syncJenkinsData = (jenkinsId: string, type: SyncType) =>
|
||||
request.post<void>(`${BASE_URL}/${jenkinsId}/sync/${type}`);
|
||||
// 同步视图
|
||||
export const syncViews = (externalSystemId: string) =>
|
||||
request.post<void>(`/api/v1/jenkins-manager/${externalSystemId}/sync-views`);
|
||||
|
||||
// 同步任务
|
||||
export const syncJobs = (externalSystemId: string) =>
|
||||
request.post<void>(`/api/v1/jenkins-manager/${externalSystemId}/sync-jobs`);
|
||||
|
||||
// 同步构建
|
||||
export const syncBuilds = (externalSystemId: string) =>
|
||||
request.post<void>(`/api/v1/jenkins-manager/${externalSystemId}/sync-builds`);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user