From 594386f7efec7898158b0b28d3741ae6f6488610 Mon Sep 17 00:00:00 2001 From: "ryota.sasazawa" Date: Thu, 19 Dec 2024 19:02:56 +0900 Subject: [PATCH] refactor: Remove highlightedHandles --- frontend/.changeset/calm-lobsters-jam.md | 6 +++ .../ERDRenderer/ERDContent/TableNode/type.ts | 1 - .../ERDContent/highlightNodesAndEdges.test.ts | 10 ---- .../ERDContent/highlightNodesAndEdges.ts | 47 +------------------ 4 files changed, 8 insertions(+), 56 deletions(-) create mode 100644 frontend/.changeset/calm-lobsters-jam.md diff --git a/frontend/.changeset/calm-lobsters-jam.md b/frontend/.changeset/calm-lobsters-jam.md new file mode 100644 index 00000000..5398a265 --- /dev/null +++ b/frontend/.changeset/calm-lobsters-jam.md @@ -0,0 +1,6 @@ +--- +"@liam-hq/erd-core": patch +"@liam-hq/cli": patch +--- + +refactor: Remove highlightedHandles diff --git a/frontend/packages/erd-core/src/components/ERDRenderer/ERDContent/TableNode/type.ts b/frontend/packages/erd-core/src/components/ERDRenderer/ERDContent/TableNode/type.ts index ab291053..6c526287 100644 --- a/frontend/packages/erd-core/src/components/ERDRenderer/ERDContent/TableNode/type.ts +++ b/frontend/packages/erd-core/src/components/ERDRenderer/ERDContent/TableNode/type.ts @@ -5,7 +5,6 @@ export type Data = { table: Table isActiveHighlighted: boolean isHighlighted: boolean - highlightedHandles: string[] sourceColumnName: string | undefined targetColumnCardinalities?: | Record diff --git a/frontend/packages/erd-core/src/components/ERDRenderer/ERDContent/highlightNodesAndEdges.test.ts b/frontend/packages/erd-core/src/components/ERDRenderer/ERDContent/highlightNodesAndEdges.test.ts index e34595e8..77ca89fb 100644 --- a/frontend/packages/erd-core/src/components/ERDRenderer/ERDContent/highlightNodesAndEdges.test.ts +++ b/frontend/packages/erd-core/src/components/ERDRenderer/ERDContent/highlightNodesAndEdges.test.ts @@ -8,7 +8,6 @@ const aTableData = (name: string, override?: Partial): Data => ({ table: aTable({ name }), isActiveHighlighted: false, isHighlighted: false, - highlightedHandles: [], sourceColumnName: undefined, ...override, }) @@ -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'], }), }), ]) @@ -94,7 +91,6 @@ describe(highlightNodesAndEdges, () => { aTableNode('users', { data: aTableData('users', { isHighlighted: true, - highlightedHandles: ['users-id'], }), }), aTableNode('posts', { @@ -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: [], }), }), ]) @@ -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'], }), }), ]) @@ -165,7 +157,6 @@ describe(highlightNodesAndEdges, () => { aTableNode('posts', { data: aTableData('posts', { isHighlighted: true, - highlightedHandles: ['posts-user_id'], }), }), aTableNode('comments', { @@ -174,7 +165,6 @@ describe(highlightNodesAndEdges, () => { aTableNode('comment_users', { data: aTableData('comment_users', { isHighlighted: true, - highlightedHandles: ['comment_users-user_id'], }), }), ]) diff --git a/frontend/packages/erd-core/src/components/ERDRenderer/ERDContent/highlightNodesAndEdges.ts b/frontend/packages/erd-core/src/components/ERDRenderer/ERDContent/highlightNodesAndEdges.ts index 30801bf7..df24fc67 100644 --- a/frontend/packages/erd-core/src/components/ERDRenderer/ERDContent/highlightNodesAndEdges.ts +++ b/frontend/packages/erd-core/src/components/ERDRenderer/ERDContent/highlightNodesAndEdges.ts @@ -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: { @@ -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, }, }) @@ -97,7 +60,6 @@ const unhighlightNode = (node: TableNodeType): TableNodeType => ({ ...node.data, isActiveHighlighted: false, isHighlighted: false, - highlightedHandles: [], }, }) @@ -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)