diff --git a/web/app/components/workflow/nodes/_base/components/variable/object-child-tree-panel/picker/field.tsx b/web/app/components/workflow/nodes/_base/components/variable/object-child-tree-panel/picker/field.tsx index 17fdf29b64..2a940f75e3 100644 --- a/web/app/components/workflow/nodes/_base/components/variable/object-child-tree-panel/picker/field.tsx +++ b/web/app/components/workflow/nodes/_base/components/variable/object-child-tree-panel/picker/field.tsx @@ -12,25 +12,34 @@ import { useTranslation } from 'react-i18next' const MAX_DEPTH = 10 -type Props = { name: string, payload: FieldType, depth?: number } +type Props = { + name: string, + payload: FieldType, + depth?: number + readonly?: boolean +} const Field: FC = ({ name, payload, depth = 1, + readonly, }) => { const { t } = useTranslation() + const isLastFieldHighlight = readonly + const hasChildren = payload.type === Type.object && payload.properties + const isHighlight = isLastFieldHighlight && !hasChildren if (depth > MAX_DEPTH + 1) return null return (
-
+
{depth === MAX_DEPTH + 1 ? ( - ) : (
{name}
)} + ) : (
{name}
)}
{depth < MAX_DEPTH + 1 && ( @@ -47,6 +56,7 @@ const Field: FC = ({ name={name} payload={payload.properties?.[name] as FieldType} depth={depth + 1} + readonly={readonly} /> ))}
diff --git a/web/app/components/workflow/nodes/_base/components/variable/object-child-tree-panel/picker/index.tsx b/web/app/components/workflow/nodes/_base/components/variable/object-child-tree-panel/picker/index.tsx index 119ec1140a..fbcd7c379e 100644 --- a/web/app/components/workflow/nodes/_base/components/variable/object-child-tree-panel/picker/index.tsx +++ b/web/app/components/workflow/nodes/_base/components/variable/object-child-tree-panel/picker/index.tsx @@ -3,26 +3,35 @@ import type { FC } from 'react' import React from 'react' import type { Field as FieldType, StructuredOutput } from '../../../../../llm/types' import Field from './field' +import cn from '@/utils/classnames' type Props = { - root: { nodeName: string, attrName: string } + className?: string + root: { nodeName?: string, attrName: string } payload: StructuredOutput - onSelect: (field: FieldType) => void + readonly?: boolean + onSelect?: (field: FieldType) => void } -const PickerPanel: FC = ({ +export const PickerPanelMain: FC = ({ + className, root, payload, + readonly, }) => { const schema = payload.schema const fieldNames = Object.keys(schema.properties) return ( -
+
{/* Root info */}
-
{root.nodeName}
-
.
+ {root.nodeName && ( + <> +
{root.nodeName}
+
.
+ + )}
{root.attrName}
{/* It must be object */} @@ -33,9 +42,21 @@ const PickerPanel: FC = ({ key={name} name={name} payload={schema.properties[name]} + readonly={readonly} /> ))}
) } + +const PickerPanel: FC = ({ + className, + ...props +}) => { + return ( +
+ +
+ ) +} export default React.memo(PickerPanel) diff --git a/web/app/components/workflow/nodes/_base/components/variable/object-child-tree-panel/test.tsx b/web/app/components/workflow/nodes/_base/components/variable/object-child-tree-panel/test.tsx index 4ab6307e16..43db2ac205 100644 --- a/web/app/components/workflow/nodes/_base/components/variable/object-child-tree-panel/test.tsx +++ b/web/app/components/workflow/nodes/_base/components/variable/object-child-tree-panel/test.tsx @@ -2,12 +2,19 @@ import type { FC } from 'react' import React from 'react' import mockStructData from '@/app/components/workflow/nodes/llm/mock-struct-data' +import VarFullPathPanel from '../var-full-path-panel' import PickerPanel from '@/app/components/workflow/nodes/_base/components/variable/object-child-tree-panel/picker' import ShowPanel from '@/app/components/workflow/nodes/_base/components/variable/object-child-tree-panel/show' +import { Type } from '../../../../llm/types' const Test: FC = () => { return ( -
+
+
= ({ + nodeName, + path, + varType, +}) => { + const schema: StructuredOutput = (() => { + const schema: StructuredOutput['schema'] = { + type: Type.object, + properties: {} as { [key: string]: Field }, + required: [], + additionalProperties: false, + } + let current = schema + for (let i = 0; i < path.length; i++) { + const isLast = i === path.length - 1 + const name = path[i] + current.properties[name] = { + type: isLast ? varType : Type.object, + properties: {}, + } as Field + current = current.properties[name] as { type: Type.object; properties: { [key: string]: Field; }; required: never[]; additionalProperties: false; } + } + return { + schema, + } + })() + return ( +
+
+ +
{nodeName}
+
+ +
+ ) +} +export default React.memo(VarFullPathPanel)