fix(sidebar): Dameng tree blank band, admin node duplication and schema auto-expand
This commit is contained in:
1 parent
707296c71d
commit
57b350eb49
8 files changed
+1330
-15
No files matched your search
@@ -48,7 +48,7 @@ import {
|
||||
type SidebarNodeScrollAlign,
|
||||
} from "@/lib/sidebar/sidebarActiveTabTarget";
|
||||
import { findLoadedTableTargetForCandidate, queryContextTargetFromCandidate, queryCursorTableCandidate, type QueryCursorTableCandidate } from "@/lib/sql/queryCursorTableTarget";
|
||||
import { createFlatTreeIndex, flatTreeRowsChanged, SIDEBAR_TREE_ROW_HEIGHT, SIDEBAR_TREE_PRERENDER_COUNT, SIDEBAR_TREE_SCROLL_BUFFER, flattenTree, shouldVirtualizeFlatTree, type FlatTreeNode } from "@/composables/useFlatTree";
|
||||
import { createFlatTreeIndex, flatTreeRowsChanged, SIDEBAR_TREE_ROW_HEIGHT, SIDEBAR_TREE_PRERENDER_COUNT, SIDEBAR_TREE_SCROLL_BUFFER, SIDEBAR_TREE_VIRTUALIZE_HYSTERESIS, SIDEBAR_TREE_VIRTUALIZE_THRESHOLD, flattenTree, shouldVirtualizeFlatTree, type FlatTreeNode } from "@/composables/useFlatTree";
|
||||
import { sidebarTreeContextKey } from "@/lib/sidebar/sidebarTreeContext";
|
||||
import { createSidebarTreeRuntime, sidebarTreeRuntimeKey, type SidebarTreeRuntimeHostInstance } from "@/lib/sidebar/sidebarTreeRuntime";
|
||||
import { createSidebarPasteHandlerRegistry } from "@/lib/sidebar/sidebarPasteHandlerRegistry";
|
||||
@@ -81,6 +81,7 @@ import { sidebarDisplayTableName } from "@/lib/sidebar/sidebarTableNameDisplay";
|
||||
import { alignedSidebarCommentLabelWidths, isSidebarCommentAlignableNode, sidebarTreeNaturalContentWidth, sidebarTreeNodeComment, usesFullWidthTreeLabel } from "@/lib/sidebar/sidebarTreeItemLayout";
|
||||
import { formatSidebarObjectStorage, sidebarTableStorageScopes, supportsSidebarTableStorage } from "@/lib/sidebar/sidebarDatabaseStorage";
|
||||
import { sidebarScrollbarGeometry as calculateSidebarScrollbarGeometry } from "@/lib/sidebar/sidebarScrollbar";
|
||||
import { createSidebarLayoutMonitor, type SidebarExpandedConnectionInfo } from "@/lib/sidebar/sidebarLayoutMonitor";
|
||||
import { disconnectSidebarConnections } from "@/lib/sidebar/sidebarConnectionDisconnect";
|
||||
import { compileSearchRegex } from "@/lib/common/searchPattern";
|
||||
|
||||
@@ -103,6 +104,7 @@ const sidebarRootStyle = computed<Record<string, string>>(() => ({ fontSize: `${
|
||||
const pointerInsideTree = ref(false);
|
||||
const treeScrollerRef = ref<InstanceType<typeof RecycleScroller> | null>(null);
|
||||
const plainTreeScrollerRef = ref<HTMLElement | null>(null);
|
||||
const treeScrollShellRef = ref<HTMLElement | null>(null);
|
||||
const sidebarScrollbarTrackRef = ref<HTMLElement | null>(null);
|
||||
const sidebarHorizontalScrollbarTrackRef = ref<HTMLElement | null>(null);
|
||||
const sidebarContextMenuRef = ref<{ close: () => void } | null>(null);
|
||||
@@ -745,6 +747,68 @@ const flatNodes = computed<FlatTreeNode[]>(() =>
|
||||
}),
|
||||
);
|
||||
|
||||
// Debug instrumentation for the "expanded tree leaves the scroll shell stuck
|
||||
// (e.g. Dameng connection expanded and the viewport froze near half height)"
|
||||
// class of layout bugs. Feeds the layout monitor with expand events and
|
||||
// tree-size changes so its anomaly reports can describe the transition.
|
||||
function readExpandedSidebarConnections(): SidebarExpandedConnectionInfo[] {
|
||||
const expanded: SidebarExpandedConnectionInfo[] = [];
|
||||
for (const node of filteredNodes.value) {
|
||||
if (node.type !== "connection" && node.type !== "connection-group") continue;
|
||||
if (!node.isExpanded) continue;
|
||||
let descendantCount = 0;
|
||||
const stack = [...(node.children ?? [])];
|
||||
while (stack.length > 0) {
|
||||
const child = stack.pop() as TreeNode;
|
||||
descendantCount += 1;
|
||||
if (child.children) stack.push(...child.children);
|
||||
}
|
||||
expanded.push({ id: node.id, label: node.label, type: node.type, descendantCount });
|
||||
}
|
||||
return expanded;
|
||||
}
|
||||
|
||||
// Which schema nodes are expanded right now — lets the layout monitor tell a
|
||||
// user-initiated expand (an expand-toggle event precedes it) from a
|
||||
// programmatic one (the schema shows up here without one).
|
||||
function readExpandedSidebarSchemas(): Array<{ id: string; label: string }> {
|
||||
const expanded: Array<{ id: string; label: string }> = [];
|
||||
for (const connection of filteredNodes.value) {
|
||||
if (connection.type !== "connection" && connection.type !== "connection-group") continue;
|
||||
const stack = [...(connection.children ?? [])];
|
||||
while (stack.length > 0) {
|
||||
const child = stack.pop() as TreeNode;
|
||||
if (child.type === "schema" && child.isExpanded) expanded.push({ id: child.id, label: child.label });
|
||||
if (child.children) stack.push(...child.children);
|
||||
}
|
||||
}
|
||||
return expanded;
|
||||
}
|
||||
|
||||
// The plain (non-virtualized) renderer keeps the sticky database/schema header
|
||||
// via native CSS position: sticky on the container rows, mirroring the overlay
|
||||
// the virtual branch renders. Only container rows stick; children scroll under
|
||||
// them until the next container takes over.
|
||||
function isPlainStickyContainerNode(node: TreeNode): boolean {
|
||||
// Mirror the virtual branch's sticky overlay: both suppress sticky headers
|
||||
// while a search filter is active so filtered rows don't pin at the top.
|
||||
if (isTreeSearchFiltering.value) return false;
|
||||
return DATABASE_LEVEL_TYPES.has(node.type) || SCHEMA_LEVEL_TYPES.has(node.type);
|
||||
}
|
||||
|
||||
const sidebarLayoutMonitor = createSidebarLayoutMonitor({
|
||||
readContext: () => ({
|
||||
flatNodeCount: flatNodes.value.length,
|
||||
useVirtualTree: useVirtualTree.value,
|
||||
virtualItemSize: SIDEBAR_TREE_ROW_HEIGHT,
|
||||
scrollerEl: currentTreeScroller(),
|
||||
shellEl: treeScrollShellRef.value,
|
||||
rootEl: rootRef.value ?? null,
|
||||
virtualScroller: (treeScrollerRef.value as unknown as Record<string, unknown> | null) ?? null,
|
||||
expandedConnections: readExpandedSidebarConnections(),
|
||||
}),
|
||||
});
|
||||
|
||||
watch(flatNodes, refreshPendingInvalidatedTableSearchScopes, { flush: "post" });
|
||||
|
||||
const sidebarCommentLabelWidths = shallowRef(new Map<string, number>());
|
||||
@@ -876,7 +940,38 @@ const flatTreeIndex = computed(() =>
|
||||
const visibleNodes = computed<TreeNode[]>(() => flatTreeIndex.value.visibleNodes);
|
||||
const selectableVisibleNodes = computed<TreeNode[]>(() => flatTreeIndex.value.selectableVisibleNodes);
|
||||
const selectableVisibleNodeIndexById = computed(() => flatTreeIndex.value.selectableVisibleNodeIndexById);
|
||||
const useVirtualTree = computed(() => shouldVirtualizeFlatTree(flatNodes.value.length));
|
||||
// Virtualization with hysteresis: switching between the plain and virtual
|
||||
// renderers remounts the tree (scroll reset), so once virtualized stay virtual
|
||||
// until the tree drops well below the threshold — otherwise search/filter
|
||||
// oscillation around the boundary would thrash between the two branches.
|
||||
const treeVirtualizationArmed = ref(false);
|
||||
watch(
|
||||
() => flatNodes.value.length,
|
||||
(count) => {
|
||||
if (treeVirtualizationArmed.value) {
|
||||
if (count < SIDEBAR_TREE_VIRTUALIZE_THRESHOLD - SIDEBAR_TREE_VIRTUALIZE_HYSTERESIS) {
|
||||
treeVirtualizationArmed.value = false;
|
||||
}
|
||||
} else if (shouldVirtualizeFlatTree(count)) {
|
||||
treeVirtualizationArmed.value = true;
|
||||
}
|
||||
},
|
||||
{ immediate: true },
|
||||
);
|
||||
const useVirtualTree = computed(() => treeVirtualizationArmed.value);
|
||||
|
||||
// The plain and virtual branches mount separate scroller elements; keep the
|
||||
// scroll position when the renderer flips so crossing the threshold does not
|
||||
// jump the user back to the top.
|
||||
watch(useVirtualTree, (virtual, wasVirtual) => {
|
||||
const previous = (wasVirtual ? treeScrollerRef.value?.$el : plainTreeScrollerRef.value) as HTMLElement | undefined;
|
||||
const savedScrollTop = previous?.scrollTop ?? 0;
|
||||
if (!savedScrollTop) return;
|
||||
void nextTick(() => {
|
||||
const next = (virtual ? treeScrollerRef.value?.$el : plainTreeScrollerRef.value) as HTMLElement | undefined;
|
||||
if (next) next.scrollTop = savedScrollTop;
|
||||
});
|
||||
});
|
||||
const activeTab = computed(() => queryStore.tabs.find((tab) => tab.id === queryStore.activeTabId));
|
||||
const hasTreeMultiSelection = computed(() => store.connectionMultiSelectActive || store.selectedTreeNodeIds.length > 1);
|
||||
|
||||
@@ -1014,6 +1109,26 @@ const stickyHeaderStyle = computed<CSSProperties>(() => {
|
||||
// Reset tracking when the tree rebuilds (connect/disconnect/collapse) so a
|
||||
// stale scrollTop doesn't keep the overlay mounted after a structural change.
|
||||
watch(flatNodes, (nodes, previousNodes) => {
|
||||
// The diagnostic events walk the whole expanded tree; only do that work when
|
||||
// the layout monitor is actually armed (dev default, disabled in production).
|
||||
if (sidebarLayoutMonitor.isEnabled()) {
|
||||
const previousCount = previousNodes?.length ?? 0;
|
||||
if (nodes.length !== previousCount) {
|
||||
const previousIds = new Set((previousNodes ?? []).map((entry) => entry.id));
|
||||
const added = nodes
|
||||
.filter((entry) => !previousIds.has(entry.id))
|
||||
.slice(0, 5)
|
||||
.map((entry) => ({ type: entry.node.type, label: entry.node.label }));
|
||||
sidebarLayoutMonitor.recordEvent({
|
||||
type: "tree-change",
|
||||
prevCount: previousCount,
|
||||
count: nodes.length,
|
||||
expandedConnections: readExpandedSidebarConnections(),
|
||||
added,
|
||||
expandedSchemas: readExpandedSidebarSchemas(),
|
||||
});
|
||||
}
|
||||
}
|
||||
const contextMenuTarget = sidebarContextMenuTarget.value;
|
||||
if (contextMenuTarget) {
|
||||
const visibleContextMenuTarget = nodes.find(({ node }) => matchesSidebarActionTarget(node, contextMenuTarget))?.node;
|
||||
@@ -1035,9 +1150,10 @@ watch(flatNodes, (nodes, previousNodes) => {
|
||||
// Reading scrollHeight forces that layout (applying the clamp), then one
|
||||
// explicit pool refresh keeps the rendered window aligned.
|
||||
if (!flatTreeRowsChanged(nodes, previousNodes)) return;
|
||||
if (!useVirtualTree.value) return;
|
||||
void nextTick(() => {
|
||||
const scroller = treeScrollerRef.value;
|
||||
if (!scroller || !useVirtualTree.value) return;
|
||||
if (!scroller) return;
|
||||
const el = scroller.$el as HTMLElement | undefined;
|
||||
if (!el) return;
|
||||
const maxScrollTop = Math.max(0, el.scrollHeight - el.clientHeight);
|
||||
@@ -1649,6 +1765,13 @@ function onSearchToggle(node: TreeNode) {
|
||||
|
||||
function onNodeToggled(node: TreeNode, expanded: boolean) {
|
||||
if (isTreeSearchFiltering.value) return;
|
||||
sidebarLayoutMonitor.recordEvent({
|
||||
type: "expand-toggle",
|
||||
nodeId: node.id,
|
||||
label: node.label,
|
||||
nodeType: node.type,
|
||||
expanded,
|
||||
});
|
||||
syncSidebarTreeNodeExpansion(store.treeNodes, node, expanded);
|
||||
}
|
||||
|
||||
@@ -2181,10 +2304,12 @@ function requestSelectedSidebarPaste(): boolean {
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
sidebarLayoutMonitor.start();
|
||||
window.addEventListener("keydown", onWindowKeydown);
|
||||
});
|
||||
|
||||
onUnmounted(() => {
|
||||
sidebarLayoutMonitor.dispose();
|
||||
sidebarTreeRuntime.dispose();
|
||||
sidebarActionGeneration += 1;
|
||||
sidebarContextMenuTarget.value = null;
|
||||
@@ -2344,7 +2469,13 @@ defineExpose({ focusSearch, createNewGroup, collapseAllTreeNodes, locateTabInSid
|
||||
</div>
|
||||
</div>
|
||||
<CustomContextMenu ref="sidebarContextMenuRef" :items="sidebarContextMenuItems" v-slot="contextMenuSlot">
|
||||
<div v-if="flatNodes.length > 0 && useVirtualTree" class="connection-tree-scroll-shell relative min-h-0 flex-1" :class="{ 'connection-tree-scroll-shell--horizontal-overflow': hasSidebarHorizontalOverflow }">
|
||||
<div v-if="flatNodes.length > 0 && useVirtualTree" ref="treeScrollShellRef" class="connection-tree-scroll-shell relative min-h-0 flex-1" :class="{ 'connection-tree-scroll-shell--horizontal-overflow': hasSidebarHorizontalOverflow }">
|
||||
<!-- NOTE: flow-mode is intentionally NOT used here. vue-virtual-scroller
|
||||
v3.0.4's flow-mode view-pool bookkeeping produces an internally
|
||||
inconsistent DOM in this app (window/spacers updated but pool views
|
||||
never materialized -> blank band). Tree rows are fixed 28px (labels
|
||||
truncate), so the standard absolute-positioning mode is safe and
|
||||
keeps the materialized window in sync with the viewport. -->
|
||||
<RecycleScroller
|
||||
ref="treeScrollerRef"
|
||||
class="sidebar-tree connection-tree-scroller h-full overflow-y-auto"
|
||||
@@ -2359,7 +2490,6 @@ defineExpose({ focusSearch, createNewGroup, collapseAllTreeNodes, locateTabInSid
|
||||
key-field="renderKey"
|
||||
type-field="poolType"
|
||||
list-class="connection-tree-content"
|
||||
flow-mode
|
||||
>
|
||||
<template #default="{ item }">
|
||||
<TreeItem
|
||||
@@ -2405,12 +2535,12 @@ defineExpose({ focusSearch, createNewGroup, collapseAllTreeNodes, locateTabInSid
|
||||
<div class="sidebar-tree-horizontal-scrollbar__thumb" :style="sidebarHorizontalScrollbarThumbStyle" @pointerdown.stop="onSidebarHorizontalScrollbarThumbPointerDown" />
|
||||
</div>
|
||||
</div>
|
||||
<div v-else-if="flatNodes.length > 0" class="connection-tree-scroll-shell relative min-h-0 flex-1" :class="{ 'connection-tree-scroll-shell--horizontal-overflow': hasSidebarHorizontalOverflow }">
|
||||
<div v-else-if="flatNodes.length > 0" ref="treeScrollShellRef" class="connection-tree-scroll-shell relative min-h-0 flex-1" :class="{ 'connection-tree-scroll-shell--horizontal-overflow': hasSidebarHorizontalOverflow }">
|
||||
<div ref="plainTreeScrollerRef" class="sidebar-tree connection-tree-scroller h-full overflow-y-auto" :class="sidebarTreeOverflowClass" :style="sidebarTreeScrollerStyle" @click="clearSidebarSelection" @scroll.passive="onTreeScroll">
|
||||
<div class="connection-tree-content">
|
||||
<TreeItem
|
||||
v-for="item in flatNodes"
|
||||
:key="item.id"
|
||||
:key="item.renderKey"
|
||||
:node="item.node"
|
||||
:depth="item.depth"
|
||||
:reorder-disabled="isRootListPartial"
|
||||
@@ -2418,6 +2548,7 @@ defineExpose({ focusSearch, createNewGroup, collapseAllTreeNodes, locateTabInSid
|
||||
:pending-rename="pendingRenameNodeId === item.node.id"
|
||||
:highlighted="highlightedNodeId === item.id"
|
||||
:comment-label-width="sidebarCommentLabelWidths.get(item.node.id)"
|
||||
:sticky-header="isPlainStickyContainerNode(item.node)"
|
||||
@context-menu="(event, node) => openSidebarContextMenu(event, node, contextMenuSlot.onContextMenu)"
|
||||
@rename-started="pendingRenameNodeId = null"
|
||||
@group-created="startRenamingCreatedGroup"
|
||||
@@ -2610,6 +2741,7 @@ defineExpose({ focusSearch, createNewGroup, collapseAllTreeNodes, locateTabInSid
|
||||
contain: content;
|
||||
scrollbar-width: none;
|
||||
-ms-overflow-style: none;
|
||||
overflow-anchor: none;
|
||||
}
|
||||
|
||||
.connection-tree-scroller::-webkit-scrollbar {
|
||||
@@ -2620,6 +2752,13 @@ defineExpose({ focusSearch, createNewGroup, collapseAllTreeNodes, locateTabInSid
|
||||
.connection-tree-scroller :deep(.vue-recycle-scroller__item-view) {
|
||||
min-width: 100%;
|
||||
contain: style;
|
||||
/* The virtual renderer positions rows at fixed item-size offsets (28px, see
|
||||
SIDEBAR_TREE_ROW_HEIGHT). TreeItem rows only guarantee min-h-7, so rename
|
||||
inputs or larger sidebar fonts could grow a row beyond 28px and overlap
|
||||
the next row. Pin every materialized row to the fixed height and clip any
|
||||
overflow instead of letting the layout drift. */
|
||||
height: 28px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.connection-tree-scroller.sidebar-tree-horizontal-scroll :deep(.vue-recycle-scroller__item-view) {
|
||||
|
||||
@@ -176,6 +176,10 @@ const props = defineProps<{
|
||||
pendingRename?: boolean;
|
||||
highlighted?: boolean;
|
||||
commentLabelWidth?: number;
|
||||
/** Plain (non-virtualized) renderer: make database/schema container rows
|
||||
* stick to the top of the tree scroller while their children scroll under
|
||||
* them (mirrors the overlay sticky header of the virtual renderer). */
|
||||
stickyHeader?: boolean;
|
||||
}>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
@@ -1395,6 +1399,7 @@ function onKeydown(event: KeyboardEvent) {
|
||||
'tree-item-active': selectionVisual.rowSelected,
|
||||
'tree-item-active--selection-set': selectionVisual.usesSelectionSetHighlight && selectionVisual.rowSelected,
|
||||
'tree-item-highlight': highlighted,
|
||||
'sidebar-tree-item--sticky': stickyHeader,
|
||||
},
|
||||
]"
|
||||
:tabindex="selectionVisual.selected || selectionVisual.multiSelected ? 0 : -1"
|
||||
@@ -1620,6 +1625,19 @@ function onKeydown(event: KeyboardEvent) {
|
||||
background-color: transparent !important;
|
||||
}
|
||||
|
||||
/* Plain (non-virtualized) renderer: database/schema container rows stick to
|
||||
the top of the tree scroller while their children scroll under them,
|
||||
mirroring the overlay sticky header the virtual renderer uses. The row is
|
||||
min-h-7, so a solid background guarantees no content shows through while
|
||||
rows slide underneath. */
|
||||
.sidebar-tree-item--sticky {
|
||||
position: sticky;
|
||||
top: 0;
|
||||
z-index: 2;
|
||||
background-color: var(--background);
|
||||
border-bottom: 1px solid var(--border);
|
||||
}
|
||||
|
||||
.tree-item-connection-tint:hover::before {
|
||||
background-color: var(--tree-connection-row-hover-bg, var(--tree-connection-row-bg));
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user