mirror of
https://github.com/langgenius/dify.git
synced 2026-04-29 04:26:30 +08:00
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 = {
|
type Props = {
|
||||||
title: string | JSX.Element
|
title: string | JSX.Element
|
||||||
value: string
|
value: string
|
||||||
variables: string[]
|
|
||||||
onChange: (value: string) => void
|
onChange: (value: string) => void
|
||||||
readOnly?: boolean
|
readOnly?: boolean
|
||||||
showRemove?: boolean
|
showRemove?: boolean
|
||||||
|
|||||||
@ -8,11 +8,14 @@ import { BodyType } from '../../types'
|
|||||||
import useKeyValueList from '../../hooks/use-key-value-list'
|
import useKeyValueList from '../../hooks/use-key-value-list'
|
||||||
import KeyValue from '../key-value'
|
import KeyValue from '../key-value'
|
||||||
import TextEditor from '../../../_base/components/editor/text-editor'
|
import TextEditor from '../../../_base/components/editor/text-editor'
|
||||||
import CodeEditor from '../../../_base/components/editor/code-editor'
|
import useAvailableVarList from '../../../_base/hooks/use-available-var-list'
|
||||||
import { CodeLanguage } from '../../../code/types'
|
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 = {
|
type Props = {
|
||||||
readonly: boolean
|
readonly: boolean
|
||||||
|
nodeId: string
|
||||||
payload: Body
|
payload: Body
|
||||||
onChange: (payload: Body) => void
|
onChange: (payload: Body) => void
|
||||||
}
|
}
|
||||||
@ -34,10 +37,17 @@ const bodyTextMap = {
|
|||||||
|
|
||||||
const EditBody: FC<Props> = ({
|
const EditBody: FC<Props> = ({
|
||||||
readonly,
|
readonly,
|
||||||
|
nodeId,
|
||||||
payload,
|
payload,
|
||||||
onChange,
|
onChange,
|
||||||
}) => {
|
}) => {
|
||||||
const { type } = payload
|
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 handleTypeChange = useCallback((e: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
const newType = e.target.value as BodyType
|
const newType = e.target.value as BodyType
|
||||||
@ -111,11 +121,10 @@ const EditBody: FC<Props> = ({
|
|||||||
{(type === BodyType.formData || type === BodyType.xWwwFormUrlencoded) && (
|
{(type === BodyType.formData || type === BodyType.xWwwFormUrlencoded) && (
|
||||||
<KeyValue
|
<KeyValue
|
||||||
readonly={readonly}
|
readonly={readonly}
|
||||||
|
nodeId={nodeId}
|
||||||
list={body}
|
list={body}
|
||||||
onChange={setBody}
|
onChange={setBody}
|
||||||
onAdd={addBody}
|
onAdd={addBody}
|
||||||
isKeyValueEdit={isBodyKeyValueEdit}
|
|
||||||
toggleKeyValueEdit={toggleIsBodyKeyValueEdit}
|
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
@ -130,11 +139,18 @@ const EditBody: FC<Props> = ({
|
|||||||
)}
|
)}
|
||||||
|
|
||||||
{type === BodyType.json && (
|
{type === BodyType.json && (
|
||||||
<CodeEditor
|
// <CodeEditor
|
||||||
readOnly={readonly}
|
// readOnly={readonly}
|
||||||
title={<div className='uppercase'>JSON</div>}
|
// title={<div className='uppercase'>JSON</div>}
|
||||||
value={payload.data} onChange={handleBodyValueChange}
|
// value={payload.data} onChange={handleBodyValueChange}
|
||||||
language={CodeLanguage.json}
|
// language={CodeLanguage.json}
|
||||||
|
// />
|
||||||
|
<InputWithVar
|
||||||
|
title='JSON'
|
||||||
|
value={payload.data}
|
||||||
|
onChange={handleBodyValueChange}
|
||||||
|
justVar
|
||||||
|
nodesOutputVars={availableVarList}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -105,6 +105,7 @@ const Panel: FC<NodePanelProps<HttpNodeType>> = ({
|
|||||||
title={t(`${i18nPrefix}.body`)}
|
title={t(`${i18nPrefix}.body`)}
|
||||||
>
|
>
|
||||||
<EditBody
|
<EditBody
|
||||||
|
nodeId={id}
|
||||||
readonly={readOnly}
|
readonly={readOnly}
|
||||||
payload={inputs.body}
|
payload={inputs.body}
|
||||||
onChange={setBody}
|
onChange={setBody}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user