feat: add form content editor

This commit is contained in:
Joel 2025-08-07 18:28:08 +08:00
parent bd7ba85471
commit e2e5dedceb
6 changed files with 91 additions and 7 deletions

View File

@ -259,8 +259,7 @@ const PromptEditor: FC<PromptEditorProps> = ({
)
}
{
// TODO: test hitlInputBlock?.show
(
hitlInputBlock?.show && (
<>
<HITLInputBlock />
<HITLInputBlockReplacementBlock />

View File

@ -1,16 +1,67 @@
'use client'
import PromptEditor from '@/app/components/base/prompt-editor'
import type { FC } 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 = {
nodeId: string
value: string
onChange: (value: string) => void
}
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 (
<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>
)
}

View File

@ -33,6 +33,7 @@ const Panel: FC<NodePanelProps<HumanInputNodeType>> = ({
handleUserActionChange,
handleUserActionDelete,
handleTimeoutChange,
handleFormContentChange,
} = useConfig(id, data)
const { availableVars, availableNodesWithParent } = useAvailableVarList(id, {
@ -64,7 +65,11 @@ const Panel: FC<NodePanelProps<HumanInputNodeType>> = ({
/>
</div>
</div>
<FormContent />
<FormContent
nodeId={id}
value={inputs.form_content}
onChange={handleFormContentChange}
/>
</div>
{/* user actions */}
<div className='px-4 py-2'>

View File

@ -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 & {
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[]
timeout: number
timeout_unit: 'hour' | 'day'

View File

@ -4,9 +4,11 @@ import useNodeCrud from '@/app/components/workflow/nodes/_base/hooks/use-node-cr
import {
useNodesReadOnly,
} from '@/app/components/workflow/hooks'
import useFormContent from './use-form-content'
const useConfig = (id: string, payload: HumanInputNodeType) => {
const { nodesReadOnly: readOnly } = useNodesReadOnly()
const { inputs, setInputs } = useNodeCrud<HumanInputNodeType>(id, payload)
const formContentHook = useFormContent(id, payload)
const handleDeliveryMethodChange = (methods: DeliveryMethod[]) => {
setInputs({
@ -58,6 +60,7 @@ const useConfig = (id: string, payload: HumanInputNodeType) => {
handleUserActionChange,
handleUserActionDelete,
handleTimeoutChange,
...formContentHook,
}
}

View File

@ -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