import type { GroupHandler, GroupMember, GroupNodeData } from './types' import type { BlockEnum, NodeProps } from '@/app/components/workflow/types' import { RiArrowRightSLine } from '@remixicon/react' import { memo, useMemo } from 'react' import BlockIcon from '@/app/components/workflow/block-icon' import { cn } from '@/utils/classnames' import { NodeSourceHandle } from '../_base/components/node-handle' const MAX_MEMBER_ICONS = 12 const GroupNode = (props: NodeProps) => { const { data } = props // show the explicitly passed members first; otherwise use the _children information to fill the type const members: GroupMember[] = useMemo(() => ( data.members?.length ? data.members : data._children?.length ? data._children.map(child => ({ id: child.nodeId, type: child.nodeType as BlockEnum, label: child.nodeType, })) : [] ), [data._children, data.members]) // handler 列表:优先使用传入的 handlers,缺省时用 members 的 label 填充。 const handlers: GroupHandler[] = useMemo(() => ( data.handlers?.length ? data.handlers : members.length ? members.map(member => ({ id: member.id, label: member.label || member.id, })) : [] ), [data.handlers, members]) return (
{members.length > 0 && (
{members.slice(0, MAX_MEMBER_ICONS).map(member => (
))} {members.length > MAX_MEMBER_ICONS && (
+ {members.length - MAX_MEMBER_ICONS}
)}
)} {handlers.length > 0 && (
{handlers.map(handler => (
{handler.label || handler.id}
))}
)}
) } GroupNode.displayName = 'GroupNode' export default memo(GroupNode)