import type { FC } from 'react' import type { HumanInputNodeType } from './types' import type { NodePanelProps, Var } from '@/app/components/workflow/types' import { RiAddLine, RiClipboardLine, RiCollapseDiagonalLine, RiExpandDiagonalLine, RiEyeLine, } from '@remixicon/react' import { useBoolean } from 'ahooks' import copy from 'copy-to-clipboard' import * as React from 'react' import { useCallback } from 'react' import { useTranslation } from 'react-i18next' import ActionButton from '@/app/components/base/action-button' import Button from '@/app/components/base/button' import Divider from '@/app/components/base/divider' import Toast from '@/app/components/base/toast' import Tooltip from '@/app/components/base/tooltip' import OutputVars, { VarItem } from '@/app/components/workflow/nodes/_base/components/output-vars' import Split from '@/app/components/workflow/nodes/_base/components/split' import useAvailableVarList from '@/app/components/workflow/nodes/_base/hooks/use-available-var-list' import { useStore } from '@/app/components/workflow/store' import { VarType } from '@/app/components/workflow/types' import { cn } from '@/utils/classnames' import DeliveryMethod from './components/delivery-method' import FormContent from './components/form-content' import FormContentPreview from './components/form-content-preview' import TimeoutInput from './components/timeout' import UserActionItem from './components/user-action' import useConfig from './hooks/use-config' import { UserActionButtonType } from './types' const i18nPrefix = 'nodes.humanInput' const Panel: FC> = ({ id, data, }) => { const { t } = useTranslation() const { readOnly, inputs, handleDeliveryMethodChange, handleUserActionAdd, handleUserActionChange, handleUserActionDelete, handleTimeoutChange, handleFormContentChange, handleFormInputsChange, handleFormInputItemRename, handleFormInputItemRemove, editorKey, structuredOutputCollapsed, setStructuredOutputCollapsed, } = useConfig(id, data) const { availableVars, availableNodesWithParent } = useAvailableVarList(id, { onlyLeafNodeVar: false, filterVar: (varPayload: Var) => { return [VarType.string, VarType.number, VarType.secret].includes(varPayload.type) }, }) const [isExpandFormContent, { toggle: toggleExpandFormContent, }] = useBoolean(false) const nodePanelWidth = useStore(state => state.nodePanelWidth) const [isPreview, { toggle: togglePreview, setFalse: hidePreview, }] = useBoolean(false) const onAddUseAction = useCallback(() => { const index = inputs.user_actions.length + 1 handleUserActionAdd({ id: `action_${index}`, title: `Button Text ${index}`, button_style: UserActionButtonType.Default, }) }, [handleUserActionAdd, inputs.user_actions.length]) return (
{/* delivery methods */}
{/* form content */}
{t(`${i18nPrefix}.formContent.title`, { ns: 'workflow' })}
{!readOnly && (
{ copy(inputs.form_content) Toast.notify({ type: 'success', message: t('actionMsg.copySuccessfully', { ns: 'common' }) }) }} >
{isExpandFormContent ? : }
)}
{/* user actions */}
{t(`${i18nPrefix}.userActions.title`, { ns: 'workflow' })}
{!readOnly && (
)}
{!inputs.user_actions.length && (
{t(`${i18nPrefix}.userActions.emptyTip`, { ns: 'workflow' })}
)} {inputs.user_actions.length > 0 && (
{inputs.user_actions.map((action, index) => ( handleUserActionChange(index, data)} onDelete={handleUserActionDelete} readonly={readOnly} /> ))}
)}
{/* timeout */}
{t(`${i18nPrefix}.timeout.title`, { ns: 'workflow' })}
{/* output vars */} { inputs.inputs.map(input => ( )) } {isPreview && ( )}
) } export default React.memo(Panel)