From d6b66aeed8c307258a9186aa5f9ad468b430c3ba Mon Sep 17 00:00:00 2001 From: Joel Date: Mon, 10 Mar 2025 11:28:40 +0800 Subject: [PATCH] feat: picker panel main ui --- .../app/configuration/config/index.tsx | 10 ++- .../object-child-tree-panel/field.tsx | 41 +++++++++++ .../object-child-tree-panel/index.tsx | 41 +++++++++++ .../tree-indent-line.tsx | 21 ++++++ .../variable/object-children-tree-panel.tsx | 69 ------------------- 5 files changed, 111 insertions(+), 71 deletions(-) create mode 100644 web/app/components/workflow/nodes/_base/components/variable/object-child-tree-panel/field.tsx create mode 100644 web/app/components/workflow/nodes/_base/components/variable/object-child-tree-panel/index.tsx create mode 100644 web/app/components/workflow/nodes/_base/components/variable/object-child-tree-panel/tree-indent-line.tsx delete mode 100644 web/app/components/workflow/nodes/_base/components/variable/object-children-tree-panel.tsx diff --git a/web/app/components/app/configuration/config/index.tsx b/web/app/components/app/configuration/config/index.tsx index b0aed6babf..ffa724f6a0 100644 --- a/web/app/components/app/configuration/config/index.tsx +++ b/web/app/components/app/configuration/config/index.tsx @@ -17,7 +17,7 @@ import type { AppType } from '@/types/app' import { ModelModeType } from '@/types/app' import mockStructData from '@/app/components/workflow/nodes/llm/mock-struct-data' -import ObjectChildrenTreePanel from '@/app/components/workflow/nodes/_base/components/variable/object-children-tree-panel' +import ObjectChildrenTreePanel from '@/app/components/workflow/nodes/_base/components/variable/object-child-tree-panel' const Config: FC = () => { const { @@ -62,7 +62,13 @@ const Config: FC = () => {
- { }} /> +
+ { }} + /> +
{/* Template */} = ({ + name, + payload, + depth = 0, +}) => { + return ( +
+
+
+ +
{name}
+
+
{getFieldType(payload)}
+
+ {payload.type === Type.object && payload.properties && ( +
+ {Object.keys(payload.properties).map(name => ( + + ))} +
+ )} +
+ ) +} +export default React.memo(Field) diff --git a/web/app/components/workflow/nodes/_base/components/variable/object-child-tree-panel/index.tsx b/web/app/components/workflow/nodes/_base/components/variable/object-child-tree-panel/index.tsx new file mode 100644 index 0000000000..b7307c0256 --- /dev/null +++ b/web/app/components/workflow/nodes/_base/components/variable/object-child-tree-panel/index.tsx @@ -0,0 +1,41 @@ +'use client' +import type { FC } from 'react' +import React from 'react' +import type { Field as FieldType, StructuredOutput } from '../../../../llm/types' +import Field from './field' + +type Props = { + root: { nodeName: string, attrName: string } + payload: StructuredOutput + onSelect: (field: FieldType) => void +} + +const ObjectChildrenTreePanel: FC = ({ + root, + payload, +}) => { + const schema = payload.schema + const fieldNames = Object.keys(schema.properties) + return ( +
+ {/* Root info */} +
+
+
{root.nodeName}
+
.
+
{root.attrName}
+
+ {/* It must be object */} +
object
+
+ {fieldNames.map(name => ( + + ))} +
+ ) +} +export default React.memo(ObjectChildrenTreePanel) diff --git a/web/app/components/workflow/nodes/_base/components/variable/object-child-tree-panel/tree-indent-line.tsx b/web/app/components/workflow/nodes/_base/components/variable/object-child-tree-panel/tree-indent-line.tsx new file mode 100644 index 0000000000..cd5d3b3eca --- /dev/null +++ b/web/app/components/workflow/nodes/_base/components/variable/object-child-tree-panel/tree-indent-line.tsx @@ -0,0 +1,21 @@ +'use client' +import type { FC } from 'react' +import React from 'react' + +type Props = { + depth?: number +} + +const TreeIndentLine: FC = ({ + depth = 0, +}) => { + const depthArray = Array.from({ length: depth + 1 }, (_, index) => index) + return ( +
+ {depthArray.map(d => ( +
+ ))} +
+ ) +} +export default React.memo(TreeIndentLine) diff --git a/web/app/components/workflow/nodes/_base/components/variable/object-children-tree-panel.tsx b/web/app/components/workflow/nodes/_base/components/variable/object-children-tree-panel.tsx deleted file mode 100644 index 2438bab2f5..0000000000 --- a/web/app/components/workflow/nodes/_base/components/variable/object-children-tree-panel.tsx +++ /dev/null @@ -1,69 +0,0 @@ -'use client' -import type { FC } from 'react' -import React from 'react' -import type { Field as FieldType, StructuredOutput } from '../../../llm/types' -import { Type } from '../../../llm/types' -import { getFieldType } from '../../../llm/utils' -import cn from '@/utils/classnames' - -type Props = { - payload: StructuredOutput - onSelect: (field: FieldType) => void -} - -// TODO: depth can be depth 10. item 12 -const indentClassName: Record = { - 0: 'pl-[10px]', - 1: 'pl-[22px]', - 2: 'pl-[30px]', - 3: 'pl-[40px]', - 4: 'pl-[50px]', -} - -const Field: FC<{ name: string, payload: FieldType, depth?: number }> = ({ - name, - payload, - depth = 0, -}) => { - return ( -
-
- {/* indent line */} -
-
{name}
-
{getFieldType(payload)}
-
- {payload.type === Type.object && payload.properties && ( -
- {Object.keys(payload.properties).map(name => ( - - ))} -
- )} -
- ) -} - -const ObjectChildrenTreePanel: FC = ({ - payload, -}) => { - const schema = payload.schema - const fieldNames = Object.keys(schema.properties) - return ( -
- {fieldNames.map(name => ( - - ))} -
- ) -} -export default React.memo(ObjectChildrenTreePanel)