mirror of https://github.com/langgenius/dify.git
feat(input-field): add isEditMode prop to InputFieldForm and update handling of variable changes
This commit is contained in:
parent
1522fd50df
commit
32a009654f
|
|
@ -1,5 +1,6 @@
|
|||
import { useTranslation } from 'react-i18next'
|
||||
import { useCallback, useState } from 'react'
|
||||
import type { MoreInfo } from '@/app/components/workflow/types'
|
||||
import { ChangeType } from '@/app/components/workflow/types'
|
||||
import { useFileUploadConfig } from '@/service/use-common'
|
||||
import type { FormData, InputFieldFormProps } from './types'
|
||||
|
|
@ -18,6 +19,7 @@ const InputFieldForm = ({
|
|||
supportFile = false,
|
||||
onCancel,
|
||||
onSubmit,
|
||||
isEditMode = true,
|
||||
}: InputFieldFormProps) => {
|
||||
const { t } = useTranslation()
|
||||
|
||||
|
|
@ -47,12 +49,13 @@ const InputFieldForm = ({
|
|||
},
|
||||
},
|
||||
onSubmit: ({ value }) => {
|
||||
const moreInfo = value.variable === initialData?.variable
|
||||
? undefined
|
||||
: {
|
||||
let moreInfo: MoreInfo | undefined
|
||||
if (isEditMode && value.variable !== initialData?.variable) {
|
||||
moreInfo = {
|
||||
type: ChangeType.changeVarName,
|
||||
payload: { beforeKey: initialData?.variable || '', afterKey: value.variable },
|
||||
}
|
||||
}
|
||||
onSubmit(value as FormData, moreInfo)
|
||||
},
|
||||
})
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ export type InputFieldFormProps = {
|
|||
supportFile?: boolean
|
||||
onCancel: () => void
|
||||
onSubmit: (value: FormData, moreInfo?: MoreInfo) => void
|
||||
isEditMode?: boolean
|
||||
}
|
||||
|
||||
export type SchemaOptions = {
|
||||
|
|
|
|||
|
|
@ -59,6 +59,7 @@ const InputFieldEditorPanel = ({
|
|||
supportFile
|
||||
onCancel={onClose}
|
||||
onSubmit={handleSubmit}
|
||||
isEditMode={!!initialData}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
|
|
|
|||
|
|
@ -258,7 +258,7 @@ const formatItem = (
|
|||
required: v.required,
|
||||
}
|
||||
try {
|
||||
if(type === VarType.object && v.json_schema) {
|
||||
if (type === VarType.object && v.json_schema) {
|
||||
varRes.children = {
|
||||
schema: JSON.parse(v.json_schema),
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue