Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Remove highlightedHandles #328

Merged
merged 1 commit into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions frontend/.changeset/calm-lobsters-jam.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@liam-hq/erd-core": patch
"@liam-hq/cli": patch
---

refactor: Remove highlightedHandles
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
Loading