mirror of https://github.com/langgenius/dify.git
feat: body to json editor
This commit is contained in:
parent
760ada399f
commit
a8236a270a
|
|
@ -19,7 +19,6 @@ import TooltipPlus from '@/app/components/base/tooltip-plus'
|
|||
type Props = {
|
||||
title: string | JSX.Element
|
||||
value: string
|
||||
variables: string[]
|
||||
onChange: (value: string) => void
|
||||
readOnly?: boolean
|
||||
showRemove?: boolean
|
||||
|
|
|
|||
|
|
@ -8,11 +8,14 @@ import { BodyType } from '../../types'
|
|||
import useKeyValueList from '../../hooks/use-key-value-list'
|
||||
import KeyValue from '../key-value'
|
||||
import TextEditor from '../../../_base/components/editor/text-editor'
|
||||
import CodeEditor from '../../../_base/components/editor/code-editor'
|
||||
import { CodeLanguage } from '../../../code/types'
|
||||
import useAvailableVarList from '../../../_base/hooks/use-available-var-list'
|
||||
import InputWithVar from '@/app/components/workflow/nodes/_base/components/prompt/editor'
|
||||
import type { Var } from '@/app/components/workflow/types'
|
||||
import { VarType } from '@/app/components/workflow/types'
|
||||
|
||||
type Props = {
|
||||
readonly: boolean
|
||||
nodeId: string
|
||||
payload: Body
|
||||
onChange: (payload: Body) => void
|
||||
}
|
||||
|
|
@ -34,10 +37,17 @@ const bodyTextMap = {
|
|||
|
||||
const EditBody: FC<Props> = ({
|
||||
readonly,
|
||||
nodeId,
|
||||
payload,
|
||||
onChange,
|
||||
}) => {
|
||||
const { type } = payload
|
||||
const availableVarList = useAvailableVarList(nodeId, {
|
||||
onlyLeafNodeVar: false,
|
||||
filterVar: (varPayload: Var) => {
|
||||
return [VarType.string, VarType.number].includes(varPayload.type)
|
||||
},
|
||||
})
|
||||
|
||||
const handleTypeChange = useCallback((e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const newType = e.target.value as BodyType
|
||||
|
|
@ -111,11 +121,10 @@ const EditBody: FC<Props> = ({
|
|||
{(type === BodyType.formData || type === BodyType.xWwwFormUrlencoded) && (
|
||||
<KeyValue
|
||||
readonly={readonly}
|
||||
nodeId={nodeId}
|
||||
list={body}
|
||||
onChange={setBody}
|
||||
onAdd={addBody}
|
||||
isKeyValueEdit={isBodyKeyValueEdit}
|
||||
toggleKeyValueEdit={toggleIsBodyKeyValueEdit}
|
||||
/>
|
||||
)}
|
||||
|
||||
|
|
@ -130,11 +139,18 @@ const EditBody: FC<Props> = ({
|
|||
)}
|
||||
|
||||
{type === BodyType.json && (
|
||||
<CodeEditor
|
||||
readOnly={readonly}
|
||||
title={<div className='uppercase'>JSON</div>}
|
||||
value={payload.data} onChange={handleBodyValueChange}
|
||||
language={CodeLanguage.json}
|
||||
// <CodeEditor
|
||||
// readOnly={readonly}
|
||||
// title={<div className='uppercase'>JSON</div>}
|
||||
// value={payload.data} onChange={handleBodyValueChange}
|
||||
// language={CodeLanguage.json}
|
||||
// />
|
||||
<InputWithVar
|
||||
title='JSON'
|
||||
value={payload.data}
|
||||
onChange={handleBodyValueChange}
|
||||
justVar
|
||||
nodesOutputVars={availableVarList}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -105,6 +105,7 @@ const Panel: FC<NodePanelProps<HttpNodeType>> = ({
|
|||
title={t(`${i18nPrefix}.body`)}
|
||||
>
|
||||
<EditBody
|
||||
nodeId={id}
|
||||
readonly={readOnly}
|
||||
payload={inputs.body}
|
||||
onChange={setBody}
|
||||
|
|
|
|||
Loading…
Reference in New Issue