1
This commit is contained in:
parent
a4a1e2d808
commit
635959ced8
@ -56,12 +56,12 @@ const ApplicationModal: React.FC<ApplicationModalProps> = ({
|
|||||||
initialValues,
|
initialValues,
|
||||||
projectGroupId,
|
projectGroupId,
|
||||||
}) => {
|
}) => {
|
||||||
const [gitInstances, setGitInstances] = useState<ExternalSystemResponse[]>([]);
|
const [externalSystems, setExternalSystems] = useState<ExternalSystemResponse[]>([]);
|
||||||
const [repositoryGroups, setRepositoryGroups] = useState<RepositoryGroup[]>([]);
|
const [repositoryGroups, setRepositoryGroups] = useState<RepositoryGroup[]>([]);
|
||||||
const [repositoryProjects, setRepositoryProjects] = useState<RepositoryProject[]>([]);
|
const [repositoryProjects, setRepositoryProjects] = useState<RepositoryProject[]>([]);
|
||||||
const {toast} = useToast();
|
const {toast} = useToast();
|
||||||
const isEdit = !!initialValues?.id;
|
const isEdit = !!initialValues?.id;
|
||||||
const [selectedGitInstance, setSelectedGitInstance] = useState<ExternalSystemResponse>();
|
const [selectedExternalSystem, setSelectedExternalSystem] = useState<ExternalSystemResponse>();
|
||||||
|
|
||||||
const form = useForm<ApplicationFormValues>({
|
const form = useForm<ApplicationFormValues>({
|
||||||
resolver: zodResolver(applicationFormSchema),
|
resolver: zodResolver(applicationFormSchema),
|
||||||
@ -79,20 +79,20 @@ const ApplicationModal: React.FC<ApplicationModalProps> = ({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
// 加载Git实例列表
|
// 加载外部系统列表
|
||||||
const loadGitInstances = async () => {
|
const loadExternalSystems = async () => {
|
||||||
try {
|
try {
|
||||||
const response = await getExternalSystems({
|
const response = await getExternalSystems({
|
||||||
type: SystemType.GIT,
|
type: SystemType.GIT,
|
||||||
enabled: true,
|
enabled: true,
|
||||||
});
|
});
|
||||||
if (response?.content) {
|
if (response?.content) {
|
||||||
setGitInstances(response.content);
|
setExternalSystems(response.content);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
toast({
|
toast({
|
||||||
variant: "destructive",
|
variant: "destructive",
|
||||||
title: "加载Git实例失败",
|
title: "加载外部系统失败",
|
||||||
description: error instanceof Error ? error.message : undefined,
|
description: error instanceof Error ? error.message : undefined,
|
||||||
duration: 3000,
|
duration: 3000,
|
||||||
});
|
});
|
||||||
@ -100,7 +100,7 @@ const ApplicationModal: React.FC<ApplicationModalProps> = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
loadGitInstances();
|
loadExternalSystems();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -117,15 +117,15 @@ const ApplicationModal: React.FC<ApplicationModalProps> = ({
|
|||||||
repoProjectId: initialValues.repoProjectId,
|
repoProjectId: initialValues.repoProjectId,
|
||||||
projectGroupId: initialValues.projectGroupId,
|
projectGroupId: initialValues.projectGroupId,
|
||||||
});
|
});
|
||||||
const gitInstance = gitInstances.find(instance => instance.id === initialValues.externalSystemId);
|
const externalSystem = externalSystems.find(system => system.id === initialValues.externalSystemId);
|
||||||
if (gitInstance) {
|
if (externalSystem) {
|
||||||
setSelectedGitInstance(gitInstance);
|
setSelectedExternalSystem(externalSystem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [initialValues, form, gitInstances]);
|
}, [initialValues, form, externalSystems]);
|
||||||
|
|
||||||
// 当选择Git实例时,获取对应的仓库组列表
|
// 当选择外部系统时,获取对应的仓库组列表
|
||||||
const handleGitInstanceChange = (externalSystemId: number) => {
|
const handleExternalSystemChange = (externalSystemId: number) => {
|
||||||
form.setValue('repoGroupId', undefined);
|
form.setValue('repoGroupId', undefined);
|
||||||
form.setValue('repoProjectId', undefined);
|
form.setValue('repoProjectId', undefined);
|
||||||
setRepositoryProjects([]);
|
setRepositoryProjects([]);
|
||||||
@ -150,12 +150,29 @@ const ApplicationModal: React.FC<ApplicationModalProps> = ({
|
|||||||
...values,
|
...values,
|
||||||
id: initialValues!.id,
|
id: initialValues!.id,
|
||||||
});
|
});
|
||||||
|
toast({
|
||||||
|
title: "更新成功",
|
||||||
|
description: `应用 ${values.appName} 已更新`,
|
||||||
|
duration: 3000,
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
await createApplication(values);
|
await createApplication(values);
|
||||||
|
toast({
|
||||||
|
title: "创建成功",
|
||||||
|
description: `应用 ${values.appName} 已创建`,
|
||||||
|
duration: 3000,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
onSuccess?.();
|
onSuccess?.();
|
||||||
|
onCancel();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
|
toast({
|
||||||
|
variant: "destructive",
|
||||||
|
title: isEdit ? "更新失败" : "创建失败",
|
||||||
|
description: e instanceof Error ? e.message : "操作失败,请重试",
|
||||||
|
duration: 3000,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -240,26 +257,26 @@ const ApplicationModal: React.FC<ApplicationModalProps> = ({
|
|||||||
name="externalSystemId"
|
name="externalSystemId"
|
||||||
render={({field}) => (
|
render={({field}) => (
|
||||||
<FormItem>
|
<FormItem>
|
||||||
<FormLabel>Git实例</FormLabel>
|
<FormLabel>外部系统</FormLabel>
|
||||||
<Select
|
<Select
|
||||||
onValueChange={(value) => {
|
onValueChange={(value) => {
|
||||||
field.onChange(Number(value));
|
field.onChange(Number(value));
|
||||||
handleGitInstanceChange(Number(value));
|
handleExternalSystemChange(Number(value));
|
||||||
}}
|
}}
|
||||||
value={field.value?.toString()}
|
value={field.value?.toString()}
|
||||||
>
|
>
|
||||||
<FormControl>
|
<FormControl>
|
||||||
<SelectTrigger>
|
<SelectTrigger>
|
||||||
<SelectValue placeholder="请选择Git实例"/>
|
<SelectValue placeholder="请选择外部系统"/>
|
||||||
</SelectTrigger>
|
</SelectTrigger>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
<SelectContent>
|
<SelectContent>
|
||||||
{gitInstances.map((instance) => (
|
{externalSystems.map((system) => (
|
||||||
<SelectItem
|
<SelectItem
|
||||||
key={instance.id}
|
key={system.id}
|
||||||
value={instance.id.toString()}
|
value={system.id.toString()}
|
||||||
>
|
>
|
||||||
{instance.name}
|
{system.name}
|
||||||
</SelectItem>
|
</SelectItem>
|
||||||
))}
|
))}
|
||||||
</SelectContent>
|
</SelectContent>
|
||||||
@ -299,7 +316,7 @@ const ApplicationModal: React.FC<ApplicationModalProps> = ({
|
|||||||
(group) => group.id === field.value
|
(group) => group.id === field.value
|
||||||
)?.fullName || "请选择代码仓库组"
|
)?.fullName || "请选择代码仓库组"
|
||||||
: !form.watch('externalSystemId')
|
: !form.watch('externalSystemId')
|
||||||
? "请先选择Git实例"
|
? "请先选择外部系统"
|
||||||
: "请选择代码仓库组"}
|
: "请选择代码仓库组"}
|
||||||
<ChevronDown className="ml-2 h-4 w-4 shrink-0 opacity-50" />
|
<ChevronDown className="ml-2 h-4 w-4 shrink-0 opacity-50" />
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user