1
This commit is contained in:
parent
0958c32310
commit
931665f6e1
@ -69,13 +69,13 @@ const ApplicationModal: React.FC<ApplicationModalProps> = ({
|
||||
appCode: "",
|
||||
appName: "",
|
||||
appDesc: "",
|
||||
repoUrl: "",
|
||||
language: undefined,
|
||||
language: DevelopmentLanguageTypeEnum.JAVA,
|
||||
enabled: true,
|
||||
sort: 0,
|
||||
gitInstanceId: undefined,
|
||||
repositoryGroupId: undefined,
|
||||
repositoryProjectId: undefined,
|
||||
repoGroupId: undefined,
|
||||
repoProjectId: undefined,
|
||||
projectGroupId: undefined,
|
||||
},
|
||||
});
|
||||
|
||||
@ -109,13 +109,13 @@ const ApplicationModal: React.FC<ApplicationModalProps> = ({
|
||||
appCode: initialValues.appCode,
|
||||
appName: initialValues.appName,
|
||||
appDesc: initialValues.appDesc || "",
|
||||
repoUrl: initialValues.repoUrl,
|
||||
language: initialValues.language,
|
||||
enabled: initialValues.enabled,
|
||||
sort: initialValues.sort,
|
||||
gitInstanceId: initialValues.gitInstanceId,
|
||||
repositoryGroupId: initialValues.repositoryGroupId,
|
||||
repositoryProjectId: initialValues.repositoryProjectId,
|
||||
repoGroupId: initialValues.repoGroupId,
|
||||
repoProjectId: initialValues.repoProjectId,
|
||||
projectGroupId: initialValues.projectGroupId,
|
||||
});
|
||||
const gitInstance = gitInstances.find(instance => instance.id === initialValues.gitInstanceId);
|
||||
if (gitInstance) {
|
||||
@ -126,8 +126,8 @@ const ApplicationModal: React.FC<ApplicationModalProps> = ({
|
||||
|
||||
// 当选择Git实例时,获取对应的仓库组列表
|
||||
const handleGitInstanceChange = (gitInstanceId: number) => {
|
||||
form.setValue('repositoryGroupId', undefined);
|
||||
form.setValue('repositoryProjectId', undefined);
|
||||
form.setValue('repoGroupId', undefined);
|
||||
form.setValue('repoProjectId', undefined);
|
||||
setRepositoryProjects([]);
|
||||
fetchRepositoryGroups(gitInstanceId);
|
||||
};
|
||||
@ -147,34 +147,20 @@ const ApplicationModal: React.FC<ApplicationModalProps> = ({
|
||||
if (isEdit) {
|
||||
await updateApplication({
|
||||
...values,
|
||||
id: initialValues.id,
|
||||
projectGroupId,
|
||||
id: initialValues!.id,
|
||||
});
|
||||
} else {
|
||||
await createApplication({
|
||||
...values,
|
||||
projectGroupId,
|
||||
});
|
||||
await createApplication(values);
|
||||
}
|
||||
toast({
|
||||
title: `${isEdit ? '更新' : '创建'}成功`,
|
||||
duration: 3000,
|
||||
});
|
||||
form.reset();
|
||||
onSuccess();
|
||||
} catch (error) {
|
||||
toast({
|
||||
variant: "destructive",
|
||||
title: `${isEdit ? '更新' : '创建'}失败`,
|
||||
description: error instanceof Error ? error.message : undefined,
|
||||
duration: 3000,
|
||||
});
|
||||
onSuccess?.();
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={(open) => !open && onCancel()}>
|
||||
<DialogContent className="max-w-[800px] h-[90vh]">
|
||||
<DialogContent className="max-w-[800px] h-[75vh]">
|
||||
<DialogHeader className="pb-4">
|
||||
<DialogTitle>{isEdit ? '编辑' : '新建'}应用</DialogTitle>
|
||||
</DialogHeader>
|
||||
@ -281,7 +267,7 @@ const ApplicationModal: React.FC<ApplicationModalProps> = ({
|
||||
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="repositoryGroupId"
|
||||
name="repoGroupId"
|
||||
render={({field}) => {
|
||||
const [searchValue, setSearchValue] = React.useState("");
|
||||
const [open, setOpen] = React.useState(false);
|
||||
@ -341,8 +327,8 @@ const ApplicationModal: React.FC<ApplicationModalProps> = ({
|
||||
group.id === field.value && "bg-accent text-accent-foreground"
|
||||
)}
|
||||
onClick={() => {
|
||||
form.setValue("repositoryGroupId", group.id);
|
||||
form.setValue("repositoryProjectId", undefined);
|
||||
form.setValue("repoGroupId", group.id);
|
||||
form.setValue("repoProjectId", undefined);
|
||||
setRepositoryProjects([]);
|
||||
fetchRepositoryProjects(group.id);
|
||||
setSearchValue("");
|
||||
@ -380,7 +366,7 @@ const ApplicationModal: React.FC<ApplicationModalProps> = ({
|
||||
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="repositoryProjectId"
|
||||
name="repoProjectId"
|
||||
render={({field}) => {
|
||||
const [searchValue, setSearchValue] = React.useState("");
|
||||
const [open, setOpen] = React.useState(false);
|
||||
@ -397,7 +383,7 @@ const ApplicationModal: React.FC<ApplicationModalProps> = ({
|
||||
<Button
|
||||
variant="outline"
|
||||
role="combobox"
|
||||
disabled={!form.watch('repositoryGroupId')}
|
||||
disabled={!form.watch('repoGroupId')}
|
||||
className={cn(
|
||||
"w-full justify-between",
|
||||
!field.value && "text-muted-foreground"
|
||||
@ -407,7 +393,7 @@ const ApplicationModal: React.FC<ApplicationModalProps> = ({
|
||||
? repositoryProjects.find(
|
||||
(project) => project.projectId === field.value
|
||||
)?.name
|
||||
: !form.watch('repositoryGroupId')
|
||||
: !form.watch('repoGroupId')
|
||||
? "请先选择代码仓库组"
|
||||
: "请选择项目"}
|
||||
<ChevronDown className="ml-2 h-4 w-4 shrink-0 opacity-50" />
|
||||
@ -440,7 +426,7 @@ const ApplicationModal: React.FC<ApplicationModalProps> = ({
|
||||
project.projectId === field.value && "bg-accent text-accent-foreground"
|
||||
)}
|
||||
onClick={() => {
|
||||
form.setValue("repositoryProjectId", project.projectId);
|
||||
form.setValue("repoProjectId", project.projectId);
|
||||
setSearchValue("");
|
||||
setOpen(false);
|
||||
}}
|
||||
@ -469,27 +455,6 @@ const ApplicationModal: React.FC<ApplicationModalProps> = ({
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="repoUrl"
|
||||
render={({field}) => (
|
||||
<FormItem>
|
||||
<FormLabel>仓库地址</FormLabel>
|
||||
<FormControl>
|
||||
<div className="flex gap-2">
|
||||
<Input
|
||||
{...field}
|
||||
placeholder={selectedGitInstance ? `例如: ${selectedGitInstance.url}/your-project.git` : "请先选择Git实例"}
|
||||
disabled={!selectedGitInstance}
|
||||
/>
|
||||
</div>
|
||||
</FormControl>
|
||||
<FormMessage/>
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="appDesc"
|
||||
|
||||
@ -13,8 +13,9 @@ export const applicationFormSchema = z.object({
|
||||
appName: z.string().min(1, "请输入应用名称").max(50, "应用名称不能超过50个字符"),
|
||||
appDesc: z.string().max(200, "应用描述不能超过200个字符").optional(),
|
||||
gitInstanceId: z.number().min(1, "请选择Git实例"),
|
||||
repositoryGroupId: z.number().min(1, "请选择代码仓库组"),
|
||||
repoUrl: z.string().url("请输入有效的URL地址").min(1, "请输入仓库地址"),
|
||||
projectGroupId: z.number().min(1, "请选择项目组"),
|
||||
repoGroupId: z.number().min(1, "请选择代码仓库组"),
|
||||
repoProjectId: z.number().min(1, "请选择代码仓库项目"),
|
||||
language: z.nativeEnum(DevelopmentLanguageTypeEnum, {
|
||||
required_error: "请选择开发语言",
|
||||
}),
|
||||
|
||||
Loading…
Reference in New Issue
Block a user