node.tsx 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import type { FC } from 'react'
  2. import React from 'react'
  3. import { useNodes } from 'reactflow'
  4. import { useTranslation } from 'react-i18next'
  5. import NodeVariableItem from '../variable-assigner/components/node-variable-item'
  6. import { type DocExtractorNodeType } from './types'
  7. import { isConversationVar, isENV, isSystemVar } from '@/app/components/workflow/nodes/_base/components/variable/utils'
  8. import { BlockEnum, type Node, type NodeProps } from '@/app/components/workflow/types'
  9. const i18nPrefix = 'workflow.nodes.docExtractor'
  10. const NodeComponent: FC<NodeProps<DocExtractorNodeType>> = ({
  11. data,
  12. }) => {
  13. const { t } = useTranslation()
  14. const nodes: Node[] = useNodes()
  15. const { variable_selector: variable } = data
  16. if (!variable || variable.length === 0)
  17. return null
  18. const isSystem = isSystemVar(variable)
  19. const isEnv = isENV(variable)
  20. const isChatVar = isConversationVar(variable)
  21. const node = isSystem ? nodes.find(node => node.data.type === BlockEnum.Start) : nodes.find(node => node.id === variable[0])
  22. const varName = isSystem ? `sys.${variable[variable.length - 1]}` : variable.slice(1).join('.')
  23. return (
  24. <div className='relative px-3'>
  25. <div className='mb-1 system-2xs-medium-uppercase text-text-tertiary'>{t(`${i18nPrefix}.inputVar`)}</div>
  26. <NodeVariableItem
  27. node={node as Node}
  28. isEnv={isEnv}
  29. isChatVar={isChatVar}
  30. varName={varName}
  31. className='bg-workflow-block-parma-bg'
  32. />
  33. </div>
  34. )
  35. }
  36. export default React.memo(NodeComponent)