Skip to content

Commit c6b9e18

Browse files
authored
chore(vscode): continued typing of nodes (#4911)
1 parent 1770cd9 commit c6b9e18

File tree

7 files changed

+107
-112
lines changed

7 files changed

+107
-112
lines changed

vscode/react/src/components/graph/ModelColumns.tsx

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
isNotNil,
1111
truncate,
1212
} from '@/utils/index'
13-
import { EnumSide, toID, type Side } from './types'
13+
import { toID, type PartialColumnHandleId, type Side } from './types'
1414
import { NoSymbolIcon } from '@heroicons/react/24/solid'
1515
import { ClockIcon, ExclamationCircleIcon } from '@heroicons/react/24/outline'
1616
import clsx from 'clsx'
@@ -38,7 +38,7 @@ export function ModelColumns({
3838
columns,
3939
disabled,
4040
className,
41-
limit = 5,
41+
limit,
4242
withHandles = false,
4343
withDescription = true,
4444
maxHeight = '50vh',
@@ -47,7 +47,7 @@ export function ModelColumns({
4747
columns: Column[]
4848
disabled?: boolean
4949
className?: string
50-
limit?: number
50+
limit: number
5151
withHandles?: boolean
5252
withDescription?: boolean
5353
maxHeight?: string
@@ -125,7 +125,7 @@ export function ModelColumns({
125125
}
126126

127127
const isSelectManually = useCallback(
128-
function isSelectManually(columnName: string): boolean {
128+
function isSelectManually(columnName: ColumnName): boolean {
129129
if (isNil(manuallySelectedColumn)) return false
130130

131131
const [selectedModel, selectedColumn] = manuallySelectedColumn
@@ -138,12 +138,10 @@ export function ModelColumns({
138138
)
139139

140140
const removeEdges = useCallback(
141-
function removeEdges(columnId: string): void {
141+
function removeEdges(columnId: PartialColumnHandleId): void {
142142
const visited = new Set<string>()
143143

144-
removeActiveEdges(
145-
walk(columnId, EnumSide.Left).concat(walk(columnId, EnumSide.Right)),
146-
)
144+
removeActiveEdges(walk(columnId, 'left').concat(walk(columnId, 'right')))
147145

148146
if (connections.size === 0 && isNotNil(lineageCache)) {
149147
setLineage(lineageCache)
@@ -164,12 +162,12 @@ export function ModelColumns({
164162
return edges
165163
.map(edge =>
166164
[
167-
side === EnumSide.Left
168-
? [toID(EnumSide.Left, id), toID(EnumSide.Right, edge)]
169-
: [toID(EnumSide.Left, edge), toID(EnumSide.Right, id)],
165+
side === 'left'
166+
? [toID('left', id), toID('right', edge)]
167+
: [toID('left', edge), toID('right', id)],
170168
].concat(walk(edge, side)),
171169
)
172-
.flat() as Array<[string, string]>
170+
.flat() as Array<[PartialColumnHandleId, PartialColumnHandleId]>
173171
}
174172
},
175173
[removeActiveEdges, connections],
@@ -324,8 +322,8 @@ function ModelColumn({
324322
withHandles = false,
325323
withDescription = true,
326324
}: {
327-
id: string
328-
nodeId: string
325+
id: PartialColumnHandleId
326+
nodeId: ModelEncodedFQN
329327
column: Column
330328
disabled?: boolean
331329
isActive?: boolean
@@ -337,7 +335,7 @@ function ModelColumn({
337335
updateColumnLineage: (
338336
lineage: ColumnLineageApiLineageModelNameColumnNameGet200,
339337
) => void
340-
removeEdges: (columnId: string) => void
338+
removeEdges: (columnId: PartialColumnHandleId) => void
341339
selectManually?: React.Dispatch<
342340
React.SetStateAction<
343341
[ModelSQLMeshModel<InitialSQLMeshModel>, Column] | undefined
@@ -454,8 +452,8 @@ function ColumnHandles({
454452
children,
455453
className,
456454
}: {
457-
nodeId: string
458-
id: string
455+
nodeId: ModelEncodedFQN
456+
id: PartialColumnHandleId
459457
children: React.ReactNode
460458
className?: string
461459
hasLeft?: boolean
@@ -482,7 +480,7 @@ function ColumnHandles({
482480
{hasLeft && (
483481
<Handle
484482
type="target"
485-
id={toID(EnumSide.Left, id)}
483+
id={toID('left', id)}
486484
position={Position.Left}
487485
isConnectable={false}
488486
className="w-2 h-2 rounded-full"
@@ -492,7 +490,7 @@ function ColumnHandles({
492490
{hasRight && (
493491
<Handle
494492
type="source"
495-
id={toID(EnumSide.Right, id)}
493+
id={toID('right', id)}
496494
position={Position.Right}
497495
isConnectable={false}
498496
className="w-2 h-2 rounded-full"
@@ -510,19 +508,13 @@ function ColumnDisplay({
510508
disabled = false,
511509
withDescription = true,
512510
}: {
513-
columnName: string
511+
columnName: ColumnName
514512
columnType: string
515513
columnDescription?: ColumnDescription
516514
disabled?: boolean
517515
withDescription?: boolean
518516
className?: string
519517
}): JSX.Element {
520-
let decodedColumnName = columnName
521-
522-
try {
523-
decodedColumnName = decodeURI(columnName)
524-
} catch {}
525-
526518
return (
527519
<div
528520
className={clsx(
@@ -533,7 +525,7 @@ function ColumnDisplay({
533525
>
534526
<div className="w-full flex justify-between items-center">
535527
<span
536-
title={decodedColumnName}
528+
title={columnName}
537529
className={clsx('flex items-center', disabled && 'opacity-50')}
538530
>
539531
{disabled && (
@@ -542,7 +534,7 @@ function ColumnDisplay({
542534
className="w-3 h-3 mr-2"
543535
/>
544536
)}
545-
{truncate(decodedColumnName, 50, 20)}
537+
{truncate(columnName, 50, 20)}
546538
</span>
547539
<span
548540
title={columnType}

vscode/react/src/components/graph/ModelNode.tsx

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import { ModelNodeHeaderHandles } from './ModelNodeHeaderHandles'
99
import { ModelColumns } from './ModelColumns'
1010
import { fromAPIColumn, type Column } from '@/domain/column'
1111
import { decode, type ModelEncodedFQN } from '@/domain/models'
12+
import { toKeys } from './types'
13+
import { MAX_VISIBLE_COLUMNS } from './constants'
1214

1315
export const EnumLineageNodeModelType = {
1416
...ModelType,
@@ -57,33 +59,24 @@ export default function ModelNode({
5759
const model = modelsArray.find((m: Model) => m.fqn === decodedId)
5860
const modelColumns = model?.columns?.map(fromAPIColumn) ?? []
5961

60-
Object.keys(lineage[decodedId]?.columns ?? {}).forEach((column: string) => {
61-
const found = modelColumns.find(({ name }: any) => {
62-
try {
63-
return name === decodeURI(column)
64-
} catch {
65-
return name === column
66-
}
67-
})
68-
62+
toKeys(lineage[decodedId]?.columns ?? {}).forEach(column => {
63+
const found = modelColumns.find(({ name }) => name === column)
6964
if (isNil(found)) {
7065
modelColumns.push(
7166
fromAPIColumn({ name: column, type: EnumColumnType.UNKNOWN }),
7267
)
7368
}
7469
})
75-
76-
modelColumns.forEach((column: any) => {
70+
return modelColumns.map(column => {
7771
let columnType = column.type ?? EnumColumnType.UNKNOWN
78-
7972
if (columnType.startsWith(EnumColumnType.STRUCT)) {
8073
columnType = EnumColumnType.STRUCT
8174
}
82-
83-
column.type = columnType
75+
return {
76+
...column,
77+
type: columnType,
78+
}
8479
})
85-
86-
return modelColumns
8780
}, [id, models, lineage])
8881

8982
const highlightedNodeModels = useMemo(
@@ -136,7 +129,7 @@ export default function ModelNode({
136129
// Ensure nodeData.type is a valid LineageNodeModelType
137130
const nodeType: LineageNodeModelType = Object.values(
138131
EnumLineageNodeModelType,
139-
).includes(nodeData.type as any)
132+
).includes(nodeData.type)
140133
? (nodeData.type as LineageNodeModelType)
141134
: EnumLineageNodeModelType.unknown
142135

@@ -222,12 +215,13 @@ export default function ModelNode({
222215
? undefined
223216
: handleSelect
224217
}
225-
count={hasHighlightedNodes ? undefined : columns.length}
218+
numberOfColumns={columns.length}
226219
/>
227220
{showColumns && (
228221
<ModelColumns
229222
className="nowheel rounded-b-lg bg-theme-lighter text-xs"
230223
nodeId={id}
224+
limit={MAX_VISIBLE_COLUMNS}
231225
columns={columns}
232226
disabled={shouldDisableColumns}
233227
withHandles={true}

vscode/react/src/components/graph/ModelNodeHeaderHandles.tsx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ import { Handle, Position } from 'reactflow'
33
import 'reactflow/dist/base.css'
44
import { getModelNodeTypeTitle } from './help'
55
import { isNotNil, truncate } from '@/utils/index'
6-
import { EnumSide, toID } from './types'
6+
import { toID } from './types'
77
import { ArrowRightCircleIcon } from '@heroicons/react/24/solid'
88
import clsx from 'clsx'
99
import { type LineageNodeModelType } from './ModelNode'
10+
import type { ModelEncodedFQN } from '@/domain/models'
1011

1112
export function ModelNodeHeaderHandles({
1213
id,
@@ -17,16 +18,16 @@ export function ModelNodeHeaderHandles({
1718
isDraggable = false,
1819
label,
1920
type,
20-
count,
21+
numberOfColumns,
2122
handleClick,
2223
handleSelect,
2324
}: {
24-
id: string
25+
id: ModelEncodedFQN
2526
label: string
2627
type?: LineageNodeModelType
2728
hasLeft?: boolean
2829
hasRight?: boolean
29-
count?: number
30+
numberOfColumns?: number
3031
className?: string
3132
isSelected?: boolean
3233
isDraggable?: boolean
@@ -38,7 +39,7 @@ export function ModelNodeHeaderHandles({
3839
{hasLeft && (
3940
<Handle
4041
type="target"
41-
id={toID(EnumSide.Left, id)}
42+
id={toID('left', id)}
4243
position={Position.Left}
4344
isConnectable={false}
4445
className="-ml-2 border rounded-full overflow-hidden border-current"
@@ -87,17 +88,17 @@ export function ModelNodeHeaderHandles({
8788
>
8889
{truncate(decodeURI(label), 50, 20)}
8990
</span>
90-
{isNotNil(count) && (
91+
{isNotNil(numberOfColumns) && (
9192
<span className="flex justify-between ml-2 mr-1 px-2 rounded-full bg-neutral-10">
92-
{count}
93+
{numberOfColumns}
9394
</span>
9495
)}
9596
</span>
9697
</div>
9798
{hasRight && (
9899
<Handle
99100
type="source"
100-
id={toID(EnumSide.Right, id)}
101+
id={toID('right', id)}
101102
position={Position.Right}
102103
isConnectable={false}
103104
className="-mr-2 border rounded-full overflow-hidden border-current"
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* Space between nodes.
3+
*/
4+
export const NODE_BALANCE_SPACE = 64
5+
/**
6+
* Height of a column line.
7+
*/
8+
export const COLUMN_LINE_HEIGHT = 24
9+
/**
10+
* Assumed width of a character.
11+
*/
12+
export const CHAR_WIDTH = 8
13+
/**
14+
* Maximum number of columns that can be visible in a node.
15+
*/
16+
export const MAX_VISIBLE_COLUMNS = 5

0 commit comments

Comments
 (0)