Skip to content

Commit

Permalink
refactor: Remove highlightedHandles
Browse files Browse the repository at this point in the history
  • Loading branch information
sasamuku committed Dec 19, 2024
1 parent 768a12a commit fb717d2
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ export type Data = {
table: Table
isActiveHighlighted: boolean
isHighlighted: boolean
highlightedHandles: string[]
sourceColumnName: string | undefined
targetColumnCardinalities?:
| Record<string, Cardinality | undefined>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const aTableData = (name: string, override?: Partial<Data>): Data => ({
table: aTable({ name }),
isActiveHighlighted: false,
isHighlighted: false,
highlightedHandles: [],
sourceColumnName: undefined,
...override,
})
Expand Down Expand Up @@ -73,14 +72,12 @@ describe(highlightNodesAndEdges, () => {
aTableNode('posts', {
data: aTableData('posts', {
isHighlighted: true,
highlightedHandles: ['posts-user_id'],
}),
}),
aTableNode('comments'),
aTableNode('comment_users', {
data: aTableData('comment_users', {
isHighlighted: true,
highlightedHandles: ['comment_users-user_id'],
}),
}),
])
Expand All @@ -94,7 +91,6 @@ describe(highlightNodesAndEdges, () => {
aTableNode('users', {
data: aTableData('users', {
isHighlighted: true,
highlightedHandles: ['users-id'],
}),
}),
aTableNode('posts', {
Expand All @@ -116,14 +112,12 @@ describe(highlightNodesAndEdges, () => {
aTableNode('posts', {
data: aTableData('posts', {
isHighlighted: false,
highlightedHandles: [],
}),
}),
aTableNode('comments'),
aTableNode('comment_users', {
data: aTableData('comment_users', {
isHighlighted: false,
highlightedHandles: [],
}),
}),
])
Expand All @@ -140,14 +134,12 @@ describe(highlightNodesAndEdges, () => {
aTableNode('posts', {
data: aTableData('posts', {
isHighlighted: true,
highlightedHandles: ['posts-user_id'],
}),
}),
aTableNode('comments'),
aTableNode('comment_users', {
data: aTableData('comment_users', {
isHighlighted: true,
highlightedHandles: ['comment_users-user_id'],
}),
}),
])
Expand All @@ -165,7 +157,6 @@ describe(highlightNodesAndEdges, () => {
aTableNode('posts', {
data: aTableData('posts', {
isHighlighted: true,
highlightedHandles: ['posts-user_id'],
}),
}),
aTableNode('comments', {
Expand All @@ -174,7 +165,6 @@ describe(highlightNodesAndEdges, () => {
aTableNode('comment_users', {
data: aTableData('comment_users', {
isHighlighted: true,
highlightedHandles: ['comment_users-user_id'],
}),
}),
])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,39 +38,6 @@ const isRelatedEdgeToTarget = (
return edge.source === targetTableName || edge.target === targetTableName
}

const getHighlightedHandlesForRelatedNode = (
targetTableName: string | undefined,
edges: Edge[],
node: TableNodeType,
): string[] => {
if (!targetTableName) {
return []
}

const handles: string[] = []
for (const edge of edges) {
if (
edge.targetHandle !== undefined &&
edge.targetHandle !== null &&
edge.source === targetTableName &&
edge.target === node.data.table.name
) {
handles.push(edge.targetHandle)
}

if (
edge.sourceHandle !== undefined &&
edge.sourceHandle !== null &&
edge.source === node.data.table.name &&
edge.target === targetTableName
) {
handles.push(edge.sourceHandle)
}
}

return handles
}

const activeHighlightNode = (node: TableNodeType): TableNodeType => ({
...node,
data: {
Expand All @@ -79,15 +46,11 @@ const activeHighlightNode = (node: TableNodeType): TableNodeType => ({
},
})

const highlightNode = (
node: TableNodeType,
handles: string[],
): TableNodeType => ({
const highlightNode = (node: TableNodeType): TableNodeType => ({
...node,
data: {
...node.data,
isHighlighted: true,
highlightedHandles: handles,
},
})

Expand All @@ -97,7 +60,6 @@ const unhighlightNode = (node: TableNodeType): TableNodeType => ({
...node.data,
isActiveHighlighted: false,
isHighlighted: false,
highlightedHandles: [],
},
})

Expand Down Expand Up @@ -150,12 +112,7 @@ export const highlightNodesAndEdges = (
isHoveredNode(hoverTableName, node) ||
isRelatedNodeToTarget(hoverTableName, edgeMap, node)
) {
const highlightedHandles = getHighlightedHandlesForRelatedNode(
activeTableName ?? hoverTableName,
edges,
node,
)
return highlightNode(node, highlightedHandles)
return highlightNode(node)
}

return unhighlightNode(node)
Expand Down

0 comments on commit fb717d2

Please sign in to comment.