fix: test data source connection need connector name (#18495)

### Summary

as title
This commit is contained in:
Haruko386
2026-08-19 18:12:18 +08:00
committed by GitHub
parent 49d0d95f71
commit 88a72e6a36
3 changed files with 20 additions and 7 deletions

View File

@@ -44,10 +44,6 @@ const AddDataSourceModal = ({
}: IModalProps<FieldValues> & { sourceData?: IDataSorceInfo }) => {
const { t } = useTranslation();
const formRef = useRef<DynamicFormRef>(null);
const { loading: testLoading, handleTest } = useTestDataSource(
formRef,
sourceData?.id,
);
const fields = useMemo<FormFieldConfig[]>(() => {
if (!sourceData) {
return [];
@@ -57,6 +53,11 @@ const AddDataSourceModal = ({
...getDataSourceFieldsWithExtras(t, sourceData.id as any),
] as FormFieldConfig[];
}, [sourceData, t]);
const { loading: testLoading, handleTest } = useTestDataSource(
formRef,
sourceData?.id,
fields,
);
const defaultValues = useMemo<FieldValues>(
() =>

View File

@@ -163,6 +163,7 @@ const SourceDetailPage = () => {
const { loading: testLoading, handleTest } = useTestDataSource(
formRef,
connectorId,
fields,
);
const onSubmit = useCallback(() => {

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
import { DynamicFormRef } from '@/components/dynamic-form';
import { DynamicFormRef, FormFieldConfig } from '@/components/dynamic-form';
import message from '@/components/ui/message';
import { RunningStatus } from '@/constants/knowledge';
import { useSetModalState } from '@/hooks/common-hooks';
@@ -292,6 +292,7 @@ export const useDataSourceRebuild = () => {
export const useTestDataSource = (
formRef: RefObject<DynamicFormRef | null>,
connectorId?: string,
fields: FormFieldConfig[] = [],
) => {
const [currentQueryParameters] = useSearchParams();
const id = currentQueryParameters.get('id');
@@ -303,7 +304,17 @@ export const useTestDataSource = (
const connectorID = id || values?.id || connectorId || source;
if (!connectorID || !source) return;
const isValid = await formRef.current?.trigger();
const fieldNames = fields
.filter((field) => {
if (field.name === 'id' || field.name === 'name') {
return false;
}
return !field.shouldRender || field.shouldRender(values);
})
.map((field) => field.name);
const isValid = await formRef.current?.trigger(
fields.length > 0 ? fieldNames : undefined,
);
if (!isValid) return;
setLoading(true);
@@ -326,7 +337,7 @@ export const useTestDataSource = (
} finally {
setLoading(false);
}
}, [connectorId, formRef, id]);
}, [connectorId, fields, formRef, id]);
return { loading, handleTest };
};