mirror of
https://github.com/langgenius/dify.git
synced 2026-05-04 17:38:04 +08:00
feat: var name rename struct
This commit is contained in:
@ -8,12 +8,13 @@ import type { InputVar } from '@/app/components/workflow/types'
|
||||
import { Variable02 } from '@/app/components/base/icons/src/vender/solid/development'
|
||||
import { Edit03 } from '@/app/components/base/icons/src/vender/solid/general'
|
||||
import { Trash03 } from '@/app/components/base/icons/src/vender/line/general'
|
||||
import type { MoreInfo } from '@/app/components/app/configuration/config-var/config-modal'
|
||||
import ConfigVarModal from '@/app/components/app/configuration/config-var/config-modal'
|
||||
|
||||
type Props = {
|
||||
readonly: boolean
|
||||
payload: InputVar
|
||||
onChange: (item: InputVar) => void
|
||||
onChange: (item: InputVar, moreInfo?: MoreInfo) => void
|
||||
onRemove: () => void
|
||||
}
|
||||
|
||||
@ -32,8 +33,8 @@ const VarItem: FC<Props> = ({
|
||||
setFalse: hideEditVarModal,
|
||||
}] = useBoolean(false)
|
||||
|
||||
const handlePayloadChange = useCallback((payload: InputVar) => {
|
||||
onChange(payload)
|
||||
const handlePayloadChange = useCallback((payload: InputVar, moreInfo?: MoreInfo) => {
|
||||
onChange(payload, moreInfo)
|
||||
hideEditVarModal()
|
||||
}, [onChange, hideEditVarModal])
|
||||
return (
|
||||
|
||||
@ -5,11 +5,11 @@ import produce from 'immer'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import VarItem from './var-item'
|
||||
import type { InputVar } from '@/app/components/workflow/types'
|
||||
|
||||
import type { MoreInfo } from '@/app/components/app/configuration/config-var/config-modal'
|
||||
type Props = {
|
||||
readonly: boolean
|
||||
list: InputVar[]
|
||||
onChange: (list: InputVar[]) => void
|
||||
onChange: (list: InputVar[], moreInfo?: { index: number; payload: MoreInfo }) => void
|
||||
}
|
||||
|
||||
const VarList: FC<Props> = ({
|
||||
@ -19,12 +19,12 @@ const VarList: FC<Props> = ({
|
||||
}) => {
|
||||
const { t } = useTranslation()
|
||||
|
||||
const handleVarNameChange = useCallback((index: number) => {
|
||||
return (payload: InputVar) => {
|
||||
const handleVarChange = useCallback((index: number) => {
|
||||
return (payload: InputVar, moreInfo?: MoreInfo) => {
|
||||
const newList = produce(list, (draft) => {
|
||||
draft[index] = payload
|
||||
})
|
||||
onChange(newList)
|
||||
onChange(newList, moreInfo ? { index, payload: moreInfo } : undefined)
|
||||
}
|
||||
}, [list, onChange])
|
||||
|
||||
@ -52,7 +52,7 @@ const VarList: FC<Props> = ({
|
||||
key={index}
|
||||
readonly={readonly}
|
||||
payload={item}
|
||||
onChange={handleVarNameChange(index)}
|
||||
onChange={handleVarChange(index)}
|
||||
onRemove={handleVarRemove(index)}
|
||||
/>
|
||||
))}
|
||||
|
||||
@ -7,10 +7,13 @@ import useNodeCrud from '@/app/components/workflow/nodes/_base/hooks/use-node-cr
|
||||
import {
|
||||
useIsChatMode,
|
||||
useNodesReadOnly,
|
||||
useWorkflow,
|
||||
} from '@/app/components/workflow/hooks'
|
||||
import type { MoreInfo } from '@/app/components/app/configuration/config-var/config-modal'
|
||||
|
||||
const useConfig = (id: string, payload: StartNodeType) => {
|
||||
const { nodesReadOnly: readOnly } = useNodesReadOnly()
|
||||
const { handleOutVarRenameChange } = useWorkflow()
|
||||
const isChatMode = useIsChatMode()
|
||||
|
||||
const { inputs, setInputs } = useNodeCrud<StartNodeType>(id, payload)
|
||||
@ -20,11 +23,15 @@ const useConfig = (id: string, payload: StartNodeType) => {
|
||||
setFalse: hideAddVarModal,
|
||||
}] = useBoolean(false)
|
||||
|
||||
const handleVarListChange = useCallback((newList: InputVar[]) => {
|
||||
const handleVarListChange = useCallback((newList: InputVar[], moreInfo?: { index: number; payload: MoreInfo }) => {
|
||||
const newInputs = produce(inputs, (draft: any) => {
|
||||
draft.variables = newList
|
||||
})
|
||||
setInputs(newInputs)
|
||||
if (moreInfo) {
|
||||
const changedVar = newList[moreInfo.index]
|
||||
handleOutVarRenameChange(id, [id, inputs.variables[moreInfo.index].variable], [id, changedVar.variable])
|
||||
}
|
||||
}, [inputs, setInputs])
|
||||
|
||||
const handleAddVariable = useCallback((payload: InputVar) => {
|
||||
|
||||
Reference in New Issue
Block a user