From 03e3d4b684afd9d0f2805bea1f083431547c31c7 Mon Sep 17 00:00:00 2001 From: Jonah879 Date: Mon, 17 Nov 2025 13:07:33 +0000 Subject: [PATCH] feat: add conditional rendering for S3-compatible fields in dynamic form --- web/src/components/dynamic-form.tsx | 22 ++++++++++++++----- .../user-setting/data-source/contant.tsx | 3 +++ 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/web/src/components/dynamic-form.tsx b/web/src/components/dynamic-form.tsx index a90afe287..5c78a1dcb 100644 --- a/web/src/components/dynamic-form.tsx +++ b/web/src/components/dynamic-form.tsx @@ -67,6 +67,7 @@ export interface FormFieldConfig { ) => string | boolean | Promise; dependencies?: string[]; schema?: ZodSchema; + shouldRender?: (formValues: any) => boolean; } // Component props interface @@ -654,6 +655,9 @@ const DynamicForm = { } }; + // Watch all form values to re-render when they change (for shouldRender checks) + const formValues = form.watch(); + return (
<> - {fields.map((field) => ( -
- {renderField(field)} -
- ))} + {fields.map((field) => { + const shouldShow = field.shouldRender + ? field.shouldRender(formValues) + : true; + return ( +
+ {renderField(field)} +
+ ); + })} {children}
diff --git a/web/src/pages/user-setting/data-source/contant.tsx b/web/src/pages/user-setting/data-source/contant.tsx index 4f884332c..65788464c 100644 --- a/web/src/pages/user-setting/data-source/contant.tsx +++ b/web/src/pages/user-setting/data-source/contant.tsx @@ -116,6 +116,9 @@ export const DataSourceFormFields = { required: false, placeholder: 'https://fsn1.your-objectstorage.com', tooltip: t('setting.S3CompatibleEndpointUrlTip'), + shouldRender: (formValues) => { + return formValues?.config?.bucket_type === 's3_compatible'; + }, }, { label: 'Prefix',