feat: handle mq message
parent
bd3f3e7b26
commit
2a4f9f0af9
@ -0,0 +1,58 @@
|
|||||||
|
import type { FC } from 'react'
|
||||||
|
import React from 'react'
|
||||||
|
import { useTranslation } from 'react-i18next'
|
||||||
|
import useConfig from './use-config'
|
||||||
|
import type { MqNodeType } from './types'
|
||||||
|
import Editor from '@/app/components/workflow/nodes/_base/components/prompt/editor'
|
||||||
|
import type { NodePanelProps } from '@/app/components/workflow/types'
|
||||||
|
import useAvailableVarList from '@/app/components/workflow/nodes/_base/hooks/use-available-var-list'
|
||||||
|
import InputWithVar from '@/app/components/workflow/nodes/_base/components/prompt/editor'
|
||||||
|
const i18nPrefix = 'workflow.nodes.answer'
|
||||||
|
|
||||||
|
const Panel: FC<NodePanelProps<MqNodeType>> = ({
|
||||||
|
id,
|
||||||
|
data,
|
||||||
|
}) => {
|
||||||
|
const { t } = useTranslation()
|
||||||
|
|
||||||
|
const {
|
||||||
|
readOnly,
|
||||||
|
inputs,
|
||||||
|
handleMessageChange,
|
||||||
|
handleChannelNameChange,
|
||||||
|
filterVar,
|
||||||
|
} = useConfig(id, data)
|
||||||
|
|
||||||
|
const { availableVars, availableNodesWithParent } = useAvailableVarList(id, {
|
||||||
|
onlyLeafNodeVar: false,
|
||||||
|
hideChatVar: false,
|
||||||
|
hideEnv: false,
|
||||||
|
filterVar,
|
||||||
|
})
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className='mb-2 mt-2 space-y-4 px-4'>
|
||||||
|
<Editor
|
||||||
|
readOnly={readOnly}
|
||||||
|
justVar
|
||||||
|
title={'Channel'}
|
||||||
|
value={inputs.channelName}
|
||||||
|
onChange={handleChannelNameChange}
|
||||||
|
nodesOutputVars={availableVars}
|
||||||
|
availableNodes={availableNodesWithParent}
|
||||||
|
isSupportFileVar
|
||||||
|
/>
|
||||||
|
<div className='mt-1'></div>
|
||||||
|
<InputWithVar
|
||||||
|
title='数据'
|
||||||
|
value={inputs.message}
|
||||||
|
onChange={handleMessageChange}
|
||||||
|
justVar
|
||||||
|
nodesOutputVars={availableVars}
|
||||||
|
availableNodes={availableNodesWithParent}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default React.memo(Panel)
|
||||||
@ -0,0 +1,6 @@
|
|||||||
|
import type { CommonNodeType } from '@/app/components/workflow/types'
|
||||||
|
|
||||||
|
export type MqNodeType = CommonNodeType & {
|
||||||
|
channelName: string
|
||||||
|
message: string
|
||||||
|
}
|
||||||
@ -0,0 +1,40 @@
|
|||||||
|
import { useCallback } from 'react'
|
||||||
|
import produce from 'immer'
|
||||||
|
import { VarType } from '../../types'
|
||||||
|
import type { Var } from '../../types'
|
||||||
|
import useNodeCrud from '@/app/components/workflow/nodes/_base/hooks/use-node-crud'
|
||||||
|
import {
|
||||||
|
useNodesReadOnly,
|
||||||
|
} from '@/app/components/workflow/hooks'
|
||||||
|
import type { MqNodeType } from '@/app/components/workflow/nodes/mq/types'
|
||||||
|
|
||||||
|
const useConfig = (id: string, payload: MqNodeType) => {
|
||||||
|
const { nodesReadOnly: readOnly } = useNodesReadOnly()
|
||||||
|
const { inputs, setInputs } = useNodeCrud<MqNodeType>(id, payload)
|
||||||
|
|
||||||
|
const handleChannelNameChange = useCallback((value: string) => {
|
||||||
|
const newInputs = produce(inputs, (draft) => {
|
||||||
|
draft.channelName = value
|
||||||
|
})
|
||||||
|
setInputs(newInputs)
|
||||||
|
}, [inputs, setInputs])
|
||||||
|
const handleMessageChange = useCallback((value: string) => {
|
||||||
|
const newInputs = produce(inputs, (draft) => {
|
||||||
|
draft.message = value
|
||||||
|
})
|
||||||
|
setInputs(newInputs)
|
||||||
|
}, [inputs, setInputs])
|
||||||
|
|
||||||
|
const filterVar = useCallback((varPayload: Var) => {
|
||||||
|
return varPayload.type !== VarType.arrayObject
|
||||||
|
}, [])
|
||||||
|
return {
|
||||||
|
readOnly,
|
||||||
|
inputs,
|
||||||
|
handleChannelNameChange,
|
||||||
|
handleMessageChange,
|
||||||
|
filterVar,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default useConfig
|
||||||
Loading…
Reference in New Issue