Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

feat: Add autofill by default value in endpoint plugin setting page. (#21669)

呆萌闷油瓶765adabb3218
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 fd862720af5..130773e0c2e 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<string, any>) => void
}
+const extractDefaultValues = (schemas: any[]) => {
+ const result: Record<string, any> = {}
+ for (const field of schemas) {
+ if (field.default !== undefined)
+ result[field.name] = field.default
+ }
+ return result
+}
+
const EndpointModal: FC<Props> = ({
formSchemas,
defaultValues = {},
@@ -26,7 +35,10 @@ const EndpointModal: FC<Props> = ({
}) => {
const getValueFromI18nObject = useRenderI18nObject()
const { t } = useTranslation()
- const [tempCredential, setTempCredential] = React.useState<any>(defaultValues)
+ const initialValues = Object.keys(defaultValues).length > 0
+ ? defaultValues
+ : extractDefaultValues(formSchemas)
+ const [tempCredential, setTempCredential] = React.useState<any>(initialValues)
const handleSave = () => {
for (const field of formSchemas) {