fix: get vartype not pass caused page crash

This commit is contained in:
Joel 2025-03-26 15:16:54 +08:00
parent 7fc39d9d80
commit 5b54ff5ae4
4 changed files with 22 additions and 13 deletions

View File

@ -29,14 +29,14 @@ import { isConversationVar, isENV, isSystemVar } from '@/app/components/workflow
import Tooltip from '@/app/components/base/tooltip' import Tooltip from '@/app/components/base/tooltip'
import { isExceptionVariable } from '@/app/components/workflow/utils' import { isExceptionVariable } from '@/app/components/workflow/utils'
import VarFullPathPanel from '@/app/components/workflow/nodes/_base/components/variable/var-full-path-panel' import VarFullPathPanel from '@/app/components/workflow/nodes/_base/components/variable/var-full-path-panel'
import type { Type } from '@/app/components/workflow/nodes/llm/types' import { Type } from '@/app/components/workflow/nodes/llm/types'
import type { ValueSelector } from '@/app/components/workflow/types' import type { ValueSelector } from '@/app/components/workflow/types'
type WorkflowVariableBlockComponentProps = { type WorkflowVariableBlockComponentProps = {
nodeKey: string nodeKey: string
variables: string[] variables: string[]
workflowNodesMap: WorkflowNodesMap workflowNodesMap: WorkflowNodesMap
getVarType: (payload: { getVarType?: (payload: {
nodeId: string, nodeId: string,
valueSelector: ValueSelector, valueSelector: ValueSelector,
}) => Type }) => Type
@ -143,6 +143,9 @@ const WorkflowVariableBlockComponent = ({
) )
} }
if (!node)
return null
return ( return (
<Tooltip <Tooltip
noDecoration noDecoration
@ -150,10 +153,10 @@ const WorkflowVariableBlockComponent = ({
<VarFullPathPanel <VarFullPathPanel
nodeName={node.title} nodeName={node.title}
path={variables.slice(1)} path={variables.slice(1)}
varType={getVarType({ varType={getVarType ? getVarType({
nodeId: variables[0], nodeId: variables[0],
valueSelector: variables, valueSelector: variables,
})} }) : Type.string}
nodeType={node?.type} nodeType={node?.type}
/>} />}
disabled={!isShowAPart} disabled={!isShowAPart}

View File

@ -9,7 +9,7 @@ import {
} from 'lexical' } from 'lexical'
import { mergeRegister } from '@lexical/utils' import { mergeRegister } from '@lexical/utils'
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext' import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext'
import type { WorkflowVariableBlockType } from '../../types' import type { GetVarType, WorkflowVariableBlockType } from '../../types'
import { import {
$createWorkflowVariableBlockNode, $createWorkflowVariableBlockNode,
WorkflowVariableBlockNode, WorkflowVariableBlockNode,
@ -25,7 +25,7 @@ export type WorkflowVariableBlockProps = {
getWorkflowNode: (nodeId: string) => Node getWorkflowNode: (nodeId: string) => Node
onInsert?: () => void onInsert?: () => void
onDelete?: () => void onDelete?: () => void
getVarType: any getVarType: GetVarType
} }
const WorkflowVariableBlock = memo(({ const WorkflowVariableBlock = memo(({
workflowNodesMap, workflowNodesMap,

View File

@ -2,18 +2,20 @@ import type { LexicalNode, NodeKey, SerializedLexicalNode } from 'lexical'
import { DecoratorNode } from 'lexical' import { DecoratorNode } from 'lexical'
import type { WorkflowVariableBlockType } from '../../types' import type { WorkflowVariableBlockType } from '../../types'
import WorkflowVariableBlockComponent from './component' import WorkflowVariableBlockComponent from './component'
import type { GetVarType } from '../../types'
export type WorkflowNodesMap = WorkflowVariableBlockType['workflowNodesMap'] export type WorkflowNodesMap = WorkflowVariableBlockType['workflowNodesMap']
export type SerializedNode = SerializedLexicalNode & { export type SerializedNode = SerializedLexicalNode & {
variables: string[] variables: string[]
workflowNodesMap: WorkflowNodesMap workflowNodesMap: WorkflowNodesMap
getVarType: any getVarType?: GetVarType
} }
export class WorkflowVariableBlockNode extends DecoratorNode<React.JSX.Element> { export class WorkflowVariableBlockNode extends DecoratorNode<React.JSX.Element> {
__variables: string[] __variables: string[]
__workflowNodesMap: WorkflowNodesMap __workflowNodesMap: WorkflowNodesMap
__getVarType: any __getVarType?: GetVarType
static getType(): string { static getType(): string {
return 'workflow-variable-block' return 'workflow-variable-block'
@ -68,6 +70,7 @@ export class WorkflowVariableBlockNode extends DecoratorNode<React.JSX.Element>
version: 1, version: 1,
variables: this.getVariables(), variables: this.getVariables(),
workflowNodesMap: this.getWorkflowNodesMap(), workflowNodesMap: this.getWorkflowNodesMap(),
getVarType: this.getVarType(),
} }
} }
@ -90,7 +93,7 @@ export class WorkflowVariableBlockNode extends DecoratorNode<React.JSX.Element>
return `{{#${this.getVariables().join('.')}#}}` return `{{#${this.getVariables().join('.')}#}}`
} }
} }
export function $createWorkflowVariableBlockNode(variables: string[], workflowNodesMap: WorkflowNodesMap, getVarType: any): WorkflowVariableBlockNode { export function $createWorkflowVariableBlockNode(variables: string[], workflowNodesMap: WorkflowNodesMap, getVarType?: GetVarType): WorkflowVariableBlockNode {
return new WorkflowVariableBlockNode(variables, workflowNodesMap, getVarType) return new WorkflowVariableBlockNode(variables, workflowNodesMap, getVarType)
} }

View File

@ -1,3 +1,4 @@
import type { Type } from '../../workflow/nodes/llm/types'
import type { Dataset } from './plugins/context-block' import type { Dataset } from './plugins/context-block'
import type { RoleName } from './plugins/history-block' import type { RoleName } from './plugins/history-block'
import type { import type {
@ -55,16 +56,18 @@ export type ExternalToolBlockType = {
onAddExternalTool?: () => void onAddExternalTool?: () => void
} }
export type GetVarType = (payload: {
nodeId: string,
valueSelector: ValueSelector,
}) => Type
export type WorkflowVariableBlockType = { export type WorkflowVariableBlockType = {
show?: boolean show?: boolean
variables?: NodeOutPutVar[] variables?: NodeOutPutVar[]
workflowNodesMap?: Record<string, Pick<Node['data'], 'title' | 'type'>> workflowNodesMap?: Record<string, Pick<Node['data'], 'title' | 'type'>>
onInsert?: () => void onInsert?: () => void
onDelete?: () => void onDelete?: () => void
getVarType?: (payload: { getVarType?: GetVarType
nodeId: string,
valueSelector: ValueSelector,
}) => string
} }
export type MenuTextMatch = { export type MenuTextMatch = {