Skip to content

Commit 152f70b

Browse files
authored
Render handles for Model Column only when that column has been select (#1994)
1 parent fd80def commit 152f70b

File tree

4 files changed

+39
-40
lines changed

4 files changed

+39
-40
lines changed

web/client/src/library/components/graph/Graph.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,13 +396,15 @@ const ModelColumn = memo(function ModelColumn({
396396
}
397397
}
398398

399+
const showHandles = withHandles && (hasLeft || hasRight)
400+
399401
return (
400402
<div
401403
className={clsx(
402404
isActive
403405
? 'bg-secondary-10 dark:bg-primary-900 text-secondary-500 dark:text-neutral-100'
404406
: 'text-neutral-600 dark:text-neutral-100 hover:bg-neutral-5',
405-
withHandles ? 'p-0 mb-1' : 'px-2 rounded-md mb-1',
407+
showHandles ? 'p-0 mb-1' : 'px-2 rounded-md mb-1',
406408
className,
407409
)}
408410
onClick={debounceSync(toggleColumnLineage, 500, true)}
@@ -413,7 +415,7 @@ const ModelColumn = memo(function ModelColumn({
413415
disabled ? 'cursor-not-allowed' : 'cursor-pointer',
414416
)}
415417
>
416-
{withHandles ? (
418+
{showHandles ? (
417419
<ModelNodeHandles
418420
id={id}
419421
nodeId={nodeId}

web/client/src/library/components/graph/ModelLineage.tsx

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,6 @@ function ModelColumnLineage(): JSX.Element {
209209
withConnected,
210210
withImpacted,
211211
withSecondary,
212-
withColumns,
213212
)
214213
const newEdges = getUpdatedEdges(
215214
allEdges,
@@ -253,8 +252,6 @@ function ModelColumnLineage(): JSX.Element {
253252
setIsBuildingLayout(false)
254253
}, 100)
255254
}
256-
257-
setActiveNodes(newActiveNodes)
258255
})
259256

260257
return () => {
@@ -265,17 +262,6 @@ function ModelColumnLineage(): JSX.Element {
265262
}
266263
}, [lineageIndex, withColumns])
267264

268-
useEffect(() => {
269-
const newActiveNodes = getActiveNodes(
270-
allEdges,
271-
activeEdges,
272-
selectedEdges,
273-
nodesMap,
274-
)
275-
276-
setActiveNodes(newActiveNodes)
277-
}, [nodesMap, activeEdges, selectedEdges])
278-
279265
useEffect(() => {
280266
if (isNil(mainNode) || isArrayEmpty(nodes)) return
281267

@@ -295,7 +281,6 @@ function ModelColumnLineage(): JSX.Element {
295281
withConnected,
296282
withImpacted,
297283
withSecondary,
298-
withColumns,
299284
)
300285

301286
const newEdges = getUpdatedEdges(

web/client/src/library/components/graph/ModelNode.tsx

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { isNil, isArrayNotEmpty, isNotNil } from '@utils/index'
1+
import { isNil, isArrayNotEmpty, isNotNil, toID } from '@utils/index'
22
import clsx from 'clsx'
33
import { useMemo, useCallback, useState } from 'react'
44
import {
@@ -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]"

web/client/src/library/components/graph/help.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { type ConnectedNode } from '~/workers/lineage'
1919
export interface GraphNodeData {
2020
label: string
2121
type: LineageNodeModelType
22+
withColumns: boolean
2223
[key: string]: any
2324
}
2425

@@ -180,6 +181,7 @@ function getNodeMap({
180181
const model = models.get(modelName)
181182
const node = createGraphNode(modelName, {
182183
label: model?.displayName ?? modelName,
184+
withColumns,
183185
type: isNotNil(model)
184186
? (model.type as LineageNodeModelType)
185187
: // If model name present in lineage but not in global models
@@ -205,7 +207,6 @@ function getNodeMap({
205207
node.data.height = withColumns
206208
? maxHeight + NODE_BALANCE_SPACE * 2
207209
: NODE_BALANCE_SPACE
208-
node.data.withColumns = withColumns
209210

210211
if (isArrayNotEmpty(lineage[node.id]?.models)) {
211212
node.targetPosition = Position.Left
@@ -664,10 +665,9 @@ function getUpdatedNodes(
664665
connectedNodes: Set<string>,
665666
selectedNodes: Set<string>,
666667
connections: Map<string, Connections>,
667-
withConnected: boolean = true,
668-
withImpacted: boolean = true,
669-
withSecondary: boolean = true,
670-
withColumns: boolean = true,
668+
withConnected: boolean,
669+
withImpacted: boolean,
670+
withSecondary: boolean,
671671
): Node[] {
672672
return nodes.map(node => {
673673
node.hidden = true
@@ -687,7 +687,7 @@ function getUpdatedNodes(
687687
node.hidden = isFalse(isActiveNode)
688688
}
689689

690-
if (node.data.type === EnumLineageNodeModelType.cte && withColumns) {
690+
if (node.data.type === EnumLineageNodeModelType.cte) {
691691
node.hidden = isFalse(activeNodes.has(node.id))
692692
}
693693

0 commit comments

Comments
 (0)