-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharray-group-node.tsx
More file actions
99 lines (90 loc) · 3.32 KB
/
Copy patharray-group-node.tsx
File metadata and controls
99 lines (90 loc) · 3.32 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import { Handle, Position, useNodeConnections, type Node } from '@xyflow/react'
import type { CustomNodeData } from '~/types/datamapper_types/react-node-types'
import HighlightButton from '../basic-components/highlight-button'
import DeleteButton from '../basic-components/delete-button'
import clsx from 'clsx'
import VariableTypeIcon from '../basic-components/variable-type-icon'
export type ArrayGroupNodeProperties = {
id: string
data: CustomNodeData
variant?: 'source' | 'target'
onDelete?: (id: string) => void
onHighlight?: (id: string) => void
}
function ArrayGroupNode({ id, data, variant = 'source', onDelete, onHighlight }: ArrayGroupNodeProperties) {
const checked = data?.checked
const connections = useNodeConnections({
id,
})
const isConnectable = connections.length === 0 || variant === 'source'
const updateChecked = () => {
const newChecked = !checked
data.setNodes?.((nodes: Node[]) =>
nodes.map((node) => (node.id === id ? { ...node, data: { ...node.data, checked: newChecked } } : node)),
)
if (variant != 'source') {
data.setNodes?.((nodes: Node[]) =>
nodes.map((node) =>
node.id !== id && node.parentId?.includes('target')
? { ...node, data: { ...node.data, checked: false } }
: node,
),
)
}
}
return (
<div
onClick={updateChecked}
className={clsx(
'group h-full cursor-pointer',
checked ? 'border-foreground-active border-rounded rounded-md border-4' : 'border-none',
data.isHidden && 'opacity-20',
)}
>
<div
className="bg-selected relative flex h-full flex-col gap-1 rounded-md border border-gray-400 p-0"
style={{ width: `${data.width}px` }}
>
{/* Header */}
<div className="bg-backdrop flex w-full gap-2 rounded-md px-2 py-2">
<span className="shrink-0">
<Handle
key={variant}
type={variant}
position={variant === 'source' ? Position.Right : Position.Left}
isConnectable={isConnectable}
style={{
width: 10,
height: 10,
top: '20px',
}} //Can't set this with tailwind for some reason
className={`${variant == 'source' ? '' : 'translate-x-1.25'} relative ${isConnectable ? 'opacity-100' : 'opacity-0'} `}
/>
<Handle
key={variant === 'source' ? 'target' : 'source'}
type={variant === 'source' ? 'target' : 'source'}
position={variant === 'source' ? Position.Left : Position.Right}
className="pointer-events-none h-0 w-0 opacity-0"
/>
<VariableTypeIcon variableType={data.variableType} variableTypeBasic={data.variableTypeBasic ?? ''} />
</span>
<div className="min-w-0 flex-1 truncate rounded-md text-left">{data.label}</div>
<div className="hidden gap-3 group-hover:flex">
<HighlightButton
onClick={() => {
onHighlight?.(id)
}}
/>
<DeleteButton
onClick={() => {
onDelete?.(id)
}}
/>
</div>
</div>
{/* Hidden opposite handle */}
</div>
</div>
)
}
export default ArrayGroupNode