mirror of https://github.com/langgenius/dify.git
feat: var assigner data logic
This commit is contained in:
parent
6e2611c86c
commit
31930159b8
|
|
@ -0,0 +1,28 @@
|
|||
import { useCallback, useState } from 'react'
|
||||
import produce from 'immer'
|
||||
import useVarList from './use-var-list'
|
||||
import type { VariableAssignerNodeType } from './types'
|
||||
|
||||
const useConfig = (initInputs: VariableAssignerNodeType) => {
|
||||
const [inputs, setInputs] = useState<VariableAssignerNodeType>(initInputs)
|
||||
|
||||
const handleOutputTypeChange = useCallback((outputType: string) => {
|
||||
const newInputs = produce(inputs, (draft) => {
|
||||
draft.output_type = outputType
|
||||
})
|
||||
setInputs(newInputs)
|
||||
}, [inputs, setInputs])
|
||||
|
||||
const { handleVarListChange, handleAddVariable } = useVarList({
|
||||
inputs,
|
||||
setInputs,
|
||||
})
|
||||
return {
|
||||
inputs,
|
||||
handleOutputTypeChange,
|
||||
handleVarListChange,
|
||||
handleAddVariable,
|
||||
}
|
||||
}
|
||||
|
||||
export default useConfig
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
import { useCallback } from 'react'
|
||||
import produce from 'immer'
|
||||
import type { VariableAssignerNodeType } from './types'
|
||||
import type { Variable } from '@/app/components/workflow/types'
|
||||
|
||||
type Params = {
|
||||
inputs: VariableAssignerNodeType
|
||||
setInputs: (newInputs: VariableAssignerNodeType) => void
|
||||
}
|
||||
function useVarList({
|
||||
inputs,
|
||||
setInputs,
|
||||
}: Params) {
|
||||
const handleVarListChange = useCallback((newList: Variable[]) => {
|
||||
const newInputs = produce(inputs, (draft: any) => {
|
||||
draft.variables = newList
|
||||
})
|
||||
setInputs(newInputs)
|
||||
}, [inputs, setInputs])
|
||||
|
||||
const handleAddVariable = useCallback(() => {
|
||||
const newInputs = produce(inputs, (draft: any) => {
|
||||
draft.variables.push([])
|
||||
})
|
||||
setInputs(newInputs)
|
||||
}, [inputs, setInputs])
|
||||
return {
|
||||
handleVarListChange,
|
||||
handleAddVariable,
|
||||
}
|
||||
}
|
||||
|
||||
export default useVarList
|
||||
Loading…
Reference in New Issue