mirror of
https://github.com/langgenius/dify.git
synced 2026-05-06 02:18:08 +08:00
feat: get and set data use context
This commit is contained in:
@ -1,16 +1,21 @@
|
||||
import { useCallback, useState } from 'react'
|
||||
import { useCallback } from 'react'
|
||||
import produce from 'immer'
|
||||
import useVarList from '../_base/hooks/use-var-list'
|
||||
import type { TemplateTransformNodeType } from './types'
|
||||
import useNodeCrud from '@/app/components/workflow/nodes/_base/hooks/use-node-crud'
|
||||
|
||||
const useConfig = (initInputs: TemplateTransformNodeType) => {
|
||||
const [inputs, setInputs] = useState<TemplateTransformNodeType>(initInputs)
|
||||
const useConfig = (id: string, payload: TemplateTransformNodeType) => {
|
||||
const { inputs, setInputs } = useNodeCrud<TemplateTransformNodeType>(id, payload)
|
||||
const { handleVarListChange, handleAddVariable } = useVarList<TemplateTransformNodeType>({
|
||||
inputs,
|
||||
setInputs,
|
||||
})
|
||||
|
||||
const handleCodeChange = useCallback((template: string) => {
|
||||
setInputs(prev => ({ ...prev, template }))
|
||||
const newInputs = produce(inputs, (draft: any) => {
|
||||
draft.template = template
|
||||
})
|
||||
setInputs(newInputs)
|
||||
}, [setInputs])
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user