mirror of
https://github.com/langgenius/dify.git
synced 2026-04-27 19:27:23 +08:00
feat: template transform default
This commit is contained in:
parent
ec49da073e
commit
af9ae91934
@ -1,19 +1,36 @@
|
|||||||
import { useCallback } from 'react'
|
import { useCallback, useEffect } from 'react'
|
||||||
import produce from 'immer'
|
import produce from 'immer'
|
||||||
import useVarList from '../_base/hooks/use-var-list'
|
import useVarList from '../_base/hooks/use-var-list'
|
||||||
import type { Var } from '../../types'
|
import type { Var } from '../../types'
|
||||||
import { VarType } from '../../types'
|
import { VarType } from '../../types'
|
||||||
|
import { useStore } from '../../store'
|
||||||
import type { TemplateTransformNodeType } from './types'
|
import type { TemplateTransformNodeType } from './types'
|
||||||
import useNodeCrud from '@/app/components/workflow/nodes/_base/hooks/use-node-crud'
|
import useNodeCrud from '@/app/components/workflow/nodes/_base/hooks/use-node-crud'
|
||||||
import useOneStepRun from '@/app/components/workflow/nodes/_base/hooks/use-one-step-run'
|
import useOneStepRun from '@/app/components/workflow/nodes/_base/hooks/use-one-step-run'
|
||||||
|
|
||||||
const useConfig = (id: string, payload: TemplateTransformNodeType) => {
|
const useConfig = (id: string, payload: TemplateTransformNodeType) => {
|
||||||
|
const defaultConfig = useStore(s => s.nodesDefaultConfigs)[payload.type]
|
||||||
|
|
||||||
const { inputs, setInputs } = useNodeCrud<TemplateTransformNodeType>(id, payload)
|
const { inputs, setInputs } = useNodeCrud<TemplateTransformNodeType>(id, payload)
|
||||||
const { handleVarListChange, handleAddVariable } = useVarList<TemplateTransformNodeType>({
|
const { handleVarListChange, handleAddVariable } = useVarList<TemplateTransformNodeType>({
|
||||||
inputs,
|
inputs,
|
||||||
setInputs,
|
setInputs,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (inputs.template)
|
||||||
|
return
|
||||||
|
|
||||||
|
const isReady = defaultConfig && Object.keys(defaultConfig).length > 0
|
||||||
|
if (isReady) {
|
||||||
|
setInputs({
|
||||||
|
...inputs,
|
||||||
|
...defaultConfig,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
}, [defaultConfig])
|
||||||
|
|
||||||
const handleCodeChange = useCallback((template: string) => {
|
const handleCodeChange = useCallback((template: string) => {
|
||||||
const newInputs = produce(inputs, (draft: any) => {
|
const newInputs = produce(inputs, (draft: any) => {
|
||||||
draft.template = template
|
draft.template = template
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user