feat: support template variables in webhook deployment

This commit is contained in:
Fu Diwei
2025-01-03 23:06:02 +08:00
parent e695c8ee5c
commit 90058b2dae
10 changed files with 97 additions and 57 deletions

View File

@@ -1,5 +1,5 @@
import { useTranslation } from "react-i18next";
import { Form, Input } from "antd";
import { Alert, Button, Form, Input } from "antd";
import { createSchemaFieldRule } from "antd-zod";
import { z } from "zod";
@@ -14,11 +14,23 @@ const DeployNodeFormWebhookFields = () => {
} catch {
return false;
}
}, t("workflow_node.deploy.form.webhook_data.placeholder")),
}, t("workflow_node.deploy.form.webhook_data.errmsg.json_invalid")),
});
const formRule = createSchemaFieldRule(formSchema);
const formInst = Form.useFormInstance();
const initialValues: Partial<z.infer<typeof formSchema>> = {
webhookData: JSON.stringify(
{
name: "${DOMAINS}",
cert: "${CERTIFICATE}",
privkey: "${PRIVATE_KEY}",
},
null,
2
),
};
const handleWebhookDataBlur = (e: React.FocusEvent<HTMLTextAreaElement>) => {
const value = e.target.value;
try {
@@ -29,19 +41,34 @@ const DeployNodeFormWebhookFields = () => {
}
};
const handlePresetDataClick = () => {
formInst.setFieldValue("webhookData", initialValues.webhookData);
};
return (
<>
<Form.Item
name="webhookData"
label={t("workflow_node.deploy.form.webhook_data.label")}
rules={[formRule]}
tooltip={<span dangerouslySetInnerHTML={{ __html: t("workflow_node.deploy.form.webhook_data.tooltip") }}></span>}
>
<Input.TextArea
autoSize={{ minRows: 3, maxRows: 10 }}
placeholder={t("workflow_node.deploy.form.webhook_data.placeholder")}
onBlur={handleWebhookDataBlur}
/>
<Form.Item className="mb-0">
<label className="mb-1 block">
<div className="flex w-full items-center justify-between gap-4">
<div className="max-w-full grow truncate">{t("workflow_node.deploy.form.webhook_data.label")}</div>
<div className="text-right">
<Button size="small" type="link" onClick={handlePresetDataClick}>
{t("workflow_node.deploy.form.webhook_data_preset.button")}
</Button>
</div>
</div>
</label>
<Form.Item name="webhookData" rules={[formRule]} initialValue={initialValues.webhookData}>
<Input.TextArea
autoSize={{ minRows: 3, maxRows: 10 }}
placeholder={t("workflow_node.deploy.form.webhook_data.placeholder")}
onBlur={handleWebhookDataBlur}
/>
</Form.Item>
</Form.Item>
<Form.Item>
<Alert type="info" message={<span dangerouslySetInnerHTML={{ __html: t("workflow_node.deploy.form.webhook_data.guide") }}></span>} />
</Form.Item>
</>
);