fix(sidebar): prevent blank tree after Dameng expansion
This commit is contained in:
1 parent
11903c6dfd
commit
34a158765e
4 files changed
+69
-3
No files matched your search
@@ -955,7 +955,7 @@ const stickyHeaderStyle = computed<CSSProperties>(() => {
|
|||||||
|
|
||||||
// Reset tracking when the tree rebuilds (connect/disconnect/collapse) so a
|
// Reset tracking when the tree rebuilds (connect/disconnect/collapse) so a
|
||||||
// stale scrollTop doesn't keep the overlay mounted after a structural change.
|
// stale scrollTop doesn't keep the overlay mounted after a structural change.
|
||||||
watch(flatNodes, (nodes) => {
|
watch(flatNodes, (nodes, previousNodes) => {
|
||||||
const contextMenuTarget = sidebarContextMenuTarget.value;
|
const contextMenuTarget = sidebarContextMenuTarget.value;
|
||||||
if (contextMenuTarget) {
|
if (contextMenuTarget) {
|
||||||
const visibleContextMenuTarget = nodes.find(({ node }) => matchesSidebarActionTarget(node, contextMenuTarget))?.node;
|
const visibleContextMenuTarget = nodes.find(({ node }) => matchesSidebarActionTarget(node, contextMenuTarget))?.node;
|
||||||
@@ -967,6 +967,25 @@ watch(flatNodes, (nodes) => {
|
|||||||
}
|
}
|
||||||
stickyScrollTop.value = 0;
|
stickyScrollTop.value = 0;
|
||||||
void nextTick(scheduleSidebarScrollMetricsUpdate);
|
void nextTick(scheduleSidebarScrollMetricsUpdate);
|
||||||
|
// After a structural change (list grew/shrunk, e.g. a Dameng connection
|
||||||
|
// expands or collapses) reconcile the virtual scroller with the browser's
|
||||||
|
// scroll position. The recycle pool is rebuilt from the live scrollTop, but
|
||||||
|
// scrollTop is only clamped on the next layout, so right after a shrink the
|
||||||
|
// pool can still target a window beyond the new content — the viewport then
|
||||||
|
// lands inside the end spacer and shows a blank region until the next scroll
|
||||||
|
// event. Reading scrollHeight forces that layout (applying the clamp), then
|
||||||
|
// one explicit pool refresh keeps the rendered window aligned. Only needed
|
||||||
|
// when the item count changed; reorders are already rebuilt by the library.
|
||||||
|
if (nodes.length === (previousNodes?.length ?? -1)) return;
|
||||||
|
void nextTick(() => {
|
||||||
|
const scroller = treeScrollerRef.value;
|
||||||
|
if (!scroller || !useVirtualTree.value) return;
|
||||||
|
const el = scroller.$el as HTMLElement | undefined;
|
||||||
|
if (!el) return;
|
||||||
|
const maxScrollTop = Math.max(0, el.scrollHeight - el.clientHeight);
|
||||||
|
if (el.scrollTop > maxScrollTop) el.scrollTop = maxScrollTop;
|
||||||
|
scroller.updateVisibleItems(true);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
const sidebarTreeOverflowClass = computed(() => (settingsStore.editorSettings.sidebarAllowHorizontalScroll ? "overflow-x-auto sidebar-tree-horizontal-scroll" : "overflow-x-hidden"));
|
const sidebarTreeOverflowClass = computed(() => (settingsStore.editorSettings.sidebarAllowHorizontalScroll ? "overflow-x-auto sidebar-tree-horizontal-scroll" : "overflow-x-hidden"));
|
||||||
|
|||||||
@@ -1328,7 +1328,7 @@ function onKeydown(event: KeyboardEvent) {
|
|||||||
<LightTooltip :text="visibleLabel(node)" :disabled="isTooltipDisabled()" side="right" :side-offset="8" :delay="0" :close-delay="30" :surface="detailTooltip ? 'popover' : 'foreground'">
|
<LightTooltip :text="visibleLabel(node)" :disabled="isTooltipDisabled()" side="right" :side-offset="8" :delay="0" :close-delay="30" :surface="detailTooltip ? 'popover' : 'foreground'">
|
||||||
<div
|
<div
|
||||||
ref="rowRef"
|
ref="rowRef"
|
||||||
class="group flex cursor-default items-center gap-2 py-1 px-2 relative outline-none"
|
class="group flex cursor-default items-center gap-2 min-h-7 py-1 px-2 relative outline-none"
|
||||||
style="contain: layout style"
|
style="contain: layout style"
|
||||||
:class="[
|
:class="[
|
||||||
rowWidthClass,
|
rowWidthClass,
|
||||||
|
|||||||
@@ -410,6 +410,10 @@ export function mergeTableTreePageChildren(currentChildren: TreeNode[], pageChil
|
|||||||
const roots = [...currentChildren];
|
const roots = [...currentChildren];
|
||||||
const nodesByKey = new Map<string, TreeNode>();
|
const nodesByKey = new Map<string, TreeNode>();
|
||||||
const rootKeys = new Set<string>();
|
const rootKeys = new Set<string>();
|
||||||
|
// Non-table children (e.g. views in simple-display pagination) have no key
|
||||||
|
// bucket of their own; dedupe them by id so paging drift can never insert
|
||||||
|
// the same node twice. Duplicate ids break the sidebar scroller's key-field.
|
||||||
|
const rootNodeIds = new Set<string>(roots.map((node) => node.id));
|
||||||
|
|
||||||
const nodeKey = (node: TreeNode) => exactObjectIdentityKey("TABLE", node.schema, node.label);
|
const nodeKey = (node: TreeNode) => exactObjectIdentityKey("TABLE", node.schema, node.label);
|
||||||
const collect = (nodes: readonly TreeNode[]) => {
|
const collect = (nodes: readonly TreeNode[]) => {
|
||||||
@@ -484,7 +488,10 @@ export function mergeTableTreePageChildren(currentChildren: TreeNode[], pageChil
|
|||||||
|
|
||||||
const addNode = (node: TreeNode) => {
|
const addNode = (node: TreeNode) => {
|
||||||
if (node.type !== "table") {
|
if (node.type !== "table") {
|
||||||
roots.push(node);
|
if (!rootNodeIds.has(node.id)) {
|
||||||
|
roots.push(node);
|
||||||
|
rootNodeIds.add(node.id);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Vendored
+40
@@ -13,6 +13,16 @@ function table(name: string, parent?: string): TableInfo {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function view(name: string): TableInfo {
|
||||||
|
return {
|
||||||
|
name,
|
||||||
|
table_type: "VIEW",
|
||||||
|
comment: null,
|
||||||
|
parent_schema: null,
|
||||||
|
parent_name: null,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
function object(name: string, parent?: string): ObjectInfo {
|
function object(name: string, parent?: string): ObjectInfo {
|
||||||
return {
|
return {
|
||||||
name,
|
name,
|
||||||
@@ -105,6 +115,36 @@ test("mergeTableTreePageChildren attaches later page partitions to loaded parent
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("mergeTableTreePageChildren dedupes non-table nodes repeated across pages", () => {
|
||||||
|
// Simple-display pagination: a later page can re-return an object the
|
||||||
|
// current children already hold (Dameng agent falls back between metadata
|
||||||
|
// queries, so page boundaries drift). Non-table nodes (views) must not be
|
||||||
|
// inserted twice — duplicate ids break the sidebar scroller's key-field.
|
||||||
|
const firstPage = buildTableTreeNodes({
|
||||||
|
nodeId: "conn:app:public",
|
||||||
|
connectionId: "conn",
|
||||||
|
database: "app",
|
||||||
|
schema: "public",
|
||||||
|
tables: [table("orders"), view("orders_v")],
|
||||||
|
});
|
||||||
|
const driftedPage = buildTableTreeNodes({
|
||||||
|
nodeId: "conn:app:public",
|
||||||
|
connectionId: "conn",
|
||||||
|
database: "app",
|
||||||
|
schema: "public",
|
||||||
|
tables: [view("orders_v"), table("payments")],
|
||||||
|
});
|
||||||
|
|
||||||
|
const merged = mergeTableTreePageChildren(firstPage, driftedPage, "conn", "app");
|
||||||
|
const ids = merged.map((node) => node.id);
|
||||||
|
assert.equal(new Set(ids).size, ids.length, "merged children must not contain duplicate ids");
|
||||||
|
assert.equal(merged.filter((node) => node.type === "view").length, 1, "the repeated view must appear once");
|
||||||
|
assert.deepEqual(
|
||||||
|
merged.map((node) => node.label).sort(),
|
||||||
|
["orders", "orders_v", "payments"].sort(),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
test("buildTableTreeNodes keeps sidebar tables in natural name order", () => {
|
test("buildTableTreeNodes keeps sidebar tables in natural name order", () => {
|
||||||
const nodes = buildTableTreeNodes({
|
const nodes = buildTableTreeNodes({
|
||||||
nodeId: "conn:app:public",
|
nodeId: "conn:app:public",
|
||||||
|
|||||||
Reference in new issue
Block a user