mirror of
https://github.com/langgenius/dify.git
synced 2025-12-25 09:02:29 +00:00
datasource
This commit is contained in:
parent
fdc4c36b77
commit
468bfdfed9
@ -14,6 +14,10 @@ export const useAvailableNodesMetaData = () => {
|
||||
...WORKFLOW_COMMON_NODES,
|
||||
{
|
||||
...dataSourceDefault,
|
||||
defaultValue: {
|
||||
...dataSourceDefault.defaultValue,
|
||||
_dataSourceStartToAdd: true,
|
||||
},
|
||||
metaData: {
|
||||
...dataSourceDefault.metaData,
|
||||
isStart: true,
|
||||
|
||||
@ -1,5 +1,28 @@
|
||||
import { VarType } from '@/app/components/workflow/types'
|
||||
|
||||
export const DEFAULT_FILE_EXTENSIONS_IN_LOCAL_FILE_DATA_SOURCE = [
|
||||
'txt',
|
||||
'markdown',
|
||||
'mdx',
|
||||
'pdf',
|
||||
'html',
|
||||
'xlsx',
|
||||
'xls',
|
||||
'vtt',
|
||||
'properties',
|
||||
'doc',
|
||||
'docx',
|
||||
'csv',
|
||||
'eml',
|
||||
'msg',
|
||||
'pptx',
|
||||
'xml',
|
||||
'epub',
|
||||
'ppt',
|
||||
'md',
|
||||
'html',
|
||||
]
|
||||
|
||||
export const OUTPUT_VARIABLES_MAP = {
|
||||
datasource_type: {
|
||||
name: 'datasource_type',
|
||||
|
||||
@ -11,28 +11,6 @@ const metaData = genNodeMetaData({
|
||||
const nodeDefault: NodeDefault<DataSourceNodeType> = {
|
||||
metaData,
|
||||
defaultValue: {
|
||||
fileExtensions: [
|
||||
'txt',
|
||||
'markdown',
|
||||
'mdx',
|
||||
'pdf',
|
||||
'html',
|
||||
'xlsx',
|
||||
'xls',
|
||||
'vtt',
|
||||
'properties',
|
||||
'doc',
|
||||
'docx',
|
||||
'csv',
|
||||
'eml',
|
||||
'msg',
|
||||
'pptx',
|
||||
'xml',
|
||||
'epub',
|
||||
'ppt',
|
||||
'md',
|
||||
'html',
|
||||
],
|
||||
datasource_parameters: {},
|
||||
datasource_configurations: {},
|
||||
},
|
||||
|
||||
@ -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({
|
||||
|
||||
@ -12,7 +12,6 @@ import type { NodePanelProps } from '@/app/components/workflow/types'
|
||||
import {
|
||||
BoxGroupField,
|
||||
Group,
|
||||
GroupField,
|
||||
} from '@/app/components/workflow/nodes/_base/components/layout'
|
||||
import OutputVars, { VarItem } from '@/app/components/workflow/nodes/_base/components/output-vars'
|
||||
import TagInput from '@/app/components/base/tag-input'
|
||||
@ -86,7 +85,7 @@ const Panel: FC<NodePanelProps<DataSourceNodeType>> = ({ id, data }) => {
|
||||
return (
|
||||
<div >
|
||||
{
|
||||
!isAuthorized && !showAuthModal && !isLocalFile && (
|
||||
!isAuthorized && !showAuthModal && !isLocalFile && currentDataSource && (
|
||||
<Group>
|
||||
<Button
|
||||
variant='primary'
|
||||
@ -101,9 +100,15 @@ const Panel: FC<NodePanelProps<DataSourceNodeType>> = ({ id, data }) => {
|
||||
}
|
||||
{
|
||||
isAuthorized && !isLocalFile && (
|
||||
<GroupField
|
||||
groupProps={{
|
||||
withBorderBottom: true,
|
||||
<BoxGroupField
|
||||
boxGroupProps={{
|
||||
boxProps: { withBorderBottom: true },
|
||||
}}
|
||||
fieldProps={{
|
||||
fieldTitleProps: {
|
||||
title: t('workflow.nodes.tool.inputVars'),
|
||||
},
|
||||
supportCollapse: true,
|
||||
}}
|
||||
>
|
||||
<InputVarList
|
||||
@ -116,7 +121,7 @@ const Panel: FC<NodePanelProps<DataSourceNodeType>> = ({ id, data }) => {
|
||||
isSupportConstantValue
|
||||
onOpen={handleOnVarOpen}
|
||||
/>
|
||||
</GroupField>
|
||||
</BoxGroupField>
|
||||
)
|
||||
}
|
||||
{
|
||||
|
||||
@ -82,6 +82,7 @@ export type CommonNodeType<T = {}> = {
|
||||
_inParallelHovering?: boolean
|
||||
_waitingRun?: boolean
|
||||
_retryIndex?: number
|
||||
_dataSourceStartToAdd?: boolean
|
||||
isInIteration?: boolean
|
||||
iteration_id?: string
|
||||
selected?: boolean
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user