From ada558bedca4dde76d720ca5f93cb4b08a79db99 Mon Sep 17 00:00:00 2001 From: Joel Date: Mon, 19 Feb 2024 18:33:06 +0800 Subject: [PATCH] feat: add picker shower --- .../base/portal-to-follow-elem/index.tsx | 4 +- .../variable/var-reference-picker.tsx | 81 +++++++++++++------ .../variable/var-reference-popup.tsx | 33 ++++++++ .../components/workflow/nodes/llm/panel.tsx | 8 +- .../nodes/llm/{use-input.ts => use-config.ts} | 0 web/app/components/workflow/nodes/mock.ts | 32 +++++++- web/app/components/workflow/types.ts | 9 +++ 7 files changed, 135 insertions(+), 32 deletions(-) create mode 100644 web/app/components/workflow/nodes/_base/components/variable/var-reference-popup.tsx rename web/app/components/workflow/nodes/llm/{use-input.ts => use-config.ts} (100%) diff --git a/web/app/components/base/portal-to-follow-elem/index.tsx b/web/app/components/base/portal-to-follow-elem/index.tsx index 2100f2601d..46f4e1a40f 100644 --- a/web/app/components/base/portal-to-follow-elem/index.tsx +++ b/web/app/components/base/portal-to-follow-elem/index.tsx @@ -16,7 +16,7 @@ import { } from '@floating-ui/react' import type { OffsetOptions, Placement } from '@floating-ui/react' - +import cn from 'classnames' export type PortalToFollowElemOptions = { /* * top, bottom, left, right @@ -129,7 +129,7 @@ React.HTMLProps & { asChild?: boolean } return (
void } +// const toShowVarType = (type: string) => { +// if (['text-input', 'paragraph', 'select', 'url'].includes(type)) +// return 'String' + +// return type.charAt(0).toUpperCase() + type.substring(1) +// } + +// TODO: get data from context const getNodeInfoById = (id: string) => { return mockNodesData[id] } @@ -25,6 +40,7 @@ const VarReferencePicker: FC = ({ isShowNodeName, value, }) => { + const [open, setOpen] = useState(false) const hasValue = value.length > 0 const node = hasValue ? getNodeInfoById(value[0]) : null const varName = hasValue ? value[value.length - 1] : '' @@ -32,33 +48,48 @@ const VarReferencePicker: FC = ({ const getVarType = () => { return 'string' } + return (
-
-
- {hasValue && ( - <> - {isShowNodeName && ( -
-
- + + setOpen(!open)} className='!flex'> +
+
+ {hasValue && ( + <> + {isShowNodeName && ( +
+
+ +
+
{node?.title}
+ +
+ )} +
+ +
{varName}
-
{node?.title}
- -
+
{getVarType()}
+ )} -
- -
{varName}
-
-
{getVarType()}
- - )} -
-
+
+
+ + + + +
) } diff --git a/web/app/components/workflow/nodes/_base/components/variable/var-reference-popup.tsx b/web/app/components/workflow/nodes/_base/components/variable/var-reference-popup.tsx new file mode 100644 index 0000000000..1d08189723 --- /dev/null +++ b/web/app/components/workflow/nodes/_base/components/variable/var-reference-popup.tsx @@ -0,0 +1,33 @@ +'use client' +import type { FC } from 'react' +import React from 'react' +import type { NodeOutPutVar } from '@/app/components/workflow/types' +import { Variable02 } from '@/app/components/base/icons/src/vender/solid/development' + +type Props = { + vars: NodeOutPutVar[] +} + +const VarReferencePopup: FC = ({ + vars, +}) => { + return ( +
+ {vars.map((item, i) => ( +
+
{item.title}
+ {item.vars.map((v, j) => ( +
+
+ +
{v.variable}
+
+
{v.type}
+
+ ))} +
+ ))} +
+ ) +} +export default React.memo(VarReferencePopup) diff --git a/web/app/components/workflow/nodes/llm/panel.tsx b/web/app/components/workflow/nodes/llm/panel.tsx index 90c18ef297..0a2266149a 100644 --- a/web/app/components/workflow/nodes/llm/panel.tsx +++ b/web/app/components/workflow/nodes/llm/panel.tsx @@ -2,7 +2,7 @@ import type { FC } from 'react' import { useTranslation } from 'react-i18next' import BasePanel from '../_base/panel' import VarList from '../_base/components/variable/var-list' -import useInput from './use-input' +import useConfig from './use-config' import { mockLLMNodeData } from './mock' import Field from '@/app/components/workflow/nodes/_base/components/field' import AddButton from '@/app/components/base/button/add-button' @@ -23,10 +23,10 @@ const Panel: FC = () => { handleVarListChange, handleAddVariable, toggleContextEnabled, - } = useInput(mockLLMNodeData) + } = useConfig(mockLLMNodeData) const model = inputs.model - const modelMode = inputs.model?.mode - const isChatMode = modelMode === 'chat' + // const modelMode = inputs.model?.mode + // const isChatMode = modelMode === 'chat' return ( = { aaa: { title: 'Start', type: BlockEnum.Start, - }, bbb: { title: 'Knowledge', type: BlockEnum.KnowledgeRetrieval, }, + ccc: { + title: 'Code', + type: BlockEnum.Code, + }, } + +export const mockNodeOutputVars: NodeOutPutVar[] = [ + { + title: 'Start', + vars: [ + { + variable: 'query', + type: 'string', + }, + { + variable: 'age', + type: 'number', + }, + ], + }, + { + title: 'LLM', + vars: [ + { + variable: 'usage', + type: 'object', + struct: ['token', 'value'], + }, + ], + }, +] diff --git a/web/app/components/workflow/types.ts b/web/app/components/workflow/types.ts index 8fd1f35d8b..5b2c86fae1 100644 --- a/web/app/components/workflow/types.ts +++ b/web/app/components/workflow/types.ts @@ -83,6 +83,15 @@ export type LLMNodeData = { } } +export type NodeOutPutVar = { + title: string + vars: { + variable: string + type: string + struct?: string[] + }[] +} + export type Block = { classification?: string type: BlockEnum