diff --git a/web/app/components/base/prompt-editor/index.tsx b/web/app/components/base/prompt-editor/index.tsx index e77dce4b66..362da77d0c 100644 --- a/web/app/components/base/prompt-editor/index.tsx +++ b/web/app/components/base/prompt-editor/index.tsx @@ -51,6 +51,7 @@ import type { export type PromptEditorProps = { className?: string + placeholder?: string style?: React.CSSProperties value?: string editable?: boolean @@ -99,6 +100,7 @@ export type PromptEditorProps = { const PromptEditor: FC = ({ className, + placeholder, style, value, editable = true, @@ -139,7 +141,7 @@ const PromptEditor: FC = ({ show: true, selectable: true, variables: [], - getWorkflowNode: () => {}, + getWorkflowNode: () => { }, onInsert: () => { }, onDelete: () => { }, }, @@ -189,7 +191,7 @@ const PromptEditor: FC = ({
} - placeholder={} + placeholder={} ErrorBoundary={LexicalErrorBoundary} /> { +const Placeholder = ({ + value, +}: { + value?: string +}) => { const { t } = useTranslation() return (
- {t('common.promptEditor.placeholder')} + {value || t('common.promptEditor.placeholder')}
) } diff --git a/web/app/components/workflow/nodes/_base/components/input-support-select-var.tsx b/web/app/components/workflow/nodes/_base/components/input-support-select-var.tsx new file mode 100644 index 0000000000..3646b2af07 --- /dev/null +++ b/web/app/components/workflow/nodes/_base/components/input-support-select-var.tsx @@ -0,0 +1,95 @@ +'use client' +import type { FC } from 'react' +import React, { useEffect } from 'react' +import cn from 'classnames' +import { useBoolean } from 'ahooks' +import { useWorkflow } from '@/app/components/workflow/hooks' +import type { NodeOutPutVar } from '@/app/components/workflow/types' +import PromptEditor from '@/app/components/base/prompt-editor' +type Props = { + className?: string + placeholder?: string + promptMinHeightClassName?: string + value: string + onChange: (value: string) => void + onFocusChange?: (value: boolean) => void + readOnly?: boolean + justVar?: boolean + nodesOutputVars?: NodeOutPutVar[] +} + +const Editor: FC = ({ + className, + placeholder, + promptMinHeightClassName = 'min-h-[30px]', + value, + onChange, + onFocusChange, + readOnly, + nodesOutputVars, +}) => { + // const { t } = useTranslation() + const { getNode } = useWorkflow() + + const [isFocus, { + setTrue: setFocus, + setFalse: setBlur, + }] = useBoolean(false) + + useEffect(() => { + onFocusChange?.(isFocus) + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [isFocus]) + + return ( +
+ <> + { }, + }} + variableBlock={{ + variables: [], + externalTools: [], + onAddExternalTool: () => { }, + }} + historyBlock={{ + show: false, + selectable: false, + history: { + user: 'Human', + assistant: 'Assistant', + }, + onEditRole: () => { }, + }} + queryBlock={{ + show: false, + selectable: false, + }} + workflowVariableBlock={{ + show: true, + selectable: true, + variables: nodesOutputVars || [], + getWorkflowNode: getNode, + }} + onChange={onChange} + editable={!readOnly} + onBlur={setBlur} + onFocus={setFocus} + /> + {/* to patch Editor not support dynamic change editable status */} + {readOnly &&
} + +
+ ) +} +export default React.memo(Editor) diff --git a/web/app/components/workflow/nodes/_base/components/prompt/editor.tsx b/web/app/components/workflow/nodes/_base/components/prompt/editor.tsx index 58e44efa59..7523cfe901 100644 --- a/web/app/components/workflow/nodes/_base/components/prompt/editor.tsx +++ b/web/app/components/workflow/nodes/_base/components/prompt/editor.tsx @@ -53,8 +53,6 @@ const Editor: FC = ({ const { t } = useTranslation() const { getNode } = useWorkflow() - console.log(nodesOutputVars, '2') - const isShowHistory = !isChatModel && isChatApp const isShowQuery = isShowHistory diff --git a/web/app/components/workflow/nodes/http/components/api-input.tsx b/web/app/components/workflow/nodes/http/components/api-input.tsx index b2cd23dc06..982a265767 100644 --- a/web/app/components/workflow/nodes/http/components/api-input.tsx +++ b/web/app/components/workflow/nodes/http/components/api-input.tsx @@ -1,12 +1,14 @@ 'use client' import type { FC } from 'react' -import React, { useCallback, useEffect, useRef } from 'react' +import React, { useEffect, useRef, useState } from 'react' import cn from 'classnames' -import { useBoolean } from 'ahooks' import { Method } from '../types' import Selector from '../../_base/components/selector' +import useAvailableVarList from '../../_base/hooks/use-available-var-list' +import { VarType } from '../../../types' +import type { Var } from '../../../types' +import Input from '@/app/components/workflow/nodes/_base/components/input-support-select-var' import { ChevronDown } from '@/app/components/base/icons/src/vender/line/arrows' -import SupportVarInput from '@/app/components/workflow/nodes/_base/components/support-var-input' const MethodOptions = [ { label: 'GET', value: Method.get }, @@ -17,6 +19,7 @@ const MethodOptions = [ { label: 'DELETE', value: Method.delete }, ] type Props = { + nodeId: string readonly: boolean method: Method onMethodChange: (method: Method) => void @@ -25,27 +28,28 @@ type Props = { } const ApiInput: FC = ({ + nodeId, readonly, method, onMethodChange, url, onUrlChange, }) => { - const handleUrlChange = useCallback((e: React.ChangeEvent) => { - onUrlChange(e.target.value) - }, [onUrlChange]) - const inputRef = useRef(null) - const [isFocus, { - setTrue: onFocus, - setFalse: onBlur, - }] = useBoolean(false) + const [isFocus, setIsFocus] = useState(false) + const availableVarList = useAvailableVarList(nodeId, { + onlyLeafNodeVar: false, + filterVar: (varPayload: Var) => { + return [VarType.string, VarType.number].includes(varPayload.type) + }, + }) + useEffect(() => { if (isFocus) inputRef.current?.focus() }, [isFocus]) return ( -
+
= ({ showChecked readonly={readonly} /> - - = ({ onBlur={onBlur} className='w-full h-6 leading-6 px-2.5 border-0 text-gray-900 text-[13px] placeholder:text-gray-400 focus:outline-none' ref={inputRef} - /> - + /> */} +
) } diff --git a/web/app/components/workflow/nodes/http/panel.tsx b/web/app/components/workflow/nodes/http/panel.tsx index 1084c3a3e2..c40dac62ca 100644 --- a/web/app/components/workflow/nodes/http/panel.tsx +++ b/web/app/components/workflow/nodes/http/panel.tsx @@ -94,6 +94,7 @@ const Panel: FC> = ({ } >