diff --git a/frontend/src/components/sidebar/useSidebarSearchModel.tsx b/frontend/src/components/sidebar/useSidebarSearchModel.tsx index 3374e1f8..5e1e13c3 100644 --- a/frontend/src/components/sidebar/useSidebarSearchModel.tsx +++ b/frontend/src/components/sidebar/useSidebarSearchModel.tsx @@ -37,6 +37,7 @@ import { filterV2CommandSearchTreeItems, filterV2ExplorerTreeByKind, resolveSidebarNodeConnectionId, + resolveSidebarTreeVirtualHeight, resolveV2ActiveConnectionId, type SidebarTreeNode as TreeNode, type V2CommandSearchItem, @@ -619,7 +620,7 @@ export const useSidebarSearchModel = ({ ), [sidebarTableMetadataFields, treeViewportWidth, v2VisibleTreeData], ); - const effectiveTreeHeight = treeHeight; + const effectiveTreeHeight = resolveSidebarTreeVirtualHeight(treeHeight, isV2Ui); const v2TreeMetrics = useMemo(() => { const databaseTableCounts = new Map(); const objectGroupCounts = new Map(); diff --git a/frontend/src/components/sidebarV2Utils.tree-height.test.ts b/frontend/src/components/sidebarV2Utils.tree-height.test.ts new file mode 100644 index 00000000..8f5dc202 --- /dev/null +++ b/frontend/src/components/sidebarV2Utils.tree-height.test.ts @@ -0,0 +1,20 @@ +import { describe, expect, it } from 'vitest'; + +import { resolveSidebarTreeVirtualHeight } from './sidebarV2Utils'; + +describe('resolveSidebarTreeVirtualHeight', () => { + it('matches the V2 tree virtual viewport to the visible holder height', () => { + expect(resolveSidebarTreeVirtualHeight(500, true)).toBe(464); + }); + + it('keeps the legacy tree height unchanged', () => { + expect(resolveSidebarTreeVirtualHeight(500, false)).toBe(500); + }); + + it('never returns a negative height and preserves subpixel measurements', () => { + expect(resolveSidebarTreeVirtualHeight(20, true)).toBe(0); + expect(resolveSidebarTreeVirtualHeight(Number.NaN, true)).toBe(0); + expect(resolveSidebarTreeVirtualHeight(500.9, true)).toBeCloseTo(464.9); + expect(resolveSidebarTreeVirtualHeight(500.9, false)).toBe(500.9); + }); +}); diff --git a/frontend/src/components/sidebarV2Utils.ts b/frontend/src/components/sidebarV2Utils.ts index b4905bec..c28cf78d 100644 --- a/frontend/src/components/sidebarV2Utils.ts +++ b/frontend/src/components/sidebarV2Utils.ts @@ -76,6 +76,26 @@ export interface SidebarTreeNode { type?: SidebarTreeNodeType; } +// Keep these values aligned with the V2 explorer tree layout in v2-theme.css. +const V2_TREE_HORIZONTAL_SCROLL_RESERVE_PX = 32; +const V2_TREE_CONTENT_TOP_PADDING_PX = 4; + +export const resolveSidebarTreeVirtualHeight = ( + containerHeight: number, + isV2Ui: boolean, +): number => { + if (!Number.isFinite(containerHeight)) return 0; + const normalizedHeight = Math.max(0, containerHeight); + return Math.max( + 0, + normalizedHeight - ( + isV2Ui + ? V2_TREE_HORIZONTAL_SCROLL_RESERVE_PX + V2_TREE_CONTENT_TOP_PADDING_PX + : 0 + ), + ); +}; + export const hasSidebarLazyChildren = (children: unknown): boolean => { return Array.isArray(children) && children.length > 0; };