mirror of
https://github.com/langgenius/dify.git
synced 2026-05-03 00:48:04 +08:00
datasource
This commit is contained in:
@ -1,18 +1,18 @@
|
||||
import { useCallback } from 'react'
|
||||
import {
|
||||
useCallback,
|
||||
useEffect,
|
||||
} from 'react'
|
||||
import { useStoreApi } from 'reactflow'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { useNodeDataUpdate } from '@/app/components/workflow/hooks'
|
||||
import type {
|
||||
DataSourceNodeType,
|
||||
ToolVarInputs,
|
||||
} from '../types'
|
||||
import { useToastContext } from '@/app/components/base/toast'
|
||||
import { DEFAULT_FILE_EXTENSIONS_IN_LOCAL_FILE_DATA_SOURCE } from '../constants'
|
||||
|
||||
export const useConfig = (id: string) => {
|
||||
const store = useStoreApi()
|
||||
const { handleNodeDataUpdateWithSyncDraft } = useNodeDataUpdate()
|
||||
const { notify } = useToastContext()
|
||||
const { t } = useTranslation()
|
||||
|
||||
const getNodeData = useCallback(() => {
|
||||
const { getNodes } = store.getState()
|
||||
@ -27,6 +27,23 @@ export const useConfig = (id: string) => {
|
||||
data,
|
||||
})
|
||||
}, [id, handleNodeDataUpdateWithSyncDraft])
|
||||
|
||||
const handleLocalFileDataSourceInit = useCallback(() => {
|
||||
const nodeData = getNodeData()
|
||||
|
||||
if (nodeData?.data._dataSourceStartToAdd && nodeData?.data.provider_type === 'local_file') {
|
||||
handleNodeDataUpdate({
|
||||
...nodeData.data,
|
||||
_dataSourceStartToAdd: false,
|
||||
fileExtensions: DEFAULT_FILE_EXTENSIONS_IN_LOCAL_FILE_DATA_SOURCE,
|
||||
})
|
||||
}
|
||||
}, [getNodeData, handleNodeDataUpdate])
|
||||
|
||||
useEffect(() => {
|
||||
handleLocalFileDataSourceInit()
|
||||
}, [handleLocalFileDataSourceInit])
|
||||
|
||||
const handleFileExtensionsChange = useCallback((fileExtensions: string[]) => {
|
||||
const nodeData = getNodeData()
|
||||
handleNodeDataUpdate({
|
||||
|
||||
Reference in New Issue
Block a user