mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-08-23 00:31:06 +08:00
fix: test data source connection need connector name (#18495)
### Summary as title
This commit is contained in:
@@ -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>(
|
||||
() =>
|
||||
|
||||
@@ -163,6 +163,7 @@ const SourceDetailPage = () => {
|
||||
const { loading: testLoading, handleTest } = useTestDataSource(
|
||||
formRef,
|
||||
connectorId,
|
||||
fields,
|
||||
);
|
||||
|
||||
const onSubmit = useCallback(() => {
|
||||
|
||||
@@ -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 };
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user