From 62e2deafcacce305f537334065066994818c9568 Mon Sep 17 00:00:00 2001 From: Joel Date: Tue, 20 Feb 2024 11:23:23 +0800 Subject: [PATCH] feat: infinite choose var --- .../variable/var-reference-picker.tsx | 2 +- .../variable/var-reference-popup.tsx | 83 ++++++++++++++++--- web/app/components/workflow/nodes/mock.ts | 39 ++++++++- web/app/components/workflow/types.ts | 12 +-- 4 files changed, 119 insertions(+), 17 deletions(-) diff --git a/web/app/components/workflow/nodes/_base/components/variable/var-reference-picker.tsx b/web/app/components/workflow/nodes/_base/components/variable/var-reference-picker.tsx index 3eb27b2185..2506215cac 100644 --- a/web/app/components/workflow/nodes/_base/components/variable/var-reference-picker.tsx +++ b/web/app/components/workflow/nodes/_base/components/variable/var-reference-picker.tsx @@ -85,7 +85,7 @@ const VarReferencePicker: FC = ({ 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 index 1d08189723..9f8a7c927a 100644 --- 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 @@ -1,13 +1,77 @@ 'use client' import type { FC } from 'react' -import React from 'react' -import type { NodeOutPutVar } from '@/app/components/workflow/types' +import React, { useRef } from 'react' +import { useHover } from 'ahooks' +import type { NodeOutPutVar, Var } from '@/app/components/workflow/types' import { Variable02 } from '@/app/components/base/icons/src/vender/solid/development' +type ObjectChildrenProps = { + title: string + data: Var[] + objPath: string[] +} + +type ItemProps = { + title: string + objPath: string[] + itemData: Var +} + +const Item: FC = ({ + title, + objPath, + itemData, +}) => { + const isObj = itemData.type === 'object' + const itemRef = useRef(null) + const isItemHovering = useHover(itemRef) + + return ( +
+
+ +
{itemData.variable}
+
+
{itemData.type}
+ {isObj && isItemHovering && ( + // eslint-disable-next-line @typescript-eslint/no-use-before-define + + )} +
+ ) +} + +const ObjectChildren: FC = ({ + title, + objPath, + data, +}) => { + const currObjPath = objPath + + return ( +
+
{title}.{currObjPath.join('.')}
+ { + data.map((v, i) => ( + + )) + } +
+ ) +} + type Props = { vars: NodeOutPutVar[] } - const VarReferencePopup: FC = ({ vars, }) => { @@ -17,13 +81,12 @@ const VarReferencePopup: FC = ({
{item.title}
{item.vars.map((v, j) => ( -
-
- -
{v.variable}
-
-
{v.type}
-
+ ))}
))} diff --git a/web/app/components/workflow/nodes/mock.ts b/web/app/components/workflow/nodes/mock.ts index ca693a73b7..598808fec8 100644 --- a/web/app/components/workflow/nodes/mock.ts +++ b/web/app/components/workflow/nodes/mock.ts @@ -36,7 +36,44 @@ export const mockNodeOutputVars: NodeOutPutVar[] = [ { variable: 'usage', type: 'object', - struct: ['token', 'value'], + children: [ + { + variable: 'token', + type: 'object', + children: [ + { + variable: 'num', + type: 'number', + }, + { + variable: 'price', + type: 'number', + }, + ], + }, + ], + }, + { + variable: 'other', + type: 'object', + children: [ + { + variable: 'a', + type: 'object', + children: [ + { + variable: 'b', + type: 'object', + children: [ + { + variable: 'c', + type: 'string', + }, + ], + }, + ], + }, + ], }, ], }, diff --git a/web/app/components/workflow/types.ts b/web/app/components/workflow/types.ts index 5b2c86fae1..7291fc5aee 100644 --- a/web/app/components/workflow/types.ts +++ b/web/app/components/workflow/types.ts @@ -83,13 +83,15 @@ export type LLMNodeData = { } } +export type Var = { + variable: string + type: string + children?: Var[] // if type is obj, has the children struct +} + export type NodeOutPutVar = { title: string - vars: { - variable: string - type: string - struct?: string[] - }[] + vars: Var[] } export type Block = {