mirror of
https://github.com/langgenius/dify.git
synced 2026-05-06 02:18:08 +08:00
refactor: rename cancel editor handler and improve variable name validation in field list
This commit is contained in:
@ -27,8 +27,7 @@ const InputFieldEditor = ({
|
|||||||
const handleSubmit = useCallback((value: FormData, moreInfo?: MoreInfo) => {
|
const handleSubmit = useCallback((value: FormData, moreInfo?: MoreInfo) => {
|
||||||
const inputFieldData = convertFormDataToINputField(value)
|
const inputFieldData = convertFormDataToINputField(value)
|
||||||
onSubmit(inputFieldData, moreInfo)
|
onSubmit(inputFieldData, moreInfo)
|
||||||
onClose()
|
}, [onSubmit])
|
||||||
}, [onSubmit, onClose])
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DialogWrapper
|
<DialogWrapper
|
||||||
|
|||||||
@ -10,6 +10,7 @@ import type { MoreInfo, ValueSelector } from '@/app/components/workflow/types'
|
|||||||
import { ChangeType } from '@/app/components/workflow/types'
|
import { ChangeType } from '@/app/components/workflow/types'
|
||||||
import { useWorkflow } from '@/app/components/workflow/hooks'
|
import { useWorkflow } from '@/app/components/workflow/hooks'
|
||||||
import { useBoolean } from 'ahooks'
|
import { useBoolean } from 'ahooks'
|
||||||
|
import Toast from '@/app/components/base/toast'
|
||||||
|
|
||||||
export const useFieldList = (
|
export const useFieldList = (
|
||||||
initialInputFields: InputVar[],
|
initialInputFields: InputVar[],
|
||||||
@ -51,8 +52,9 @@ export const useFieldList = (
|
|||||||
setEditingField(inputFieldsRef.current[index])
|
setEditingField(inputFieldsRef.current[index])
|
||||||
setShowInputFieldEditor(true)
|
setShowInputFieldEditor(true)
|
||||||
}, [])
|
}, [])
|
||||||
const handleCancelInputFieldEditor = useCallback(() => {
|
const handleCloseInputFieldEditor = useCallback(() => {
|
||||||
setShowInputFieldEditor(false)
|
setShowInputFieldEditor(false)
|
||||||
|
editingFieldIndex.current = -1
|
||||||
setEditingField(undefined)
|
setEditingField(undefined)
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
@ -77,6 +79,15 @@ export const useFieldList = (
|
|||||||
}, [removedIndex, handleInputFieldsChange, removeUsedVarInNodes, removedVar, hideRemoveVarConfirm])
|
}, [removedIndex, handleInputFieldsChange, removeUsedVarInNodes, removedVar, hideRemoveVarConfirm])
|
||||||
|
|
||||||
const handleSubmitField = useCallback((data: InputVar, moreInfo?: MoreInfo) => {
|
const handleSubmitField = useCallback((data: InputVar, moreInfo?: MoreInfo) => {
|
||||||
|
const isDuplicate = inputFieldsRef.current.some(field =>
|
||||||
|
field.variable === data.variable && field.variable !== editingField?.variable)
|
||||||
|
if (isDuplicate) {
|
||||||
|
Toast.notify({
|
||||||
|
type: 'error',
|
||||||
|
message: 'Variable name already exists. Please choose a different name.',
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
const newInputFields = produce(inputFieldsRef.current, (draft) => {
|
const newInputFields = produce(inputFieldsRef.current, (draft) => {
|
||||||
const currentIndex = editingFieldIndex.current
|
const currentIndex = editingFieldIndex.current
|
||||||
if (currentIndex === -1) {
|
if (currentIndex === -1) {
|
||||||
@ -89,7 +100,8 @@ export const useFieldList = (
|
|||||||
// Update variable name in nodes if it has changed
|
// Update variable name in nodes if it has changed
|
||||||
if (moreInfo?.type === ChangeType.changeVarName)
|
if (moreInfo?.type === ChangeType.changeVarName)
|
||||||
handleOutVarRenameChange(nodeId, [nodeId, moreInfo.payload?.beforeKey || ''], [nodeId, moreInfo.payload?.afterKey || ''])
|
handleOutVarRenameChange(nodeId, [nodeId, moreInfo.payload?.beforeKey || ''], [nodeId, moreInfo.payload?.afterKey || ''])
|
||||||
}, [handleInputFieldsChange, handleOutVarRenameChange, nodeId])
|
handleCloseInputFieldEditor()
|
||||||
|
}, [editingField?.variable, handleCloseInputFieldEditor, handleInputFieldsChange, handleOutVarRenameChange, nodeId])
|
||||||
|
|
||||||
return {
|
return {
|
||||||
inputFields,
|
inputFields,
|
||||||
@ -100,7 +112,7 @@ export const useFieldList = (
|
|||||||
editingField,
|
editingField,
|
||||||
showInputFieldEditor,
|
showInputFieldEditor,
|
||||||
handleOpenInputFieldEditor,
|
handleOpenInputFieldEditor,
|
||||||
handleCancelInputFieldEditor,
|
handleCloseInputFieldEditor,
|
||||||
isShowRemoveVarConfirm,
|
isShowRemoveVarConfirm,
|
||||||
hideRemoveVarConfirm,
|
hideRemoveVarConfirm,
|
||||||
onRemoveVarConfirm,
|
onRemoveVarConfirm,
|
||||||
|
|||||||
@ -34,7 +34,7 @@ const FieldList = ({
|
|||||||
handleSubmitField,
|
handleSubmitField,
|
||||||
handleListSortChange,
|
handleListSortChange,
|
||||||
handleRemoveField,
|
handleRemoveField,
|
||||||
handleCancelInputFieldEditor,
|
handleCloseInputFieldEditor,
|
||||||
handleOpenInputFieldEditor,
|
handleOpenInputFieldEditor,
|
||||||
showInputFieldEditor,
|
showInputFieldEditor,
|
||||||
editingField,
|
editingField,
|
||||||
@ -69,7 +69,7 @@ const FieldList = ({
|
|||||||
show={showInputFieldEditor}
|
show={showInputFieldEditor}
|
||||||
initialData={editingField}
|
initialData={editingField}
|
||||||
onSubmit={handleSubmitField}
|
onSubmit={handleSubmitField}
|
||||||
onClose={handleCancelInputFieldEditor}
|
onClose={handleCloseInputFieldEditor}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
<RemoveEffectVarConfirm
|
<RemoveEffectVarConfirm
|
||||||
|
|||||||
Reference in New Issue
Block a user