File size: 1,584 Bytes
a8b3f00
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import type { FC } from 'react'
import {
  memo,
  useMemo,
  useRef,
} from 'react'
import type { NodeProps } from 'reactflow'
import { useTranslation } from 'react-i18next'
import NodeGroupItem from './components/node-group-item'
import type { VariableAssignerNodeType } from './types'

const i18nPrefix = 'workflow.nodes.variableAssigner'

const Node: FC<NodeProps<VariableAssignerNodeType>> = (props) => {
  const { t } = useTranslation()
  const ref = useRef<HTMLDivElement>(null)
  const { id, data } = props
  const { advanced_settings } = data

  const groups = useMemo(() => {
    if (!advanced_settings?.group_enabled) {
      return [{
        groupEnabled: false,
        targetHandleId: 'target',
        title: t(`${i18nPrefix}.title`),
        type: data.output_type,
        variables: data.variables,
        variableAssignerNodeId: id,
        variableAssignerNodeData: data,
      }]
    }
    return advanced_settings.groups.map((group) => {
      return {
        groupEnabled: true,
        targetHandleId: group.groupId,
        title: group.group_name,
        type: group.output_type,
        variables: group.variables,
        variableAssignerNodeId: id,
        variableAssignerNodeData: data,
      }
    })
  }, [t, advanced_settings, data, id])

  return (
    <div className='relative mb-1 px-1 space-y-0.5' ref={ref}>
      {
        groups.map((item) => {
          return (
            <NodeGroupItem
              key={item.title}
              item={item}
            />
          )
        })
      }
    </div >
  )
}

export default memo(Node)