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