dify/web/app/components/workflow/nodes/answer/use-config.ts
Stephen Zhou a84c2d36a3
style: format with vp fmt (#38803)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2026-07-12 15:57:46 +00:00

43 lines
1.2 KiB
TypeScript

import type { Var } from '../../types'
import type { AnswerNodeType } from './types'
import { produce } from 'immer'
import { useCallback } from 'react'
import { useNodesReadOnly } from '@/app/components/workflow/hooks'
import useNodeCrud from '@/app/components/workflow/nodes/_base/hooks/use-node-crud'
import { VarType } from '../../types'
import useVarList from '../_base/hooks/use-var-list'
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