From 6bd3b4998ebf68d1407a7d46f72f7f46f0429955 Mon Sep 17 00:00:00 2001 From: Fu Diwei Date: Wed, 25 Dec 2024 20:57:09 +0800 Subject: [PATCH] feat(ui): new WorkflowNotifyNodeForm using antd --- internal/certificate/service.go | 4 +- internal/domain/setting.go | 8 +- .../workflow/node-processor/notify_node.go | 4 +- .../access/AccessEditFormKubernetesConfig.tsx | 2 +- .../access/AccessEditFormSSHConfig.tsx | 2 +- ui/src/components/workflow/NotifyForm.tsx | 174 ------------------ ui/src/components/workflow/PanelBody.tsx | 4 +- .../workflow/node/NotifyNodeForm.tsx | 118 ++++++++++++ .../workflow/node/StartNodeForm.tsx | 6 +- ui/src/i18n/locales/en/nls.workflow.json | 17 +- ui/src/i18n/locales/zh/nls.workflow.json | 17 +- ui/src/pages/settings/SettingsSSLProvider.tsx | 4 +- ui/src/pages/workflows/WorkflowDetail.tsx | 43 ++--- 13 files changed, 168 insertions(+), 235 deletions(-) delete mode 100644 ui/src/components/workflow/NotifyForm.tsx create mode 100644 ui/src/components/workflow/node/NotifyNodeForm.tsx diff --git a/internal/certificate/service.go b/internal/certificate/service.go index 2b29b9f5..08f485b2 100644 --- a/internal/certificate/service.go +++ b/internal/certificate/service.go @@ -73,8 +73,8 @@ func buildMsg(records []domain.Certificate) *domain.NotifyMessage { json.Unmarshal([]byte(setting.Content), &templates) if templates != nil && len(templates.NotifyTemplates) > 0 { - subject = templates.NotifyTemplates[0].Title - message = templates.NotifyTemplates[0].Content + subject = templates.NotifyTemplates[0].Subject + message = templates.NotifyTemplates[0].Message } } diff --git a/internal/domain/setting.go b/internal/domain/setting.go index da368566..813b6aa4 100644 --- a/internal/domain/setting.go +++ b/internal/domain/setting.go @@ -35,11 +35,11 @@ type NotifyTemplates struct { } type NotifyTemplate struct { - Title string `json:"title"` - Content string `json:"content"` + Subject string `json:"subject"` + Message string `json:"message"` } type NotifyMessage struct { - Subject string - Message string + Subject string `json:"subject"` + Message string `json:"message"` } diff --git a/internal/workflow/node-processor/notify_node.go b/internal/workflow/node-processor/notify_node.go index 7fd92ec0..7ef60a61 100644 --- a/internal/workflow/node-processor/notify_node.go +++ b/internal/workflow/node-processor/notify_node.go @@ -41,8 +41,8 @@ func (n *notifyNode) Run(ctx context.Context) error { return err } - if err := notify.SendToChannel(n.node.GetConfigString("title"), - n.node.GetConfigString("content"), + if err := notify.SendToChannel(n.node.GetConfigString("subject"), + n.node.GetConfigString("message"), n.node.GetConfigString("channel"), channelConfig, ); err != nil { diff --git a/ui/src/components/access/AccessEditFormKubernetesConfig.tsx b/ui/src/components/access/AccessEditFormKubernetesConfig.tsx index a00e734a..e96e6c2c 100644 --- a/ui/src/components/access/AccessEditFormKubernetesConfig.tsx +++ b/ui/src/components/access/AccessEditFormKubernetesConfig.tsx @@ -53,7 +53,7 @@ const AccessEditFormKubernetesConfig = ({ form, formName, disabled, model, onMod const handleKubeFileChange: UploadProps["onChange"] = async ({ file }) => { if (file && file.status !== "removed") { - formInst.setFieldValue("kubeConfig", (await readFileContent(file.originFileObj ?? (file as unknown as File))).trim()); + formInst.setFieldValue("kubeConfig", await readFileContent(file.originFileObj ?? (file as unknown as File))); setKubeFileList([file]); } else { formInst.setFieldValue("kubeConfig", ""); diff --git a/ui/src/components/access/AccessEditFormSSHConfig.tsx b/ui/src/components/access/AccessEditFormSSHConfig.tsx index ec0d5ba9..2b209204 100644 --- a/ui/src/components/access/AccessEditFormSSHConfig.tsx +++ b/ui/src/components/access/AccessEditFormSSHConfig.tsx @@ -88,7 +88,7 @@ const AccessEditFormSSHConfig = ({ form, formName, disabled, model, onModelChang const handleKeyFileChange: UploadProps["onChange"] = async ({ file }) => { if (file && file.status !== "removed") { - formInst.setFieldValue("key", (await readFileContent(file.originFileObj ?? (file as unknown as File))).trim()); + formInst.setFieldValue("key", await readFileContent(file.originFileObj ?? (file as unknown as File))); setKeyFileList([file]); } else { formInst.setFieldValue("key", ""); diff --git a/ui/src/components/workflow/NotifyForm.tsx b/ui/src/components/workflow/NotifyForm.tsx deleted file mode 100644 index 75d87643..00000000 --- a/ui/src/components/workflow/NotifyForm.tsx +++ /dev/null @@ -1,174 +0,0 @@ -import { WorkflowNode, WorkflowNodeConfig } from "@/domain/workflow"; -import { zodResolver } from "@hookform/resolvers/zod"; -import { useForm } from "react-hook-form"; -import { z } from "zod"; -import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage } from "../ui/form"; -import { Select, SelectContent, SelectGroup, SelectItem, SelectTrigger } from "../ui/select"; -import { Input } from "../ui/input"; -import { useWorkflowStore } from "@/stores/workflow"; -import { useZustandShallowSelector } from "@/hooks"; -import { usePanel } from "./PanelProvider"; -import { useTranslation } from "react-i18next"; -import { Button } from "../ui/button"; -import { useNotifyChannelStore } from "@/stores/notify"; -import { useEffect, useState } from "react"; -import { notifyChannelsMap } from "@/domain/settings"; -import { SelectValue } from "@radix-ui/react-select"; -import { Textarea } from "../ui/textarea"; -import { RefreshCw, Settings } from "lucide-react"; - -type NotifyFormProps = { - data: WorkflowNode; -}; - -type ChannelName = { - key: string; - label: string; -}; - -const i18nPrefix = "workflow.node.notify.form"; -const NotifyForm = ({ data }: NotifyFormProps) => { - const { updateNode } = useWorkflowStore(useZustandShallowSelector(["updateNode"])); - const { hidePanel } = usePanel(); - const { t } = useTranslation(); - const { channels: supportedChannels, fetchChannels } = useNotifyChannelStore(); - - const [channels, setChannels] = useState([]); - - useEffect(() => { - fetchChannels(); - }, [fetchChannels]); - - useEffect(() => { - const rs: ChannelName[] = []; - for (const channel of notifyChannelsMap.values()) { - if (supportedChannels[channel.type]?.enabled) { - rs.push({ key: channel.type, label: channel.name }); - } - } - setChannels(rs); - }, [supportedChannels]); - - const formSchema = z.object({ - channel: z.string(), - title: z.string().min(1), - content: z.string().min(1), - }); - - let config: WorkflowNodeConfig = { - channel: "", - title: "", - content: "", - }; - - if (data) config = data.config ?? config; - - const form = useForm>({ - resolver: zodResolver(formSchema), - defaultValues: { - channel: config.channel as string, - title: config.title as string, - content: config.content as string, - }, - }); - - const onSubmit = (config: z.infer) => { - updateNode({ ...data, config, validated: true }); - hidePanel(); - }; - - return ( - <> -
- { - e.stopPropagation(); - form.handleSubmit(onSubmit)(e); - }} - className="space-y-8 dark:text-stone-200" - > - ( - - -
-
{t(`${i18nPrefix}.channel.label`)}
- fetchChannels()} /> -
- -
{t(`${i18nPrefix}.settingChannel.label`)}
-
-
- - - - - -
- )} - /> - ( - - {t(`${i18nPrefix}.title.label`)} - - - - - - - )} - /> - - ( - - {t(`${i18nPrefix}.content.label`)} - -