mirror of
https://github.com/langgenius/dify.git
synced 2026-05-05 17:18:40 +08:00
fix: debug set var value error
This commit is contained in:
parent
9b577fa32c
commit
7ba0bfffa2
@ -38,7 +38,6 @@ const ConfigModal: FC<IConfigModalProps> = ({
|
|||||||
const { modelConfig } = useContext(ConfigContext)
|
const { modelConfig } = useContext(ConfigContext)
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const [tempPayload, setTempPayload] = useState<InputVar>(payload || getNewVarInWorkflow('') as any)
|
const [tempPayload, setTempPayload] = useState<InputVar>(payload || getNewVarInWorkflow('') as any)
|
||||||
// const { type, name, key, options, max_length } = tempPayload; name => label; variable => key
|
|
||||||
const { type, label, variable, options, max_length } = tempPayload
|
const { type, label, variable, options, max_length } = tempPayload
|
||||||
|
|
||||||
const isStringInput = type === InputVarType.textInput || type === InputVarType.paragraph
|
const isStringInput = type === InputVarType.textInput || type === InputVarType.paragraph
|
||||||
|
|||||||
@ -5,6 +5,7 @@ import { useTranslation } from 'react-i18next'
|
|||||||
import { useBoolean } from 'ahooks'
|
import { useBoolean } from 'ahooks'
|
||||||
import type { Timeout } from 'ahooks/lib/useRequest/src/types'
|
import type { Timeout } from 'ahooks/lib/useRequest/src/types'
|
||||||
import { useContext } from 'use-context-selector'
|
import { useContext } from 'use-context-selector'
|
||||||
|
import produce from 'immer'
|
||||||
import Panel from '../base/feature-panel'
|
import Panel from '../base/feature-panel'
|
||||||
import EditModal from './config-modal'
|
import EditModal from './config-modal'
|
||||||
import IconTypeIcon from './input-type-icon'
|
import IconTypeIcon from './input-type-icon'
|
||||||
@ -71,23 +72,35 @@ const ConfigVar: FC<IConfigVarProps> = ({ promptVariables, readonly, onPromptVar
|
|||||||
})
|
})
|
||||||
onPromptVariablesChange?.(newPromptVariables)
|
onPromptVariablesChange?.(newPromptVariables)
|
||||||
}
|
}
|
||||||
|
const [currIndex, setCurrIndex] = useState<number>(-1)
|
||||||
|
const currItem = currIndex !== -1 ? promptVariables[currIndex] : null
|
||||||
|
const currItemToEdit: InputVar | null = (() => {
|
||||||
|
if (!currItem)
|
||||||
|
return null
|
||||||
|
|
||||||
const batchUpdatePromptVariable = (key: string, updateKeys: string[], newValues: any[], isParagraph?: boolean) => {
|
return {
|
||||||
console.log(key)
|
...currItem,
|
||||||
const newPromptVariables = promptVariables.map((item) => {
|
label: currItem.name,
|
||||||
if (item.key === key) {
|
variable: currItem.key,
|
||||||
const newItem: any = { ...item }
|
type: currItem.type === 'string' ? InputVarType.textInput : currItem.type,
|
||||||
updateKeys.forEach((updateKey, i) => {
|
} as InputVar
|
||||||
newItem[updateKey] = newValues[i]
|
})()
|
||||||
})
|
const updatePromptVariableItem = (payload: InputVar) => {
|
||||||
if (isParagraph) {
|
console.log(payload)
|
||||||
delete newItem.max_length
|
const newPromptVariables = produce(promptVariables, (draft) => {
|
||||||
delete newItem.options
|
const { variable, label, type, ...rest } = payload
|
||||||
}
|
draft[currIndex] = {
|
||||||
return newItem
|
...rest,
|
||||||
|
type: type === InputVarType.textInput ? 'string' : type,
|
||||||
|
key: variable,
|
||||||
|
name: label,
|
||||||
}
|
}
|
||||||
|
|
||||||
return item
|
if (payload.type === InputVarType.textInput)
|
||||||
|
draft[currIndex].max_length = draft[currIndex].max_length || DEFAULT_VALUE_MAX_LEN
|
||||||
|
|
||||||
|
if (payload.type !== InputVarType.select)
|
||||||
|
delete draft[currIndex].options
|
||||||
})
|
})
|
||||||
|
|
||||||
onPromptVariablesChange?.(newPromptVariables)
|
onPromptVariablesChange?.(newPromptVariables)
|
||||||
@ -243,23 +256,12 @@ const ConfigVar: FC<IConfigVarProps> = ({ promptVariables, readonly, onPromptVar
|
|||||||
didRemoveVar(index)
|
didRemoveVar(index)
|
||||||
}
|
}
|
||||||
|
|
||||||
const [currKey, setCurrKey] = useState<string | null>(null)
|
// const [currKey, setCurrKey] = useState<string | null>(null)
|
||||||
const currItem = currKey ? promptVariables.find(item => item.key === currKey) : null
|
|
||||||
const currItemToEdit: InputVar | null = (() => {
|
|
||||||
if (!currItem)
|
|
||||||
return null
|
|
||||||
|
|
||||||
return {
|
|
||||||
...currItem,
|
|
||||||
label: currItem.name,
|
|
||||||
variable: currItem.key,
|
|
||||||
type: currItem.type === 'string' ? InputVarType.textInput : currItem.type,
|
|
||||||
} as InputVar
|
|
||||||
})()
|
|
||||||
const [isShowEditModal, { setTrue: showEditModal, setFalse: hideEditModal }] = useBoolean(false)
|
const [isShowEditModal, { setTrue: showEditModal, setFalse: hideEditModal }] = useBoolean(false)
|
||||||
|
|
||||||
const handleConfig = ({ key, type, index, name, config, icon, icon_background }: ExternalDataToolParams) => {
|
const handleConfig = ({ key, type, index, name, config, icon, icon_background }: ExternalDataToolParams) => {
|
||||||
setCurrKey(key)
|
// setCurrKey(key)
|
||||||
|
setCurrIndex(index)
|
||||||
if (type !== 'string' && type !== 'paragraph' && type !== 'select') {
|
if (type !== 'string' && type !== 'paragraph' && type !== 'select') {
|
||||||
handleOpenExternalDataToolModal({ key, type, index, name, config, icon, icon_background }, promptVariables)
|
handleOpenExternalDataToolModal({ key, type, index, name, config, icon, icon_background }, promptVariables)
|
||||||
return
|
return
|
||||||
@ -311,7 +313,6 @@ const ConfigVar: FC<IConfigVarProps> = ({ promptVariables, readonly, onPromptVar
|
|||||||
<tr key={index} className="h-9 leading-9">
|
<tr key={index} className="h-9 leading-9">
|
||||||
<td className="w-[160px] border-b border-gray-100 pl-3">
|
<td className="w-[160px] border-b border-gray-100 pl-3">
|
||||||
<div className='flex items-center space-x-1'>
|
<div className='flex items-center space-x-1'>
|
||||||
{type}
|
|
||||||
<IconTypeIcon type={type as IInputTypeIconProps['type']} className='text-gray-400' />
|
<IconTypeIcon type={type as IInputTypeIconProps['type']} className='text-gray-400' />
|
||||||
{!readonly
|
{!readonly
|
||||||
? (
|
? (
|
||||||
@ -377,14 +378,7 @@ const ConfigVar: FC<IConfigVarProps> = ({ promptVariables, readonly, onPromptVar
|
|||||||
isShow={isShowEditModal}
|
isShow={isShowEditModal}
|
||||||
onClose={hideEditModal}
|
onClose={hideEditModal}
|
||||||
onConfirm={(item) => {
|
onConfirm={(item) => {
|
||||||
const { type, max_length, options } = item
|
updatePromptVariableItem(item)
|
||||||
if (type === InputVarType.textInput)
|
|
||||||
batchUpdatePromptVariable(currKey as string, ['type', 'max_length'], ['string', max_length || DEFAULT_VALUE_MAX_LEN])
|
|
||||||
if (type === InputVarType.paragraph)
|
|
||||||
batchUpdatePromptVariable(currKey as string, ['type', 'max_length'], [InputVarType.paragraph, max_length || DEFAULT_VALUE_MAX_LEN], true)
|
|
||||||
else
|
|
||||||
batchUpdatePromptVariable(currKey as string, ['type', 'options'], [type, options || []], false)
|
|
||||||
|
|
||||||
hideEditModal()
|
hideEditModal()
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user