mirror of
https://github.com/langgenius/dify.git
synced 2025-07-15 13:14:44 +00:00
35 lines
1005 B
TypeScript
35 lines
1005 B
TypeScript
import { useCallback } from 'react'
|
|
import { useStoreApi } from 'reactflow'
|
|
import { useNodeDataUpdate } from '@/app/components/workflow/hooks'
|
|
import type { DataSourceNodeType } from '../types'
|
|
|
|
export const useConfig = (id: string) => {
|
|
const store = useStoreApi()
|
|
const { handleNodeDataUpdateWithSyncDraft } = useNodeDataUpdate()
|
|
|
|
const getNodeData = useCallback(() => {
|
|
const { getNodes } = store.getState()
|
|
const nodes = getNodes()
|
|
|
|
return nodes.find(node => node.id === id)
|
|
}, [store, id])
|
|
|
|
const handleNodeDataUpdate = useCallback((data: Partial<DataSourceNodeType>) => {
|
|
handleNodeDataUpdateWithSyncDraft({
|
|
id,
|
|
data,
|
|
})
|
|
}, [id, handleNodeDataUpdateWithSyncDraft])
|
|
const handleFileExtensionsChange = useCallback((fileExtensions: string[]) => {
|
|
const nodeData = getNodeData()
|
|
handleNodeDataUpdate({
|
|
...nodeData?.data,
|
|
fileExtensions,
|
|
})
|
|
}, [handleNodeDataUpdate, getNodeData])
|
|
|
|
return {
|
|
handleFileExtensionsChange,
|
|
}
|
|
}
|