From 765adabb32180bc1c157d355976fda6a59be9c7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=86=E8=90=8C=E9=97=B7=E6=B2=B9=E7=93=B6?= <253605712@qq.com> Date: Sun, 29 Jun 2025 13:09:21 +0800 Subject: [PATCH] feat: Add autofill by default value in endpoint plugin setting page. (#21669) --- .../plugins/plugin-detail-panel/endpoint-modal.tsx | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/web/app/components/plugins/plugin-detail-panel/endpoint-modal.tsx b/web/app/components/plugins/plugin-detail-panel/endpoint-modal.tsx index fd862720af..130773e0c2 100644 --- a/web/app/components/plugins/plugin-detail-panel/endpoint-modal.tsx +++ b/web/app/components/plugins/plugin-detail-panel/endpoint-modal.tsx @@ -18,6 +18,15 @@ type Props = { onSaved: (value: Record) => void } +const extractDefaultValues = (schemas: any[]) => { + const result: Record = {} + for (const field of schemas) { + if (field.default !== undefined) + result[field.name] = field.default + } + return result +} + const EndpointModal: FC = ({ formSchemas, defaultValues = {}, @@ -26,7 +35,10 @@ const EndpointModal: FC = ({ }) => { const getValueFromI18nObject = useRenderI18nObject() const { t } = useTranslation() - const [tempCredential, setTempCredential] = React.useState(defaultValues) + const initialValues = Object.keys(defaultValues).length > 0 + ? defaultValues + : extractDefaultValues(formSchemas) + const [tempCredential, setTempCredential] = React.useState(initialValues) const handleSave = () => { for (const field of formSchemas) {