mirror of
https://github.com/langgenius/dify.git
synced 2026-04-27 02:36:29 +08:00
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 { useTranslation } from 'react-i18next'
|
||||||
import { useCallback, useState } from 'react'
|
import { useCallback, useState } from 'react'
|
||||||
|
import type { MoreInfo } from '@/app/components/workflow/types'
|
||||||
import { ChangeType } from '@/app/components/workflow/types'
|
import { ChangeType } from '@/app/components/workflow/types'
|
||||||
import { useFileUploadConfig } from '@/service/use-common'
|
import { useFileUploadConfig } from '@/service/use-common'
|
||||||
import type { FormData, InputFieldFormProps } from './types'
|
import type { FormData, InputFieldFormProps } from './types'
|
||||||
@ -18,6 +19,7 @@ const InputFieldForm = ({
|
|||||||
supportFile = false,
|
supportFile = false,
|
||||||
onCancel,
|
onCancel,
|
||||||
onSubmit,
|
onSubmit,
|
||||||
|
isEditMode = true,
|
||||||
}: InputFieldFormProps) => {
|
}: InputFieldFormProps) => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
|
|
||||||
@ -47,12 +49,13 @@ const InputFieldForm = ({
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
onSubmit: ({ value }) => {
|
onSubmit: ({ value }) => {
|
||||||
const moreInfo = value.variable === initialData?.variable
|
let moreInfo: MoreInfo | undefined
|
||||||
? undefined
|
if (isEditMode && value.variable !== initialData?.variable) {
|
||||||
: {
|
moreInfo = {
|
||||||
type: ChangeType.changeVarName,
|
type: ChangeType.changeVarName,
|
||||||
payload: { beforeKey: initialData?.variable || '', afterKey: value.variable },
|
payload: { beforeKey: initialData?.variable || '', afterKey: value.variable },
|
||||||
}
|
}
|
||||||
|
}
|
||||||
onSubmit(value as FormData, moreInfo)
|
onSubmit(value as FormData, moreInfo)
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|||||||
@ -25,6 +25,7 @@ export type InputFieldFormProps = {
|
|||||||
supportFile?: boolean
|
supportFile?: boolean
|
||||||
onCancel: () => void
|
onCancel: () => void
|
||||||
onSubmit: (value: FormData, moreInfo?: MoreInfo) => void
|
onSubmit: (value: FormData, moreInfo?: MoreInfo) => void
|
||||||
|
isEditMode?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export type SchemaOptions = {
|
export type SchemaOptions = {
|
||||||
|
|||||||
@ -59,6 +59,7 @@ const InputFieldEditorPanel = ({
|
|||||||
supportFile
|
supportFile
|
||||||
onCancel={onClose}
|
onCancel={onClose}
|
||||||
onSubmit={handleSubmit}
|
onSubmit={handleSubmit}
|
||||||
|
isEditMode={!!initialData}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
|||||||
@ -258,7 +258,7 @@ const formatItem = (
|
|||||||
required: v.required,
|
required: v.required,
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
if(type === VarType.object && v.json_schema) {
|
if (type === VarType.object && v.json_schema) {
|
||||||
varRes.children = {
|
varRes.children = {
|
||||||
schema: JSON.parse(v.json_schema),
|
schema: JSON.parse(v.json_schema),
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user