mirror of
https://github.com/Syngnat/GoNavi.git
synced 2026-08-21 00:20:22 +08:00
🐛 fix(sidebar): 修复连接树末项无法完整显示
This commit is contained in:
@@ -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<React.Key, number>();
|
||||
const objectGroupCounts = new Map<React.Key, number>();
|
||||
|
||||
20
frontend/src/components/sidebarV2Utils.tree-height.test.ts
Normal file
20
frontend/src/components/sidebarV2Utils.tree-height.test.ts
Normal file
@@ -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);
|
||||
});
|
||||
});
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user