This commit is contained in:
dengqichen 2025-01-10 16:02:58 +08:00
parent 1aeafd6fc8
commit 7fa1011ffd

View File

@ -105,6 +105,7 @@ const ApplicationModal: React.FC<ApplicationModalProps> = ({
useEffect(() => { useEffect(() => {
if (initialValues) { if (initialValues) {
// 设置表单初始值
form.reset({ form.reset({
appCode: initialValues.appCode, appCode: initialValues.appCode,
appName: initialValues.appName, appName: initialValues.appName,
@ -112,17 +113,23 @@ const ApplicationModal: React.FC<ApplicationModalProps> = ({
language: initialValues.language, language: initialValues.language,
enabled: initialValues.enabled, enabled: initialValues.enabled,
sort: initialValues.sort, sort: initialValues.sort,
projectGroupId: initialValues.projectGroupId,
externalSystemId: initialValues.externalSystemId, externalSystemId: initialValues.externalSystemId,
repoGroupId: initialValues.repoGroupId, repoGroupId: initialValues.repoGroupId,
repoProjectId: initialValues.repoProjectId, repoProjectId: initialValues.repoProjectId
projectGroupId: initialValues.projectGroupId,
}); });
const externalSystem = externalSystems.find(system => system.id === initialValues.externalSystemId);
if (externalSystem) { // 如果有外部系统ID加载仓库组
setSelectedExternalSystem(externalSystem); if (initialValues.externalSystemId) {
fetchRepositoryGroups(initialValues.externalSystemId);
}
// 如果有仓库组ID加载仓库项目
if (initialValues.repoGroupId) {
fetchRepositoryProjects(initialValues.repoGroupId);
} }
} }
}, [initialValues, form, externalSystems]); }, [initialValues]);
// 当选择外部系统时,获取对应的仓库组列表 // 当选择外部系统时,获取对应的仓库组列表
const handleExternalSystemChange = (externalSystemId: number) => { const handleExternalSystemChange = (externalSystemId: number) => {
@ -412,7 +419,7 @@ const ApplicationModal: React.FC<ApplicationModalProps> = ({
> >
{field.value {field.value
? repositoryProjects.find( ? repositoryProjects.find(
(project) => project.projectId === field.value (project) => project.id === field.value
)?.name )?.name
: !form.watch('repoGroupId') : !form.watch('repoGroupId')
? "请先选择代码仓库组" ? "请先选择代码仓库组"
@ -441,13 +448,13 @@ const ApplicationModal: React.FC<ApplicationModalProps> = ({
) : ( ) : (
filteredProjects.map((project) => ( filteredProjects.map((project) => (
<div <div
key={project.projectId} key={project.id}
className={cn( className={cn(
"relative flex cursor-pointer select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none hover:bg-accent hover:text-accent-foreground", "relative flex cursor-pointer select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none hover:bg-accent hover:text-accent-foreground",
project.projectId === field.value && "bg-accent text-accent-foreground" project.id === field.value && "bg-accent text-accent-foreground"
)} )}
onClick={() => { onClick={() => {
form.setValue("repoProjectId", project.projectId); form.setValue("repoProjectId", project.id);
setSearchValue(""); setSearchValue("");
setOpen(false); setOpen(false);
}} }}
@ -459,7 +466,7 @@ const ApplicationModal: React.FC<ApplicationModalProps> = ({
}} }}
> >
{project.name} {project.name}
{project.projectId === field.value && ( {project.id === field.value && (
<Check className="ml-auto h-4 w-4" /> <Check className="ml-auto h-4 w-4" />
)} )}
</div> </div>