mirror of
https://github.com/langgenius/dify.git
synced 2026-04-29 04:26:30 +08:00
feat: add form content editor
This commit is contained in:
parent
bd7ba85471
commit
e2e5dedceb
@ -259,8 +259,7 @@ const PromptEditor: FC<PromptEditorProps> = ({
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
// TODO: test hitlInputBlock?.show
|
hitlInputBlock?.show && (
|
||||||
(
|
|
||||||
<>
|
<>
|
||||||
<HITLInputBlock />
|
<HITLInputBlock />
|
||||||
<HITLInputBlockReplacementBlock />
|
<HITLInputBlockReplacementBlock />
|
||||||
|
|||||||
@ -1,16 +1,67 @@
|
|||||||
'use client'
|
'use client'
|
||||||
|
import PromptEditor from '@/app/components/base/prompt-editor'
|
||||||
import type { FC } from 'react'
|
import type { FC } from 'react'
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
|
import useAvailableVarList from '../../_base/hooks/use-available-var-list'
|
||||||
|
import { BlockEnum } from '../../../types'
|
||||||
|
import { useWorkflowVariableType } from '../../../hooks'
|
||||||
|
import { useTranslation } from 'react-i18next'
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
|
nodeId: string
|
||||||
|
value: string
|
||||||
|
onChange: (value: string) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
const FormContent: FC<Props> = ({
|
const FormContent: FC<Props> = ({
|
||||||
|
nodeId,
|
||||||
|
value,
|
||||||
|
onChange,
|
||||||
}) => {
|
}) => {
|
||||||
|
const { t } = useTranslation()
|
||||||
|
const filterVar = () => true
|
||||||
|
const {
|
||||||
|
availableVars,
|
||||||
|
availableNodesWithParent: availableNodes,
|
||||||
|
} = useAvailableVarList(nodeId, {
|
||||||
|
onlyLeafNodeVar: false,
|
||||||
|
filterVar,
|
||||||
|
})
|
||||||
|
|
||||||
|
const getVarType = useWorkflowVariableType()
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
aaaa
|
<PromptEditor
|
||||||
|
value={value}
|
||||||
|
onChange={onChange}
|
||||||
|
className='min-h-[80px]'
|
||||||
|
hitlInputBlock={{
|
||||||
|
show: true,
|
||||||
|
}}
|
||||||
|
workflowVariableBlock={{
|
||||||
|
show: true,
|
||||||
|
variables: availableVars || [],
|
||||||
|
getVarType: getVarType as any,
|
||||||
|
workflowNodesMap: availableNodes.reduce((acc: any, node) => {
|
||||||
|
acc[node.id] = {
|
||||||
|
title: node.data.title,
|
||||||
|
type: node.data.type,
|
||||||
|
width: node.width,
|
||||||
|
height: node.height,
|
||||||
|
position: node.position,
|
||||||
|
}
|
||||||
|
if (node.data.type === BlockEnum.Start) {
|
||||||
|
acc.sys = {
|
||||||
|
title: t('workflow.blocks.start'),
|
||||||
|
type: BlockEnum.Start,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return acc
|
||||||
|
}, {}),
|
||||||
|
}}
|
||||||
|
editable
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -33,6 +33,7 @@ const Panel: FC<NodePanelProps<HumanInputNodeType>> = ({
|
|||||||
handleUserActionChange,
|
handleUserActionChange,
|
||||||
handleUserActionDelete,
|
handleUserActionDelete,
|
||||||
handleTimeoutChange,
|
handleTimeoutChange,
|
||||||
|
handleFormContentChange,
|
||||||
} = useConfig(id, data)
|
} = useConfig(id, data)
|
||||||
|
|
||||||
const { availableVars, availableNodesWithParent } = useAvailableVarList(id, {
|
const { availableVars, availableNodesWithParent } = useAvailableVarList(id, {
|
||||||
@ -64,7 +65,11 @@ const Panel: FC<NodePanelProps<HumanInputNodeType>> = ({
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<FormContent />
|
<FormContent
|
||||||
|
nodeId={id}
|
||||||
|
value={inputs.form_content}
|
||||||
|
onChange={handleFormContentChange}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
{/* user actions */}
|
{/* user actions */}
|
||||||
<div className='px-4 py-2'>
|
<div className='px-4 py-2'>
|
||||||
|
|||||||
@ -1,8 +1,17 @@
|
|||||||
import type { CommonNodeType, Variable } from '@/app/components/workflow/types'
|
import type { CommonNodeType, InputVarType, ValueSelector, Variable } from '@/app/components/workflow/types'
|
||||||
|
|
||||||
export type HumanInputNodeType = CommonNodeType & {
|
export type HumanInputNodeType = CommonNodeType & {
|
||||||
delivery_methods: DeliveryMethod[]
|
delivery_methods: DeliveryMethod[]
|
||||||
form_content: any
|
form_content: string
|
||||||
|
form_input: {
|
||||||
|
type: InputVarType
|
||||||
|
output_variable_name: string
|
||||||
|
placeholder?: { // only text-input and paragraph support placeholder
|
||||||
|
type: 'variable' | 'const',
|
||||||
|
selector: ValueSelector
|
||||||
|
value: string
|
||||||
|
}
|
||||||
|
}[]
|
||||||
user_actions: UserAction[]
|
user_actions: UserAction[]
|
||||||
timeout: number
|
timeout: number
|
||||||
timeout_unit: 'hour' | 'day'
|
timeout_unit: 'hour' | 'day'
|
||||||
|
|||||||
@ -4,9 +4,11 @@ import useNodeCrud from '@/app/components/workflow/nodes/_base/hooks/use-node-cr
|
|||||||
import {
|
import {
|
||||||
useNodesReadOnly,
|
useNodesReadOnly,
|
||||||
} from '@/app/components/workflow/hooks'
|
} from '@/app/components/workflow/hooks'
|
||||||
|
import useFormContent from './use-form-content'
|
||||||
const useConfig = (id: string, payload: HumanInputNodeType) => {
|
const useConfig = (id: string, payload: HumanInputNodeType) => {
|
||||||
const { nodesReadOnly: readOnly } = useNodesReadOnly()
|
const { nodesReadOnly: readOnly } = useNodesReadOnly()
|
||||||
const { inputs, setInputs } = useNodeCrud<HumanInputNodeType>(id, payload)
|
const { inputs, setInputs } = useNodeCrud<HumanInputNodeType>(id, payload)
|
||||||
|
const formContentHook = useFormContent(id, payload)
|
||||||
|
|
||||||
const handleDeliveryMethodChange = (methods: DeliveryMethod[]) => {
|
const handleDeliveryMethodChange = (methods: DeliveryMethod[]) => {
|
||||||
setInputs({
|
setInputs({
|
||||||
@ -58,6 +60,7 @@ const useConfig = (id: string, payload: HumanInputNodeType) => {
|
|||||||
handleUserActionChange,
|
handleUserActionChange,
|
||||||
handleUserActionDelete,
|
handleUserActionDelete,
|
||||||
handleTimeoutChange,
|
handleTimeoutChange,
|
||||||
|
...formContentHook,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -0,0 +1,17 @@
|
|||||||
|
import useNodeCrud from '../_base/hooks/use-node-crud'
|
||||||
|
import type { HumanInputNodeType } from './types'
|
||||||
|
|
||||||
|
const useFormContent = (id: string, payload: HumanInputNodeType) => {
|
||||||
|
const { inputs, setInputs } = useNodeCrud<HumanInputNodeType>(id, payload)
|
||||||
|
const handleFormContentChange = (value: string) => {
|
||||||
|
setInputs({
|
||||||
|
...inputs,
|
||||||
|
form_content: value,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
handleFormContentChange,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default useFormContent
|
||||||
Loading…
Reference in New Issue
Block a user