1- import { isNil , isArrayNotEmpty , isNotNil } from '@utils/index'
1+ import { isNil , isArrayNotEmpty , isNotNil , toID } from '@utils/index'
22import clsx from 'clsx'
33import { useMemo , useCallback , useState } from 'react'
44import {
@@ -22,10 +22,11 @@ export default function ModelNode({
2222 data,
2323 sourcePosition,
2424 targetPosition,
25- } : NodeProps & { data : GraphNodeData } ) : JSX . Element {
25+ } : NodeProps ) : JSX . Element {
26+ const nodeData : GraphNodeData = data ?? { }
2627 const {
28+ connections,
2729 models,
28- withColumns,
2930 handleClickModel,
3031 lineage = { } ,
3132 selectedNodes,
@@ -99,20 +100,30 @@ export default function ModelNode({
99100 [ setSelectedNodes , highlightedNodeModels ] ,
100101 )
101102
103+ const hasSelectedColumns = columns . some ( ( { name } ) =>
104+ connections . get ( toID ( id , name ) ) ,
105+ )
102106 const highlighted = Object . keys ( highlightedNodes ?? { } ) . find ( key =>
103107 highlightedNodes [ key ] ! . includes ( id ) ,
104108 )
105109 const splat = highlightedNodes ?. [ '*' ]
106- const isInteractive = mainNode !== id && isNotNil ( handleClickModel )
107- const isCTE = data . type === EnumLineageNodeModelType . cte
108- const isModelExternal = data . type === EnumLineageNodeModelType . external
109- const isModelSeed = data . type === EnumLineageNodeModelType . seed
110- const isModelPython = data . type === EnumLineageNodeModelType . python
111- const showColumns = ( withColumns && isArrayNotEmpty ( columns ) ) || isMouseOver
112110 const isMainNode = mainNode === id || highlightedNodeModels . includes ( id )
111+ const isSelected = selectedNodes . has ( id )
112+ const isInteractive = mainNode !== id && isNotNil ( handleClickModel )
113+ const isCTE = nodeData . type === EnumLineageNodeModelType . cte
114+ const isModelExternal = nodeData . type === EnumLineageNodeModelType . external
115+ const isModelSeed = nodeData . type === EnumLineageNodeModelType . seed
116+ const isModelPython = nodeData . type === EnumLineageNodeModelType . python
117+ const showColumns =
118+ ( hasSelectedColumns ||
119+ nodeData . withColumns ||
120+ isMouseOver ||
121+ isSelected ||
122+ isMainNode ) &&
123+ isArrayNotEmpty ( columns )
113124 const isActiveNode =
114125 selectedNodes . size > 0 || activeNodes . size > 0 || withConnected
115- ? selectedNodes . has ( id ) ||
126+ ? isSelected ||
116127 activeNodes . has ( id ) ||
117128 ( withConnected && connectedNodes . has ( id ) )
118129 : connectedNodes . has ( id )
@@ -126,23 +137,24 @@ export default function ModelNode({
126137 isCTE ? 'text-neutral-100' : 'text-secondary-500 dark:text-primary-100' ,
127138 ( isModelExternal || isModelSeed ) &&
128139 'border-4 border-accent-500 ring-8 ring-accent-200' ,
129- selectedNodes . has ( id ) &&
130- 'border-4 border-secondary-500 ring-8 ring-secondary-200' ,
140+ isSelected && 'border-4 border-secondary-500 ring-8 ring-secondary-200' ,
131141 isMainNode && 'ring-8 ring-brand-200' ,
132142 isNil ( highlighted ) ? splat : highlighted ,
133143 isActiveNode || isMainNode
134144 ? 'opacity-100'
135145 : 'opacity-40 hover:opacity-100' ,
136146 ) }
137147 style = { {
138- maxWidth : isNil ( data . width ) ? 'auto' : `${ data . width as number } px` ,
148+ maxWidth : isNil ( nodeData . width )
149+ ? 'auto'
150+ : `${ nodeData . width as number } px` ,
139151 } }
140152 >
141153 < ModelNodeHeaderHandles
142154 id = { id }
143- type = { data . type }
144- label = { data . label }
145- isSelected = { selectedNodes . has ( id ) }
155+ type = { nodeData . type }
156+ label = { nodeData . label }
157+ isSelected = { isSelected }
146158 isDraggable = { true }
147159 className = { clsx (
148160 showColumns ? 'rounded-t-md' : 'rounded-lg' ,
@@ -162,7 +174,7 @@ export default function ModelNode({
162174 }
163175 count = { columns . length }
164176 />
165- { showColumns && isArrayNotEmpty ( columns ) && (
177+ { showColumns && (
166178 < >
167179 < ModelColumns
168180 className = "max-h-[15rem]"
0 commit comments