This commit is contained in:
dengqichen 2025-01-10 15:04:20 +08:00
parent 0958c32310
commit 931665f6e1
2 changed files with 25 additions and 59 deletions

View File

@ -69,13 +69,13 @@ const ApplicationModal: React.FC<ApplicationModalProps> = ({
appCode: "", appCode: "",
appName: "", appName: "",
appDesc: "", appDesc: "",
repoUrl: "", language: DevelopmentLanguageTypeEnum.JAVA,
language: undefined,
enabled: true, enabled: true,
sort: 0, sort: 0,
gitInstanceId: undefined, gitInstanceId: undefined,
repositoryGroupId: undefined, repoGroupId: undefined,
repositoryProjectId: undefined, repoProjectId: undefined,
projectGroupId: undefined,
}, },
}); });
@ -109,13 +109,13 @@ const ApplicationModal: React.FC<ApplicationModalProps> = ({
appCode: initialValues.appCode, appCode: initialValues.appCode,
appName: initialValues.appName, appName: initialValues.appName,
appDesc: initialValues.appDesc || "", appDesc: initialValues.appDesc || "",
repoUrl: initialValues.repoUrl,
language: initialValues.language, language: initialValues.language,
enabled: initialValues.enabled, enabled: initialValues.enabled,
sort: initialValues.sort, sort: initialValues.sort,
gitInstanceId: initialValues.gitInstanceId, gitInstanceId: initialValues.gitInstanceId,
repositoryGroupId: initialValues.repositoryGroupId, repoGroupId: initialValues.repoGroupId,
repositoryProjectId: initialValues.repositoryProjectId, repoProjectId: initialValues.repoProjectId,
projectGroupId: initialValues.projectGroupId,
}); });
const gitInstance = gitInstances.find(instance => instance.id === initialValues.gitInstanceId); const gitInstance = gitInstances.find(instance => instance.id === initialValues.gitInstanceId);
if (gitInstance) { if (gitInstance) {
@ -126,8 +126,8 @@ const ApplicationModal: React.FC<ApplicationModalProps> = ({
// 当选择Git实例时获取对应的仓库组列表 // 当选择Git实例时获取对应的仓库组列表
const handleGitInstanceChange = (gitInstanceId: number) => { const handleGitInstanceChange = (gitInstanceId: number) => {
form.setValue('repositoryGroupId', undefined); form.setValue('repoGroupId', undefined);
form.setValue('repositoryProjectId', undefined); form.setValue('repoProjectId', undefined);
setRepositoryProjects([]); setRepositoryProjects([]);
fetchRepositoryGroups(gitInstanceId); fetchRepositoryGroups(gitInstanceId);
}; };
@ -147,34 +147,20 @@ const ApplicationModal: React.FC<ApplicationModalProps> = ({
if (isEdit) { if (isEdit) {
await updateApplication({ await updateApplication({
...values, ...values,
id: initialValues.id, id: initialValues!.id,
projectGroupId,
}); });
} else { } else {
await createApplication({ await createApplication(values);
...values,
projectGroupId,
});
} }
toast({ onSuccess?.();
title: `${isEdit ? '更新' : '创建'}成功`, } catch (e) {
duration: 3000, console.error(e);
});
form.reset();
onSuccess();
} catch (error) {
toast({
variant: "destructive",
title: `${isEdit ? '更新' : '创建'}失败`,
description: error instanceof Error ? error.message : undefined,
duration: 3000,
});
} }
}; };
return ( return (
<Dialog open={open} onOpenChange={(open) => !open && onCancel()}> <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"> <DialogHeader className="pb-4">
<DialogTitle>{isEdit ? '编辑' : '新建'}</DialogTitle> <DialogTitle>{isEdit ? '编辑' : '新建'}</DialogTitle>
</DialogHeader> </DialogHeader>
@ -281,7 +267,7 @@ const ApplicationModal: React.FC<ApplicationModalProps> = ({
<FormField <FormField
control={form.control} control={form.control}
name="repositoryGroupId" name="repoGroupId"
render={({field}) => { render={({field}) => {
const [searchValue, setSearchValue] = React.useState(""); const [searchValue, setSearchValue] = React.useState("");
const [open, setOpen] = React.useState(false); const [open, setOpen] = React.useState(false);
@ -341,8 +327,8 @@ const ApplicationModal: React.FC<ApplicationModalProps> = ({
group.id === field.value && "bg-accent text-accent-foreground" group.id === field.value && "bg-accent text-accent-foreground"
)} )}
onClick={() => { onClick={() => {
form.setValue("repositoryGroupId", group.id); form.setValue("repoGroupId", group.id);
form.setValue("repositoryProjectId", undefined); form.setValue("repoProjectId", undefined);
setRepositoryProjects([]); setRepositoryProjects([]);
fetchRepositoryProjects(group.id); fetchRepositoryProjects(group.id);
setSearchValue(""); setSearchValue("");
@ -380,7 +366,7 @@ const ApplicationModal: React.FC<ApplicationModalProps> = ({
<FormField <FormField
control={form.control} control={form.control}
name="repositoryProjectId" name="repoProjectId"
render={({field}) => { render={({field}) => {
const [searchValue, setSearchValue] = React.useState(""); const [searchValue, setSearchValue] = React.useState("");
const [open, setOpen] = React.useState(false); const [open, setOpen] = React.useState(false);
@ -397,7 +383,7 @@ const ApplicationModal: React.FC<ApplicationModalProps> = ({
<Button <Button
variant="outline" variant="outline"
role="combobox" role="combobox"
disabled={!form.watch('repositoryGroupId')} disabled={!form.watch('repoGroupId')}
className={cn( className={cn(
"w-full justify-between", "w-full justify-between",
!field.value && "text-muted-foreground" !field.value && "text-muted-foreground"
@ -407,7 +393,7 @@ const ApplicationModal: React.FC<ApplicationModalProps> = ({
? repositoryProjects.find( ? repositoryProjects.find(
(project) => project.projectId === field.value (project) => project.projectId === field.value
)?.name )?.name
: !form.watch('repositoryGroupId') : !form.watch('repoGroupId')
? "请先选择代码仓库组" ? "请先选择代码仓库组"
: "请选择项目"} : "请选择项目"}
<ChevronDown className="ml-2 h-4 w-4 shrink-0 opacity-50" /> <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" project.projectId === field.value && "bg-accent text-accent-foreground"
)} )}
onClick={() => { onClick={() => {
form.setValue("repositoryProjectId", project.projectId); form.setValue("repoProjectId", project.projectId);
setSearchValue(""); setSearchValue("");
setOpen(false); setOpen(false);
}} }}
@ -469,27 +455,6 @@ const ApplicationModal: React.FC<ApplicationModalProps> = ({
}} }}
/> />
</div> </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 <FormField
control={form.control} control={form.control}
name="appDesc" name="appDesc"

View File

@ -13,8 +13,9 @@ export const applicationFormSchema = z.object({
appName: z.string().min(1, "请输入应用名称").max(50, "应用名称不能超过50个字符"), appName: z.string().min(1, "请输入应用名称").max(50, "应用名称不能超过50个字符"),
appDesc: z.string().max(200, "应用描述不能超过200个字符").optional(), appDesc: z.string().max(200, "应用描述不能超过200个字符").optional(),
gitInstanceId: z.number().min(1, "请选择Git实例"), gitInstanceId: z.number().min(1, "请选择Git实例"),
repositoryGroupId: z.number().min(1, "请选择代码仓库组"), projectGroupId: z.number().min(1, "请选择项目组"),
repoUrl: z.string().url("请输入有效的URL地址").min(1, "请输入仓库地址"), repoGroupId: z.number().min(1, "请选择代码仓库组"),
repoProjectId: z.number().min(1, "请选择代码仓库项目"),
language: z.nativeEnum(DevelopmentLanguageTypeEnum, { language: z.nativeEnum(DevelopmentLanguageTypeEnum, {
required_error: "请选择开发语言", required_error: "请选择开发语言",
}), }),