mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-05-14 04:28:17 +08:00

Co-authored-by: Joel <iamjoel007@gmail.com> Co-authored-by: Yeuoly <admin@srmxy.cn> Co-authored-by: JzoNg <jzongcode@gmail.com> Co-authored-by: StyleZhang <jasonapring2015@outlook.com> Co-authored-by: jyong <jyong@dify.ai> Co-authored-by: nite-knite <nkCoding@gmail.com> Co-authored-by: jyong <718720800@qq.com>
42 lines
1.2 KiB
TypeScript
42 lines
1.2 KiB
TypeScript
import { useCallback } from 'react'
|
|
import produce from 'immer'
|
|
import useVarList from '../_base/hooks/use-var-list'
|
|
import type { Var } from '../../types'
|
|
import { VarType } from '../../types'
|
|
import type { AnswerNodeType } from './types'
|
|
import useNodeCrud from '@/app/components/workflow/nodes/_base/hooks/use-node-crud'
|
|
import {
|
|
useNodesReadOnly,
|
|
} from '@/app/components/workflow/hooks'
|
|
|
|
const useConfig = (id: string, payload: AnswerNodeType) => {
|
|
const { nodesReadOnly: readOnly } = useNodesReadOnly()
|
|
const { inputs, setInputs } = useNodeCrud<AnswerNodeType>(id, payload)
|
|
// variables
|
|
const { handleVarListChange, handleAddVariable } = useVarList<AnswerNodeType>({
|
|
inputs,
|
|
setInputs,
|
|
})
|
|
|
|
const handleAnswerChange = useCallback((value: string) => {
|
|
const newInputs = produce(inputs, (draft) => {
|
|
draft.answer = value
|
|
})
|
|
setInputs(newInputs)
|
|
}, [inputs, setInputs])
|
|
|
|
const filterVar = useCallback((varPayload: Var) => {
|
|
return varPayload.type !== VarType.arrayObject
|
|
}, [])
|
|
return {
|
|
readOnly,
|
|
inputs,
|
|
handleVarListChange,
|
|
handleAddVariable,
|
|
handleAnswerChange,
|
|
filterVar,
|
|
}
|
|
}
|
|
|
|
export default useConfig
|