From a31df420869b67ecbe8b7f8364643c711187c52e Mon Sep 17 00:00:00 2001 From: dextmorgn Date: Wed, 12 Nov 2025 23:19:18 +0100 Subject: [PATCH] feat(app): virtualize relationship items --- .../graphs/details-panel/relationships.tsx | 107 ++++++++++++++---- 1 file changed, 85 insertions(+), 22 deletions(-) diff --git a/flowsint-app/src/components/graphs/details-panel/relationships.tsx b/flowsint-app/src/components/graphs/details-panel/relationships.tsx index 02485743..5fe59927 100644 --- a/flowsint-app/src/components/graphs/details-panel/relationships.tsx +++ b/flowsint-app/src/components/graphs/details-panel/relationships.tsx @@ -5,8 +5,11 @@ import { Badge } from '@/components/ui/badge' import { useGraphStore } from '@/stores/graph-store' import { useQuery } from '@tanstack/react-query' import { ArrowRight } from 'lucide-react' -import { memo, useCallback } from 'react' +import { memo, useCallback, useRef } from 'react' import { GraphEdge, GraphNode } from '@/types' +import { useVirtualizer } from '@tanstack/react-virtual' + +const ITEM_HEIGHT = 36 // 32px badge height + 4px gap type Relation = { source: GraphNode @@ -34,32 +37,92 @@ const Relationships = memo( const relationships = getInlineRelationships(neighborsData?.nds || [], neighborsData?.rls || []) - if (isLoading) + if (isLoading) { return ( -
+
) + } - return ( -
- {relationships.map((rel, index) => ( - -
-
- + if (relationships.length === 0) { + return ( +
+ No relationships found +
+ ) + } + + return + } +) + +const VirtualizedList = memo(({ relationships }: { relationships: Relation[] }) => { + const parentRef = useRef(null) + + const virtualizer = useVirtualizer({ + count: relationships.length, + getScrollElement: () => parentRef.current, + estimateSize: () => ITEM_HEIGHT, + overscan: 5 + }) + + const virtualItems = virtualizer.getVirtualItems() + + console.log('VirtualizedList Debug:', { + relationshipsCount: relationships.length, + totalSize: virtualizer.getTotalSize(), + virtualItemsCount: virtualItems.length, + firstItem: virtualItems[0], + parentRefCurrent: parentRef.current + }) + + return ( +
+
+ {virtualItems.map((virtualRow) => { + const rel = relationships[virtualRow.index] + + return ( +
+ +
+
+ +
+ +
+ {rel.edge.label} +
+ +
+ +
+
+
- -
- {rel.edge.label} -
- -
- -
-
- - ))} + ) + })} +
) } @@ -71,7 +134,7 @@ const RelationshipItem = memo(({ node }: { node: GraphNode }) => { const setCurrentNode = useGraphStore((s) => s.setCurrentNode) const handleClick = useCallback(() => { setCurrentNode(node) - }, [setCurrentNode]) + }, [setCurrentNode, node]) return (