From 85d7e573ad2156ceb1bafceea9dcd3d0292e71e4 Mon Sep 17 00:00:00 2001 From: dengqichen Date: Fri, 10 Jan 2025 14:07:47 +0800 Subject: [PATCH] 1 --- .../List/components/ApplicationModal.tsx | 132 ++++++++++++++---- .../pages/Deploy/Application/List/service.ts | 9 +- .../pages/Deploy/Application/List/types.ts | 15 ++ 3 files changed, 131 insertions(+), 25 deletions(-) diff --git a/frontend/src/pages/Deploy/Application/List/components/ApplicationModal.tsx b/frontend/src/pages/Deploy/Application/List/components/ApplicationModal.tsx index 71f119eb..0182a6ed 100644 --- a/frontend/src/pages/Deploy/Application/List/components/ApplicationModal.tsx +++ b/frontend/src/pages/Deploy/Application/List/components/ApplicationModal.tsx @@ -1,7 +1,7 @@ import React, {useEffect, useState} from 'react'; -import type {Application, RepositoryGroup} from '../types'; +import type {Application, RepositoryGroup, RepositoryProject} from '../types'; import {DevelopmentLanguageTypeEnum} from '../types'; -import {createApplication, updateApplication, getRepositoryGroupList} from '../service'; +import {createApplication, updateApplication, getRepositoryGroupList, getRepositoryProjects} from '../service'; import type {ExternalSystemResponse} from '@/pages/Deploy/External/types'; import {SystemType} from '@/pages/Deploy/External/types'; import {getExternalSystems} from '@/pages/Deploy/External/service'; @@ -58,6 +58,7 @@ const ApplicationModal: React.FC = ({ }) => { const [gitInstances, setGitInstances] = useState([]); const [repositoryGroups, setRepositoryGroups] = useState([]); + const [repositoryProjects, setRepositoryProjects] = useState([]); const {toast} = useToast(); const isEdit = !!initialValues?.id; const [selectedGitInstance, setSelectedGitInstance] = useState(); @@ -74,6 +75,7 @@ const ApplicationModal: React.FC = ({ sort: 0, gitInstanceId: undefined, repositoryGroupId: undefined, + repositoryProjectId: undefined, }, }); @@ -113,6 +115,7 @@ const ApplicationModal: React.FC = ({ sort: initialValues.sort, gitInstanceId: initialValues.gitInstanceId, repositoryGroupId: initialValues.repositoryGroupId, + repositoryProjectId: initialValues.repositoryProjectId, }); const gitInstance = gitInstances.find(instance => instance.id === initialValues.gitInstanceId); if (gitInstance) { @@ -122,20 +125,21 @@ const ApplicationModal: React.FC = ({ }, [initialValues, form, gitInstances]); // 当选择Git实例时,获取对应的仓库组列表 - const handleGitInstanceChange = async (gitInstanceId: number) => { - try { - const data = await getRepositoryGroupList(gitInstanceId); - setRepositoryGroups(data); - // 清空已选择的仓库组 - form.setValue('repositoryGroupId', undefined); - } catch (error) { - console.error('Failed to fetch repository groups:', error); - toast({ - title: "错误", - description: "获取仓库组列表失败", - variant: "destructive", - }); - } + const handleGitInstanceChange = (gitInstanceId: number) => { + form.setValue('repositoryGroupId', undefined); + form.setValue('repositoryProjectId', undefined); + setRepositoryProjects([]); + fetchRepositoryGroups(gitInstanceId); + }; + + const fetchRepositoryGroups = async (externalSystemId: number) => { + const response = await getRepositoryGroupList(externalSystemId); + setRepositoryGroups(response || []); + }; + + const fetchRepositoryProjects = async (groupId: number) => { + const response = await getRepositoryProjects(groupId); + setRepositoryProjects(response || []); }; const handleSubmit = async (values: ApplicationFormValues) => { @@ -241,7 +245,7 @@ const ApplicationModal: React.FC = ({ )} /> -
+
= ({ setSearchValue(e.target.value)} + /> +
+ + {filteredProjects.length === 0 ? ( +
+ 未找到项目 +
+ ) : ( + filteredProjects.map((project) => ( +
{ + form.setValue("repositoryProjectId", project.projectId); + setSearchValue(""); + setOpen(false); + }} + > + {project.name} + {project.projectId === field.value && ( + + )} +
+ )) + )} +
+ + + + + ); + }} + />
@@ -43,3 +44,9 @@ export const getRepositoryGroupList = (externalSystemId: number) => request.get(`${REPOSITORY_GROUP_URL}/list`, { params: { externalSystemId }, }); + +// 获取项目列表 +export const getRepositoryProjects = (groupId: number) => + request.get(`${REPOSITORY_PROJECT_URL}/list`, { + params: { groupId }, + }); diff --git a/frontend/src/pages/Deploy/Application/List/types.ts b/frontend/src/pages/Deploy/Application/List/types.ts index f2a5e759..16998698 100644 --- a/frontend/src/pages/Deploy/Application/List/types.ts +++ b/frontend/src/pages/Deploy/Application/List/types.ts @@ -64,3 +64,18 @@ export interface RepositoryGroup { sort?: number; enabled?: boolean; } + +export interface RepositoryProject { + name: string; + path: string; + description: string; + visibility: string; + groupId: number; + isDefaultBranch: string; + webUrl: string; + sshUrl: string; + httpUrl: string; + lastActivityAt: string; + externalSystemId: number; + projectId: number; +}