From fb717d28cdca1cb07ea7cab940e3138061db33c3 Mon Sep 17 00:00:00 2001 From: "ryota.sasazawa" Date: Thu, 19 Dec 2024 19:02:56 +0900 Subject: [PATCH] refactor: Remove highlightedHandles --- .../ERDRenderer/ERDContent/TableNode/type.ts | 1 - .../ERDContent/highlightNodesAndEdges.test.ts | 10 ---- .../ERDContent/highlightNodesAndEdges.ts | 47 +------------------ 3 files changed, 2 insertions(+), 56 deletions(-) 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)